Skip to content

fix(sdk): reach the AppContainer + DACL tier from the streaming path - #645

Merged
shschaefer merged 1 commit into
microsoft:mainfrom
caarlos0:caarlos0/fix-sdk-appcontainer-dacl-fallback
Jul 14, 2026
Merged

shschaefer merged 1 commit into
microsoft:mainfrom
caarlos0:caarlos0/fix-sdk-appcontainer-dacl-fallback

Conversation

@caarlos0

@caarlos0 Carlos Alexandro Becker (caarlos0) commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

📖 Description

The mxc-sdk streaming path (spawn_sandbox → mxc_engine::dispatch::spawn_process_container) resolved the Windows ProcessContainer backend to only two isolation tiers — BaseContainer when the native OS sandbox API is usable, otherwise AppContainer + BFS (bfscfg.exe). On a host with neither the BaseContainer API nor bfscfg.exe, the streaming path failed closed with a "bfscfg.exe is not available" error instead of falling back to AppContainer + DACL (Tier 3). The run-to-completion executor path (wxc-exec) already had all three tiers via dispatch_with_fallback, so the two surfaces disagreed.

This PR makes the streaming path use the same three-tier fallback:

  • Extracts the tier → (backend, DACL) mapping into a single shared select_backend_with_fallback in appcontainer_common::dispatcher, so the run-to-completion (dispatch_with_fallback) and streaming (spawn_with_fallback) surfaces can no longer drift on tier selection.
  • Adds spawn_with_fallback, whose returned handle owns any DaclManager via a new DaclGuardedProcess. Its field order restores host ACEs only after the child tree is torn down (firewall / BFS enforcement first), matching the run-to-completion drop order.
  • On a spawn failure that occurs after a tier was selected, carries the selected tier and tier-selection warnings in SpawnDispatchError::Spawn so the engine logs them just like the run-to-completion resolve path (which logs before its separate spawn attempt) — keeping diagnostics parity on the failure path.

Docs (mxc-sdk README + mxc_engine::dispatch module doc) are updated to describe the shared three-tier fallback.

Scope: Windows only. No behavior change to the run-to-completion executor path or to non-Windows backends.

🔗 References

Resolves #643

🔍 Validation

  • cargo check --target x86_64-pc-windows-msvc -p appcontainer_common -p mxc_engine --tests — clean.
  • cargo clippy --target x86_64-pc-windows-msvc -p appcontainer_common -p mxc_engine --tests -- -D warnings — clean.
  • cargo fmt --all -- --check — clean.
  • cargo test -p mxc_engine (host) — 15 passed / 0 failed.
  • New Windows-only unit tests in dispatcher.rs cover the shared selector for each tier (T1 / T2-no-deny / T2-deny / T3), the streaming Tier-3 fallback when BaseContainer is unusable and BFS is not compiled in (the Rust SDK fails to fall back to AppContainer + DACL #643 regression guard), and DaclGuardedProcess method delegation.
  • The actual Windows spawn-failure runtime path is exercised by CI on Windows (no local spawn seam on macOS).

✅ Checklist

  • Signed the Contributor License Agreement
  • Linked to an issue
  • Updated documentation (if applicable)
  • Updated Copilot instructions (if build, architecture, or conventions changed)
  • If this PR changes Cargo.lock, the dependency-feed-check check passes (no Cargo.lock change)

📋 Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

The mxc-sdk streaming path (`spawn_sandbox` -> `mxc_engine::dispatch`)
resolved Windows ProcessContainer to only two tiers -- BaseContainer when
usable, otherwise AppContainer + BFS -- so a host with neither the
BaseContainer API nor `bfscfg.exe` failed closed instead of falling back
to AppContainer + DACL (Tier 3). The run-to-completion executor path
already had all three tiers via `dispatch_with_fallback`.

Extract the tier -> (backend, DACL) mapping into a shared
`select_backend_with_fallback`, and add a streaming `spawn_with_fallback`
that both surfaces go through, so they can no longer drift. The returned
handle owns any `DaclManager` via `DaclGuardedProcess`, whose field order
restores host ACEs only after the child tree is torn down, matching the
run-to-completion drop order.

On a spawn failure after tier selection, carry the selected tier and the
tier-selection warnings in `SpawnDispatchError::Spawn` so the engine logs
them just like the run-to-completion resolve path (which logs before its
separate spawn), keeping diagnostics parity.

Resolves microsoft#643

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3005336c-50df-445b-a777-7f140edf929c
Signed-off-by: Carlos Alexandro Becker <[email protected]>
Copilot AI review requested due to automatic review settings July 14, 2026 16:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Windows-only behavioral gap between the Rust SDK streaming API (spawn_sandbox) and the run-to-completion executor path (wxc-exec) for ProcessContainer tier fallback. It centralizes tier selection and adds a streaming fallback dispatcher so streaming can reach the AppContainer + DACL (Tier 3) isolation mode when BaseContainer is unusable and BFS (bfscfg.exe) isn’t available, matching existing executor behavior.

Changes:

  • Refactors ProcessContainer tier selection into a shared select_backend_with_fallback to prevent drift between streaming and run-to-completion paths.
  • Adds a streaming spawn_with_fallback API and a DaclGuardedProcess wrapper so the streaming handle owns the DACL guard and restores host ACEs only after the child process tree is torn down.
  • Updates engine/docs to describe the full three-tier fallback (BaseContainer → AppContainer+BFS → AppContainer+DACL) and improves failure-path diagnostics parity by retaining tier/warnings on spawn failures.
Show a summary per file
File Description
src/core/mxc-sdk/README.md Updates SDK documentation to reflect shared three-tier ProcessContainer fallback and DACL-guard ownership in streaming.
src/core/mxc_engine/src/dispatch.rs Switches streaming ProcessContainer dispatch to spawn_with_fallback and logs tier/warnings on both success and spawn-failure paths.
src/backends/appcontainer/common/src/dispatcher.rs Introduces shared backend selection (select_backend_with_fallback), streaming spawn_with_fallback, and DaclGuardedProcess to correctly scope DACL guard lifetime and drop ordering.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Low

@caarlos0
Carlos Alexandro Becker (caarlos0) marked this pull request as ready for review July 14, 2026 18:35
@shschaefer
shschaefer merged commit 47a172c into microsoft:main Jul 14, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust SDK fails to fall back to AppContainer + DACL

3 participants