Skip to content

feat(box): check native file permission changes with policy - #151

Merged
kevin-orellana merged 4 commits into
mainfrom
feature/native-permission-checks
Oct 26, 2026
Merged

kevin-orellana merged 4 commits into
mainfrom
feature/native-permission-checks

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: Native file checks cover selected operations, but they do not yet ask policy before changing Unix file permissions.
A filesystem write grant can therefore permit these changes without the additional Dogwood check.

Solution: For selected workloads, check permission changes on regular files and directories through the existing fs:write action and set_permissions operation.
This includes chmod and fchmod, which changes permissions through an open file descriptor.
A denial prevents the change. A permit remains subject to the sandbox grants and other operating system checks.

Trade-off: Permission changes now add policy evaluations and durable history records.
A policy that forbids these changes can now stop build tools that make generated files executable.
The policy receives the path and operation, but cannot inspect the requested permission bits.
The feature remains experimental and uses the existing workload selection.

Description

Subscribe to Endpoint Security permission-change authorization and notification events.
Decode the target's existing file type and identity, then use the existing path checks before and after policy evaluation.
Refuse unsupported target types and malformed paths or identities.

This deliberately extends native policy checks, as requested by the operator.
It adds no configuration field, policy action, operation enum, stored record, or protocol field.

FAQ

Which Dogwood policy matches this?

The action is Box::Action::"fs:write". The operation is Box::FsWriteOperation::"set_permissions".
A policy can forbid permission changes while other permitted writes continue:

forbid(principal, action == Box::Action::"fs:write", resource)
when {
    context.input.operation == Box::FsWriteOperation::"set_permissions"
};

This rule grants nothing. Existing permit rules still determine which other requests succeed.

Does this check every filesystem operation?

No. Attribute changes, timestamps, links, copies, and metadata reads need their own event mappings and compatibility tests.
A missing Dogwood mapping does not establish that the sandbox permits the operation.
This change does not revoke access through an already-open file or address loss of interception after the trusted process dies.

Related Issues

Related to #117. That issue tracks broader failure behavior and remains open.

Type of Change

New feature

Testing

Tested on macOS 27.0.1, ARM64. The code and tests match commit 3f841c0.
The signed run used base 250ca537 plus this code change; later edits changed documentation only.

Check Result and scope
Signed native suite 23 passed, zero failed or skipped. Both new permission tests cover files, directories, child processes, and descriptor calls.
Controlled C bridge Passed. Removing the subscription or copying the requested mode instead of the target mode makes the check fail.
Adapter unit tests 17 passed with the macos_enforcement filter. The broader Box unit run reported 609 passes.
Independent review No source defect found. Both permission tests passed against the signed candidate and failed against a historical pre-change signed binary. This historical control is not an isolated source mutation.
Deterministic integration suite GREEN: 121 passed, zero failed, eight declared Linux-only skips. All 129 expected cases produced records.
Formatting and lint Workspace formatting and just clippy passed. Separate native-package formatting and strict clippy passed.
Feature disabled build cargo build -p strands-box --no-default-features passed with one existing containment::render_profile dead-code warning.
Full workspace gate just check failed in two box_project startup tests. It reported 785 passes and four ignored tests before stopping. Later suites did not run.

The two failed tests are a_run_on_a_running_box_is_refused_before_it_touches_an_alias and a_policy_edited_during_a_run_governs_the_next_run_and_not_the_running_one.
Both wait for a startup file without reading their child's output pipes.
A focused rerun reproduced the timeout. A stack sample showed the child blocked in __eprint / write before launching the workload.
The first test also failed against a build with native interception compiled out.
This isolates that timeout from the added SETMODE handler. The test-harness repair is outside this PR.

The existing committed signed receipt covers an older source snapshot; its freshness check is informational.
The fresh local signed suite and independent rerun supply the permission-change evidence above.
No fresh model-driven agent run or standard release qualification is claimed. Current-head hosted results appear in the CI repair sections below.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

The strict-clippy checkbox remains unchecked because CONTRIBUTING.md prescribes just clippy with existing vendored lint allowances. That recipe passed.

CI recorder shutdown repair

Commit c3b9394d16869fe84b86b91cebf16d8a4bda2fd0 corrects the host-recorder test that failed the macOS deterministic job. The existing test assumed a queued byte had been read before stop() shut down the accepted socket. macOS can instead refuse the handler's timeout option with error 22, or return end-of-stream before any byte is read. I reproduced the exact CI failure on the fifth focused run of an existing harness with byte-identical recorder source, without the permission-change feature.

The test now accepts only the recorded early-close outcomes for an empty observation. It retains the positive control, stop/accept ordering, one incomplete observation, shutdown deadline, peer-closure check, and empty handler/active-stream checks. No product code, timeout, test selection, or permission behavior changed.

Validation:

  • All 89 standalone harness library tests passed on macOS and Linux ARM64. The Linux run used cached Box for the existing fixture probes; this is not a new Linux product build.
  • The corrected macOS race test passed 500 consecutive runs.
  • Independent mutations removed shutdown or moved it before the accept-thread join. Both failed the unchanged 1.5-second bound at about five seconds.
  • Independent scoped build, all-target lint with warnings denied, formatting, no-default-features build, and review passed.

The unchanged PR head had already passed the failed-job retry. This commit addresses the reproduced recurring test race; the final hosted results and timing-test retry are recorded below. Existing native-feature validation and human ownership limits remain as documented above.

Linux Cargo fixture follow-up

After the recorder repair, the new hosted run exposed an interaction between merged #129 and #136. CN-W-06 writes its test-owned Cargo home but omitted that directory from its read roots. Linux correctly refused that unsupported write-only grant before Cargo ran. The failure was separate from the native permission-change feature.

Synchronized the branch with main without rewriting history. Commit 008ec573a865acb3349b179d1aa2d1e27409894c adds the exact Cargo-home path to the fixture's read roots. It changes one line and retains every compilation, execution, read-only-write refusal, ungranted-program refusal, protected-config refusal, and undeclared-output assertion.

The complete Linux Cargo case passed as the ordinary test user against the cached Linux Box runtime. Removing only the added read grant reproduced the exact hosted refusal. An independent reviewer repeated both controls and passed scoped build, containment-test compilation, warnings-denied lint, formatting, and no-default-features build. This is fixture validation against a cached runtime; the new hosted run supplies current-product coverage.

Final hosted validation for 008ec573a865acb3349b179d1aa2d1e27409894c: all executed checks passed, including Linux and macOS Rust suites, native macOS tests, lint, both deterministic suites, CodeQL, and CI Gate. Linux recorded 120 passes and nine declared skips; macOS recorded 121 passes and eight declared skips. Both recorded all 129 expected cases.

The unrelated catalog timing test failed the first macOS unit attempt at ratio 3.31, then passed the unchanged-head retry at 1.77 against the same limit of 3. No benchmark threshold or test selection changed. This clears the current failure, but does not permanently fix the shared timing instability also seen on #152. Final test and check evidence.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Codex prepared this change and reviewed the code. Kevin confirmed the author ownership checklist item.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

Native filesystem policy checks selected file operations but does not yet check Unix permission changes.
A selected workload can change permission bits within its filesystem grants without the additional Dogwood decision.

## Solution

Kevin requested this deliberate extension of native filesystem checks.
Subscribe to permission-change authorization and notification events, then map regular files and directories to existing fs:write / set_permissions requests.
Keep the kernel target identity and use the existing checks before and after policy evaluation.
Refuse unsupported target types and malformed paths or identities.

An existing fs:write forbid can now deny chmod and fchmod from selected workloads.
The change adds no configuration key, policy operation, stored record, or protocol field.
Each permission change adds a policy evaluation and durable history records.
Requested permission bits remain absent from the policy input.

## Tests

permission_changes_obey_dogwood_for_files_directories_and_children pins chmod/fchmod allow and deny cases for files, directories, and children.
permission_changes_preserve_selection_and_static_grants pins workload selection and static write grants.
permission_changes_check_the_existing_object_and_policy_operation pins operation mapping and rejected identities/types.
The controlled bridge check fails if the SETMODE subscription is removed or requested mode replaces target mode.

