Skip to content

refactor(engine): DeleteFs trait sandbox refactor + emitter wiring (SEC-1.q) - #4728

Merged
oferchen merged 1 commit into
masterfrom
feat/sec-1-q-delete-fs-trait-sandbox-refactor
May 22, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/sec-1-q-delete-fs-trait-sandbox-refactor

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Implements SEC-1.q per docs/design/sec-1-q-delete-emitter-sandbox-2026-05-22.md. Closes 6 GAP sites from the SEC-1 audit (PR #4710 rows 22-27): daemon-reachable unlink/rmdir/remove_dir_all calls in the engine DeleteFs impl that weren't anchored on DirSandbox.

This was previously opened as PR #4727 stacked on SEC-1.s (PR #4726). #4726 merged at sha 2a5d119, GitHub auto-closed #4727 when its base branch was deleted, and reopen is blocked. Re-opening here against master with the same source branch.

Changes

  1. Trait extension (crates/engine/src/delete/emitter/fs.rs): six new unix-only *_at siblings taking BorrowedFd<'_> + &OsStr. Path-based methods preserved as no-sandbox/Windows fallback.
  2. Implementations: RealDeleteFs routes through fast_io::unlinkat and fast_io::recursive_unlinkat (SEC-1.s helper); RecordingDeleteFs and ScriptedDeleteFs discard parent_fd and record the leaf name so existing emitter tests pass unchanged; &F blanket impl mirrors the six methods.
  3. Emitter wiring: Option<Arc<DirSandbox>> carrier field on DeleteEmitter plus with_sandbox() builder and sandbox() accessor. drain_plan opens a per-plan dirfd against sandbox.root_dirfd(); dispatch and dispatch_dir route through the *_at methods when the dirfd is available, otherwise transparently fall back to path-based methods. All cross-platform via #[cfg(unix)] gates.
  4. Tests (crates/engine/src/delete/emitter/tests/sandbox.rs): seven tests covering per-method sandbox dispatch, symlink-swap resistance (regular file, symlink, recursive peel against escape symlinks), sandbox-off fallback, device/special leaf dispatch, missing-plan-directory fallback.
  5. Helper exposure: recursive_unlinkat(parent_dirfd, leaf) promoted from private to pub and re-exported, so engine can drive the recursive peel directly.

Deferred

Receiver loop in crates/transfer/ doesn't route through DeleteEmitter yet; wiring that path is a separate follow-up (noted in the design doc).

Constraints

  • No unsafe added to engine crate (still denies unsafe).
  • Cross-platform: unix gates the new methods; Windows path unchanged.
  • Conventional commit prefix refactor: per PR title.

…EC-1.q)

Extend DeleteFs with unix-only `*_at` siblings (unlink_file_at, rmdir_at,
unlink_symlink_at, unlink_device_at, unlink_special_at, remove_dir_all_at)
that take a parent dirfd + single-component leaf and route through
fast_io::unlinkat / fast_io::recursive_unlinkat (SEC-1.s). Path-based
methods stay as the no-sandbox / Windows fallback so existing callers
keep working unchanged.

Closes the six GAP sites in crates/engine/src/delete/emitter/fs.rs from
PR #4710 audit section 4 (#22-#27) by giving RealDeleteFs a dirfd-
anchored dispatch shape. Adds DeleteEmitter::with_sandbox carrier slot
that opens a per-plan dirfd via DirSandbox::root_dirfd just before
dispatch so a mid-syscall symlink swap on the parent walk cannot
redirect the call. Plan-directory open failure transparently falls back
to the path-based methods so the drain stays compatible.

RecordingDeleteFs and ScriptedDeleteFs implement `*_at` by discarding
parent_fd and recording the leaf name so every emitter unit test keeps
working without sandbox plumbing. New sandbox.rs test module exercises
each `*_at` variant against a live tempdir, the recursive peel's
symlink-swap resistance, and the sandbox-off / missing-plan-directory
fallback paths.

Promotes recursive_unlinkat(parent_dirfd, leaf) from a SEC-1.s internal
helper to a pub entry point so engine can use it directly without
synthesising absolute-path arguments. Receiver-deletion integration in
crates/transfer/ deferred to a follow-up per design doc; the receiver
loop does not yet route through DeleteEmitter.
@oferchen
oferchen merged commit 899fd78 into master May 22, 2026
30 of 34 checks passed
@oferchen
oferchen deleted the feat/sec-1-q-delete-fs-trait-sandbox-refactor branch May 22, 2026 11:42
oferchen added a commit that referenced this pull request May 22, 2026
#4729)

