Repository navigation
feat(box): add opt-in native filesystem policy interception on macOS - #107
kevin-orellana wants to merge 8 commits into
Conversation
…macOS ## Problem Direct filesystem operations inside contained workloads do not reach Dogwood. Containment grants cannot apply history-based policy to those operations. ## Solution Add an optional macOS 27 monitor behind kernel-policy-integration. Route covered opens and mutations through the existing policy engine. Start monitoring before the broker accepts requests or the workload starts. Add PathResolver::approve_host_entry for directory-entry operations. Include the local memory-history, policy-timing, and interception controls used for the performance experiment. These controls are not a supported Box setting. The public resolver addition and benchmark controls remain review items. No configuration key, record layout, wire protocol, or dependency pin changes. ## Tests The signed macos_file_enforcement suite passed ten tests, including direct_open_truncate_and_grandchild_obey_dogwood, native_mutations_preserve_denied_paths, and native_history_changes_the_next_decision_without_a_cached_allow. The run::macos_enforcement::tests suite passed ten event-mapping tests. Six benchmark controls and two native history controls passed. All 72 read invocations passed. Cargo completed 0/3 durable builds, 2/3 memory builds, and 3/3 baseline builds. Failed builds reported Box transport timeouts. Memory-mode restart of an existing committed box remains unsupported. Linux native interception and later reads through existing handles are not covered. The required review found merge blockers in test-control isolation, the public resolver decision, signed CI setup, and unbounded native test waits. Process-global timing counters remain diagnostic only. These findings are disclosed in the draft. Fresh release all-feature build and formatting passed. Broader release tests and example gates are running; full workspace and cross-platform validation are incomplete.
Park the observer until the peer sees closure. Shutdown can precede reads, so queued bytes are optional; closure, joined handlers and elapsed bounds remain required. The fixed case passes 50 repeats and fails with shutdown ordering deliberately broken.
Track descendant identities through shutdown, check default event muting, bound callback draining, and retain failed callback storage safely. Keep policy records durable and publish final decisions after the kernel reply. Use the native-filesystem-policy feature name consistently and refuse unsupported activation before changing the stored record. Enumerate actual child IDs instead of treating the process-list buffer estimate as a child count. Weak-link the newer process signaling function and check its availability. Add signed descendant/history coverage and reuse the shared policy test fixture.
|
The structured-denial criterion in filesystem interception epic #43 depends on agent/tool integration. It cannot be satisfied by this PR's kernel interception path alone. Apple's Endpoint Security response interfaces accept an authorization decision or allowed flags, plus a caching choice. They have no field for a custom error message. The native adapter returns that decision. A refused filesystem call reports an operating-system error code, such as The agent-facing requirement remains valid: the agent should receive the action, deciding rule, and explanation. Delivering those details requires an integration that matches a Box denial to the exact failed tool call and supplies the structured explanation to the agent. Operator diagnostics or a separate event viewer do not satisfy that requirement. I propose treating structured agent-denial delivery as a dependent integration task under first denial epic #9, linked from #43. This PR should document the current native error behavior and its structured operator diagnostics. Completing this PR does not complete the agent-facing denial criterion or close #43. |
Description
Direct filesystem operations inside contained workloads currently bypass Dogwood. Containment grants alone cannot apply Dogwood temporal policy to those operations.
This experimental feature checks selected kernel filesystem open, create, unlink, rename, and truncate requests on macOS. It uses the existing policy engine and history. Containment restrictions still apply.
Activation requires a build with the
native-filesystem-policyCargo feature and this explicit selection:Per-workload selection
The global experimental setting supplies the default. Optional overrides select native filesystem mediation independently for the agent, individual tools, and local Model Context Protocol (MCP) servers:
Only selection fields appear above. Existing tables still require their command and other settings. An absent process setting inherits the global default, not the agent override. Explicit enablement requires the global gate. Remote MCP entries reject this local-process setting.
The trusted launcher holds each workload until Box registers its mode against the kernel-observed process identity. Descendants inherit the mode across forks and executable changes. Broker-launched tools receive their selected table's mode. Undeclared executables allowed by the agent's execute grants retain the agent's mode.
Disabled workloads retain sandbox restrictions and shutdown tracking. Their native file operations bypass Dogwood evaluation and history recording. History-based rules cannot rely on observing those operations. Shell and network policy checks remain active. Disabled workloads can still incur kernel event-delivery and launcher overhead.
Leveraging MacOS Endpoint Security API
This feature on the Box Core binary requires macOS 27+, the macOS 27 SDK, and Apple's Endpoint Security entitlement. Endpoint Security lets a client decide selected operating system requests. Standard Box Core release artifacts exclude this experimental feature. An absent setting or
falsekeeps it disabled, including in all-feature builds. Unavailable support refuses startup before workload launch or stored-record changes.Without process overrides, disabled records use version 21 and enabled records use version 22. Explicit process overrides require version 23. Older binaries reject unsupported versions. Remove process overrides and disable the global setting with a compatible build before returning to a version-21 binary.
Ordinary workspace tests require no signing identity.
Callout: File descriptor handle allows for continued file access without policy engine mediation
Existing open file descriptors can carry later access without another open request. This experiment does not revoke descriptors or intercept every filesystem operation.
Rationale: Today, there is no readily available way to close or disable file descriptor access once it's been provided to a sandboxed process. We will declare this in our documentation.
FAQ
Does this check every file access?
No. It checks selected open, create, unlink, rename, and truncate requests. An already-open file descriptor can permit later access without another policy check. The feature does not revoke descriptors or intercept every filesystem operation.
Why add policy checks when containment already exists?
Containment restricts which paths a process can reach. Dogwood adds policy decisions, including rules that depend on prior events. Both restrictions apply. A policy permit cannot expand containment grants.
Can customers enable this through TOML alone?
Only when they already have a compatible, signed build. The build needs the
native-filesystem-policyCargo feature and Apple's Endpoint Security entitlement. Activation requires macOS 27+ and explicit selection inbox.toml. Standard release artifacts exclude the experiment.What happens when selected support is unavailable?
Box Core refuses startup before the workload runs or the stored record changes. It does not silently disable the selected checks.
Why disable authorization caching?
The adapter disables kernel authorization caching so intercepted requests receive fresh policy decisions. Repeated checks add work. Reusing an earlier decision could miss changes in policy history.
Does an allow record prove that the operation succeeded?
No. Accepted authorization replies produce
indeterminateoutcomes. These records confirm authorization, not the filesystem result.Can customers downgrade immediately?
Configurations without process overrides use version 22 when enabled. Explicit overrides require version 23. Remove process overrides, set the global feature to
false, and run once with a compatible build before using a version-21 binary. That run retains existing durable history.Related Issues
No closing issue reference.
Type of Change
New feature, experimental.
Testing
Review fixes validated at
9a556f4An explicitly disabled agent or tool no longer needs filesystem policy permissions during trusted launcher startup. The temporary bootstrap exemption ends before workload execution. Unknown processes remain mediated, and stale messages cannot overwrite a newer executable's tracking state.
-D warnings. The bridge compiled against SDK 26.5 and SDK 27.Three independent reviewers found no remaining source blocker. Their checks covered runtime behavior, test strength, contracts, and code conventions.
The CI Gate now requires the native build, adapter and configuration tests, and signed-receipt freshness check. The signed kernel run remains manual on a trusted macOS 27 host. The receipt is an attestation; it is not an independent hosted signing pipeline. Covered source or workflow changes require a fresh build and signed run. An older hosted SDK compiles the unsupported-platform code; the signed macOS 27 suite exercises the active bridge.
See the signed-run receipt and validation instructions.
Live model workloads, the full workspace suite, and Linux runtime tests were not rerun for this fix. Earlier results and their limits remain below. This PR remains a draft.
Earlier validation and workload measurements
Native agent workload smoke tests
The explicitly selected
test-workload/workload-native-filesystemcase passed locally with Claude Code 2.1.299 and Codex CLI 0.162.1. Each agent passed 11 host checks: an allowed edit, one protected-edit attempt, an unchanged protected file, native Dogwood denial evidence, matching policy records, and continued work after denial. Claude used Read/Edit/Write; Codex used file-change tools without command execution.The 29 verdict/configuration regression tests passed, including false-pass mutations and compatibility checks for existing launchers. The existing run-validity and two-run harness checks passed. The final adversarial review found no remaining source blocker. These regression tests now run in the existing verdict CI job; the live model tests remain explicitly selected and require a signed macOS 27 build. Current Linux CI remains pending.
The signed runtime remains
5769dc1; commit05f3caechanges the workload harness, tests, CI, and documentation. The logs also contain denied agent setup operations: Claude local-socket creation and Codex skills-directory/rollout access. These file-edit tests do not validate every agent feature, rollout persistence, or structured policy errors delivered to the agent.Run the native agent workloads.
Current per-workload validation on macOS 27.0.1 (26A434):
independent_agent_and_tool_modes_survive_concurrent_forks_and_execcovers mixed selections.local_mcp_selection_is_independent_of_the_agentcovers local servers.a_disabled_agent_retains_containment_and_does_not_record_native_historycovers disabled history and retained filesystem grants.-D warnings.posix_spawn.For 1,000 repeated reads of one 4 KiB file, median total command times across three rotating runs were 8.69 seconds with tool mediation, 1.00 second with only that tool disabled, and 0.82 seconds with interception globally disabled. The agent was disabled in all three modes, and the policy permitted every request. Each run used a fresh box and workspace. These times include startup and shutdown. Disabling the tool was about 8.7 times faster for this test, while kernel delivery and launcher setup still added overhead. This test does not establish a Cargo build speedup or isolate internal policy/database costs.
The signed test source hashes match the final source. Linux validation remains pending. This PR remains a draft; these macOS results do not establish Linux support or every shutdown-failure behavior.
Earlier validation before per-workload selection
Local host: macOS 27.0.1 (26A434). The signed executable came from the current source. Source hashes match the test receipt.
Reproduce ordinary tests:
cargo test --release --workspace --all-targets --all-features --locked --no-fail-fastBuild and sign according to the native filesystem guide, then run:
STRANDS_BOX_SIGNED_TEST_BINARY=/absolute/path/KernelBox.app/Contents/MacOS/strands-box \ cargo test --manifest-path test-native-filesystem/Cargo.toml --locked -- --nocapturejust check, orcargo test --workspace --all-features). Results and remaining platform gaps appear above.cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsFormatting passed. Clippy passed with the repository's lint allowances, rather than the unmodified command above.
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.