The signed macOS 27.0.1 suite passed all 23 native tests and the C bridge test.
All 17 adapter unit tests passed. Independent review reran both signed permission tests successfully.
The deterministic suite reported GREEN: 121 passed, eight declared Linux-only skips.
Formatting and just clippy passed with the repository's existing vendored lint allowances.
The no-default-features build passed with one existing containment warning.

just check stopped at two box_project startup timeouts, after 785 reported passes and four ignored tests.
A focused rerun also timed out. Its child blocked while writing startup text to an undrained stderr pipe before launching the workload.
No full workspace pass, hosted Linux result, or live agent validation is claimed.
@kevin-orellana
kevin-orellana marked this pull request as ready for review October 22, 2026 23:18
@github-actions

Copy link
Copy Markdown

Assessment: Approve (one non-blocking suggestion)

Focused, well-scoped change that extends native macOS enforcement to permission changes by reusing the existing fs:write / set_permissions surface — no new policy action, enum, config key, or protocol field, so no frozen-surface approval is needed. Behavior is fail-closed and consistent with the existing CREATE/UNLINK/RENAME arms.

Review notes
  • API/surface: Reuses existing FsOperation::SetPermissions (already mapped to fs:write in schema.rs); no public API or frozen-surface change — no API review required.
  • Correctness: C decode guards a null setmode.target and captures the existing st_mode purely for type detection; the Rust arm restricts to regular files/dirs with FILE_IDENTITY. Unsupported types deny (fail-closed), matching sibling operations.
  • Testing: Strong coverage across layers — Rust unit decode (files, dirs, parent-identity rejection, bad target types), C bridge decode, and signed integration over chmod/fchmod, directories, child processes, workload selection, and static grants. The event() helper defaults source_identity to FILE_IDENTITY, so the bad-type cases genuinely exercise type rejection.
  • Docs: native-filesystem-policy.md updated with coverage and the documented limitation that policy input excludes the requested permission bits.

Nicely layered tests make the enforcement behavior easy to trust.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

CI recorder shutdown repair

Commit c3b9394d16869fe84b86b91cebf16d8a4bda2fd0 corrects the host-recorder test that failed the macOS deterministic job. The existing test assumed a queued byte had been read before stop() shut down the accepted socket. macOS can instead refuse the handler's timeout option with error 22, or return end-of-stream before any byte is read. I reproduced the exact CI failure on the fifth focused run of an existing harness with byte-identical recorder source, without the permission-change feature.

The test now accepts only the recorded early-close outcomes for an empty observation. It retains the positive control, stop/accept ordering, one incomplete observation, shutdown deadline, peer-closure check, and empty handler/active-stream checks. No product code, timeout, test selection, or permission behavior changed.

Validation:

  • All 89 standalone harness library tests passed on macOS and Linux ARM64. The Linux run used cached Box for the existing fixture probes; this is not a new Linux product build.
  • The corrected macOS race test passed 500 consecutive runs.
  • Independent mutations removed shutdown or moved it before the accept-thread join. Both failed the unchanged 1.5-second bound at about five seconds.
  • Independent scoped build, all-target lint with warnings denied, formatting, no-default-features build, and review passed.

The unchanged PR head had already passed the failed-job retry. This commit addresses the reproduced recurring test race; hosted checks for the new head are being collected separately. Existing native-feature validation and human ownership limits remain as documented above.

@github-actions

Copy link
Copy Markdown

Re-review @ c3b9394 (previously reviewed 3f841c0)

The only delta since my last pass is the test-only commit "accept sockets closed before the recorder first read" touching test-integ/src/egress.rs. No product or feature code changed, so the permission-change review above still stands.

On the test change itself (a_stream_accepted_during_stop_is_shut_down_and_stop_stays_bounded): relaxing the assertion from a strict raw == "G" to "either the byte was read or the stream closed before the first read" is a reasonable fix for the macOS shutdown/read race. The relaxation is well-contained — the macOS EINVAL branch is cfg!(target_os = "macos")-gated, and the test still enforces the meaningful invariants (exactly one observation, incomplete, no request line, ended by shutdown not deadline). The matched error strings are produced in the same harness file, so the coupling stays internal.

Assessment: Approve (unchanged). The earlier non-blocking suggestion on mod.rs:237 (specific deny reason for unsupported SETMODE targets) remains open at the author's discretion.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

Linux Cargo fixture follow-up

After the recorder repair, the new hosted run exposed an interaction between merged #129 and #136. CN-W-06 writes its test-owned Cargo home but omitted that directory from its read roots. Linux correctly refused that unsupported write-only grant before Cargo ran. The failure was separate from the native permission-change feature.

Synchronized the branch with main without rewriting history. Commit 008ec573a865acb3349b179d1aa2d1e27409894c adds the exact Cargo-home path to the fixture's read roots. It changes one line and retains every compilation, execution, read-only-write refusal, ungranted-program refusal, protected-config refusal, and undeclared-output assertion.

The complete Linux Cargo case passed as the ordinary test user against the cached Linux Box runtime. Removing only the added read grant reproduced the exact hosted refusal. An independent reviewer repeated both controls and passed scoped build, containment-test compilation, warnings-denied lint, formatting, and no-default-features build. This is fixture validation against a cached runtime; the new hosted run supplies current-product coverage.

The preceding macOS deterministic job already passed with the recorder fix. New-head hosted checks are now running.

@github-actions

Copy link
Copy Markdown

Re-review @ 008ec57 (previously reviewed c3b9394)

The only delta is the test-only commit "grant explicit reads of the Linux Cargo home" — a one-line change in test-integ/tests/containment/cn_w_06.rs adding cargo_home.clone() to the read roots. The permission-change feature code is unchanged, so the prior review still stands.

The change is correct and well-scoped: cargo_home was already granted write but not read, and Cargo legitimately reads CARGO_HOME (registry/config/cache) during cargo run --offline. Granting the explicit read doesn't weaken the test — the negative controls (READ_ONLY_WRITE_REFUSED, UNGRANTED_PROGRAM_REFUSED, PROTECTED_CONFIG_REFUSED) are all retained.

Assessment: Approve (unchanged). The earlier non-blocking suggestion on mod.rs:237 (specific deny reason for unsupported SETMODE targets) remains open at the author's discretion.

@kevin-orellana

kevin-orellana commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Final hosted validation

Head 008ec573a865acb3349b179d1aa2d1e27409894c passes CI attempt 2. Every executed job now has a successful check status, including both Rust platform suites, native macOS build/unit tests, lint, both deterministic suites, and CI Gate. The separate CodeQL analyses passed.

  • Linux ARM64 deterministic result: 120 passed, zero failures/errors, nine declared skips; all 129 expected cases recorded. The repaired Cargo workflow passed against the fresh hosted product build.
  • macOS deterministic result: 121 passed, zero failures/errors, eight declared skips; all 129 expected cases recorded. The recorder shutdown test passed.
  • The first macOS unit attempt failed the existing catalog timing test at ratio 3.31 against the limit of 3. The unchanged-head retry passed at 1.77: 5.611 seconds for 256 pages and 3.167 seconds for 128 pages. No benchmark source, threshold, or test selection changed. This retry passed the test; it does not permanently fix the shared timing instability also seen on fix: reject unresolved host paths and bound native filename scans #152.
  • The automated reviewer inspected 008ec57 and approved the two test repairs. Its existing optional diagnostic-message suggestion remains open; this is not a formal human approval.

The recorder fix preserves the shutdown deadline, and the Cargo fix grants read access only to the already-writable test Cargo home. Neither change relaxes permission refusal assertions. Existing signed-native evidence, human ownership attestation, and release qualification limits remain unchanged.

@kevin-orellana
kevin-orellana merged commit 96de955 into main Oct 26, 2026
29 of 30 checks passed
@kevin-orellana
kevin-orellana deleted the feature/native-permission-checks branch October 26, 2026 17:52
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.

3 participants