Captures the receiver-side `--delete` wiring follow-up SEC-1.q (PR #4728)
intentionally deferred. The merged engine-side work added a sandbox-aware
DeleteFs trait surface plus the DeleteEmitter::with_sandbox carrier, but
the receiver loop in crates/transfer/src/receiver/directory/deletion.rs
still calls std::fs::remove_file / remove_dir_all / read_dir directly.

Lays out three options (migrate receiver to DeleteEmitter, swap to
fast_io *_via_sandbox_or_fallback helpers, defer behind Landlock) with
LoC scope, risk, test cost, and cross-platform plan. Recommends Option B
(direct helper swap) on effort-vs-risk grounds and because the SEC-1.r
temp_guard / temp_cleanup PR (#4723) is the established precedent for
exactly this carrier-threading shape.

Closes audit rows #5-#7 in docs/audits/sec-1-path-syscall-audit-2026-05-22.md
once the implementation PR lands. Docs-only.
oferchen added a commit that referenced this pull request May 22, 2026
SkipWhile<Components, _> has no as_path() method on stable Rust 1.88;
the previous skip_while-then-as_path call introduced in SEC-1.q (#4728)
slipped through that PR's CI but breaks fmt+clippy on every subsequent
master CI run. Switch to a manual Components::next() walk that consumes
the leading Prefix/RootDir/CurDir components, then calls as_path() on
the unwrapped Components iterator.
oferchen added a commit that referenced this pull request May 22, 2026
SkipWhile<Components, _> has no as_path() method on stable Rust 1.88;
the previous skip_while-then-as_path call introduced in SEC-1.q (#4728)
slipped through that PR's CI but breaks fmt+clippy on every subsequent
master CI run. Switch to a manual Components::next() walk that consumes
the leading Prefix/RootDir/CurDir components, then calls as_path() on
the unwrapped Components iterator.
oferchen added a commit that referenced this pull request May 22, 2026
…olding (PIP-8) (#4731)

* refactor(transfer,engine): tear out dead parallel-receive-delta scaffolding (PIP-8)

PIP-7 (#4730) proved that the receiver-side parallel-receive-delta
dispatch was a side-effect-only no-op. ReceiverContext::delta_pipeline
had 1 writer (enable_parallel_receive_delta) and 0 readers - the
production receive loop never drained the swapped pipeline. The only
observable behaviour the feature flag enabled was the side effect of
constructing ParallelDeltaPipeline::new, which spawns a DeltaConsumer
background thread - the suspected source of the file_1.txt corruption
PIP-4 surfaced.

Remove the dead scaffolding:

- ReceiverContext::enable_parallel_receive_delta
- ReceiverContext::set_delta_pipeline
- ReceiverContext::dispatch_receiver_strategy
- ReceiverContext::select_receiver_strategy
- ReceiverContext::total_source_bytes
- ReceiverContext::dispatch_forced_parallel
- The delta_pipeline: Option<Box<dyn ReceiverDeltaPipeline>> field
- The ReceiverStrategy enum and TransferStats::receiver_strategy_chosen
- PARALLEL_RECEIVE_FILE_COUNT_THRESHOLD, PARALLEL_RECEIVE_BYTES_THRESHOLD,
  FORCE_PARALLEL_RECEIVE_ENV constants
- strategy_tests module in receiver/mod.rs
- crates/transfer/src/receiver/tests/file_list/receiver_strategy.rs
- dispatch_receiver_strategy() call sites in receiver/transfer/
  {sync,pipelined,pipelined_incremental}.rs

Keep compiled (no functional change):

- ParallelDeltaApplier - benches drive it directly
  (parallel_receive_delta_perf, br_3j_f_dashmap_cores_vs_throughput,
  parallel_verify_chunk)
- ParallelDeltaPipeline - wire_format_parallel_scheduling_fuzz exercises
  it; PIP-9 will need it as a substrate
- DeltaConsumer - engine consumer tests + multi_producer_audit
- The parallel-receive-delta feature flag - now a no-op pending PIP-9

Add docs/design/pip-9-parallel-receive-delta-wire-up-2026-05-22.md
to track the future RJN-3 fan-out integration of ParallelDeltaApplier
through a production reader. Update README, CHANGELOG, and the
deferral notes in parallel-receive-delta-default-on.md,
pip-4-closure-2026-05-21.md, br-6-sign-off-check-in-2026-05-21.md,
and the PIP-7 doc itself (status: OPEN -> MITIGATED-PENDING-PIP-9).

* fix(engine): use Components::next() walk for plan_directory_to_relative

SkipWhile<Components, _> has no as_path() method on stable Rust 1.88;
the previous skip_while-then-as_path call introduced in SEC-1.q (#4728)
slipped through that PR's CI but breaks fmt+clippy on every subsequent
master CI run. Switch to a manual Components::next() walk that consumes
the leading Prefix/RootDir/CurDir components, then calls as_path() on
the unwrapped Components iterator.
oferchen added a commit that referenced this pull request May 22, 2026
…-1.q2) (#4732)

* feat(transfer): thread DirSandbox through receiver --delete path (SEC-1.q2)

Replace the three unanchored syscalls in delete_extraneous_files with
their sandbox-anchored siblings so a TOCTOU symlink swap on a top-level
extraneous entry cannot redirect the listing or the unlink to an
attacker-chosen inode outside the destination tree.

Adds fast_io::read_dir_via_sandbox_or_fallback (mirrors the existing
*_via_sandbox_or_fallback shape: openat(O_DIRECTORY | O_NOFOLLOW) +
fdopendir for single-component scans, std::fs::read_dir fallback
otherwise). Closes audit rows #5, #6, #7 from the SEC-1 path-syscall
audit.

Mirrors the SEC-1.r temp_guard/temp_cleanup carrier-threading pattern
(PR #4723): the Option<Arc<DirSandbox>> is cloned once into the
map_blocking worker closure and forwarded to every helper call.
Sandbox-off and multi-component paths take the documented identical-
behaviour fallback. No transfer-crate unsafe is introduced; all unsafe
stays behind the existing fast_io safe wrappers.

Windows continues through std::fs::remove_file / remove_dir_all /
read_dir (NTFS handle semantics already close the symlink-swap window
per the SEC-1.l audit).

* fix(engine): use Components::next() walk for plan_directory_to_relative

SkipWhile<Components, _> has no as_path() method on stable Rust 1.88;
the previous skip_while-then-as_path call introduced in SEC-1.q (#4728)
slipped through that PR's CI but breaks fmt+clippy on every subsequent
master CI run. Switch to a manual Components::next() walk that consumes
the leading Prefix/RootDir/CurDir components, then calls as_path() on
the unwrapped Components iterator.

* fix(transfer): cfg-gate rel_for_unlink to unix to silence Windows unused-var
oferchen added a commit that referenced this pull request Aug 24, 2026
…EC-1.q) (#4728)

Extend DeleteFs with unix-only `*_at` siblings (unlink_file_at, rmdir_at,
unlink_symlink_at, unlink_device_at, unlink_special_at, remove_dir_all_at)
that take a parent dirfd + single-component leaf and route through
fast_io::unlinkat / fast_io::recursive_unlinkat (SEC-1.s). Path-based
methods stay as the no-sandbox / Windows fallback so existing callers
keep working unchanged.

Closes the six GAP sites in crates/engine/src/delete/emitter/fs.rs from
PR #4710 audit section 4 (#22-#27) by giving RealDeleteFs a dirfd-
anchored dispatch shape. Adds DeleteEmitter::with_sandbox carrier slot
that opens a per-plan dirfd via DirSandbox::root_dirfd just before
dispatch so a mid-syscall symlink swap on the parent walk cannot
redirect the call. Plan-directory open failure transparently falls back
to the path-based methods so the drain stays compatible.

RecordingDeleteFs and ScriptedDeleteFs implement `*_at` by discarding
parent_fd and recording the leaf name so every emitter unit test keeps
working without sandbox plumbing. New sandbox.rs test module exercises
each `*_at` variant against a live tempdir, the recursive peel's
symlink-swap resistance, and the sandbox-off / missing-plan-directory
fallback paths.

Promotes recursive_unlinkat(parent_dirfd, leaf) from a SEC-1.s internal
helper to a pub entry point so engine can use it directly without
synthesising absolute-path arguments. Receiver-deletion integration in
crates/transfer/ deferred to a follow-up per design doc; the receiver
loop does not yet route through DeleteEmitter.
oferchen added a commit that referenced this pull request Aug 24, 2026
#4729)

Captures the receiver-side `--delete` wiring follow-up SEC-1.q (PR #4728)
intentionally deferred. The merged engine-side work added a sandbox-aware
DeleteFs trait surface plus the DeleteEmitter::with_sandbox carrier, but
the receiver loop in crates/transfer/src/receiver/directory/deletion.rs
still calls std::fs::remove_file / remove_dir_all / read_dir directly.

Lays out three options (migrate receiver to DeleteEmitter, swap to
fast_io *_via_sandbox_or_fallback helpers, defer behind Landlock) with
LoC scope, risk, test cost, and cross-platform plan. Recommends Option B
(direct helper swap) on effort-vs-risk grounds and because the SEC-1.r
temp_guard / temp_cleanup PR (#4723) is the established precedent for
exactly this carrier-threading shape.

Closes audit rows #5-#7 in docs/audits/sec-1-path-syscall-audit-2026-05-22.md
once the implementation PR lands. Docs-only.
oferchen added a commit that referenced this pull request Aug 24, 2026
…olding (PIP-8) (#4731)

* refactor(transfer,engine): tear out dead parallel-receive-delta scaffolding (PIP-8)

PIP-7 (#4730) proved that the receiver-side parallel-receive-delta
dispatch was a side-effect-only no-op. ReceiverContext::delta_pipeline
had 1 writer (enable_parallel_receive_delta) and 0 readers - the
production receive loop never drained the swapped pipeline. The only
observable behaviour the feature flag enabled was the side effect of
constructing ParallelDeltaPipeline::new, which spawns a DeltaConsumer
background thread - the suspected source of the file_1.txt corruption
PIP-4 surfaced.

Remove the dead scaffolding:

- ReceiverContext::enable_parallel_receive_delta
- ReceiverContext::set_delta_pipeline
- ReceiverContext::dispatch_receiver_strategy
- ReceiverContext::select_receiver_strategy
- ReceiverContext::total_source_bytes
- ReceiverContext::dispatch_forced_parallel
- The delta_pipeline: Option<Box<dyn ReceiverDeltaPipeline>> field
- The ReceiverStrategy enum and TransferStats::receiver_strategy_chosen
- PARALLEL_RECEIVE_FILE_COUNT_THRESHOLD, PARALLEL_RECEIVE_BYTES_THRESHOLD,
  FORCE_PARALLEL_RECEIVE_ENV constants
- strategy_tests module in receiver/mod.rs
- crates/transfer/src/receiver/tests/file_list/receiver_strategy.rs
- dispatch_receiver_strategy() call sites in receiver/transfer/
  {sync,pipelined,pipelined_incremental}.rs

Keep compiled (no functional change):

- ParallelDeltaApplier - benches drive it directly
  (parallel_receive_delta_perf, br_3j_f_dashmap_cores_vs_throughput,
  parallel_verify_chunk)
- ParallelDeltaPipeline - wire_format_parallel_scheduling_fuzz exercises
  it; PIP-9 will need it as a substrate
- DeltaConsumer - engine consumer tests + multi_producer_audit
- The parallel-receive-delta feature flag - now a no-op pending PIP-9

Add docs/design/pip-9-parallel-receive-delta-wire-up-2026-05-22.md
to track the future RJN-3 fan-out integration of ParallelDeltaApplier
through a production reader. Update README, CHANGELOG, and the
deferral notes in parallel-receive-delta-default-on.md,
pip-4-closure-2026-05-21.md, br-6-sign-off-check-in-2026-05-21.md,
and the PIP-7 doc itself (status: OPEN -> MITIGATED-PENDING-PIP-9).

* fix(engine): use Components::next() walk for plan_directory_to_relative

SkipWhile<Components, _> has no as_path() method on stable Rust 1.88;
the previous skip_while-then-as_path call introduced in SEC-1.q (#4728)
slipped through that PR's CI but breaks fmt+clippy on every subsequent
master CI run. Switch to a manual Components::next() walk that consumes
the leading Prefix/RootDir/CurDir components, then calls as_path() on
the unwrapped Components iterator.
oferchen added a commit that referenced this pull request Aug 24, 2026
…-1.q2) (#4732)

* feat(transfer): thread DirSandbox through receiver --delete path (SEC-1.q2)

Replace the three unanchored syscalls in delete_extraneous_files with
their sandbox-anchored siblings so a TOCTOU symlink swap on a top-level
extraneous entry cannot redirect the listing or the unlink to an
attacker-chosen inode outside the destination tree.

Adds fast_io::read_dir_via_sandbox_or_fallback (mirrors the existing
*_via_sandbox_or_fallback shape: openat(O_DIRECTORY | O_NOFOLLOW) +
fdopendir for single-component scans, std::fs::read_dir fallback
otherwise). Closes audit rows #5, #6, #7 from the SEC-1 path-syscall
audit.

Mirrors the SEC-1.r temp_guard/temp_cleanup carrier-threading pattern
(PR #4723): the Option<Arc<DirSandbox>> is cloned once into the
map_blocking worker closure and forwarded to every helper call.
Sandbox-off and multi-component paths take the documented identical-
behaviour fallback. No transfer-crate unsafe is introduced; all unsafe
stays behind the existing fast_io safe wrappers.

Windows continues through std::fs::remove_file / remove_dir_all /
read_dir (NTFS handle semantics already close the symlink-swap window
per the SEC-1.l audit).

* fix(engine): use Components::next() walk for plan_directory_to_relative

SkipWhile<Components, _> has no as_path() method on stable Rust 1.88;
the previous skip_while-then-as_path call introduced in SEC-1.q (#4728)
slipped through that PR's CI but breaks fmt+clippy on every subsequent
master CI run. Switch to a manual Components::next() walk that consumes
the leading Prefix/RootDir/CurDir components, then calls as_path() on
the unwrapped Components iterator.

* fix(transfer): cfg-gate rel_for_unlink to unix to silence Windows unused-var
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant