Skip to content

feat: enforce native filesystem policy on Linux - #181

Merged
kevin-orellana merged 3 commits into
feature/linux-native-launch-prepfrom
feature/linux-native-policy
Oct 27, 2026
Merged

kevin-orellana merged 3 commits into
feature/linux-native-launch-prepfrom
feature/linux-native-policy

Conversation

@kevin-orellana

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

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: Linux workloads can reach files through direct system calls without consulting the authored filesystem policy. The experimental selection already exists, but Linux has no production adapter behind it.

Solution: Add the Linux adapter for selected workloads. It checks opens, creation, deletion, renames, and truncation against the same policy and history as other Box operations. The worker acts on pinned objects. Kernel identity checks prevent deletion or renaming of a replacement object after authorization.

Trade-off: This implementation requires seccomp descriptor transfer and BPF security hooks. Qualification covers ARM64 Linux. Existing file descriptors retain their access. Linux permission changes remain governed by static write grants. Independent metadata queries and link-target reads remain deferred. Performance and capacity qualification are separate work.

Description

This PR depends on #186. Its preparation-branch base exists for review only. Merge #186 into main first, update this branch from main, then retarget this PR to main. Do not merge this PR into the preparation branch.

The trusted loader uses CAP_BPF and CAP_PERFMON, then removes its capabilities before runtime threads and workloads start. The workload hands its notification listener and captured filesystem root to Box before execution. Unsupported setup stops launch.

Containment::apply gains a fourth optional native-registration socket argument. Existing callers pass None. Workload selection, policy actions, record versions, and the public broker protocol stay unchanged.

A runtime probe checks actual O_PATH descriptor transfer. Supported kernels can issue policy-authorized path-only handles that cannot read contents. Unsupported kernels refuse only path-only opens and print the limitation. Unexpected probe failures stop startup.

Ordinary symlinks and parent components resolve within the captured workload root. Authorization uses the resolved object. Mutation requests preserve trailing-slash requirements and refuse final dot components. Tests cover the destructive suffix defect found during review.

The library retains its readiness callback ordering, including callbacks that create the configuration. The trampoline retains parent acknowledgment before configuration loading, followed by native registration before execution.

Related Issues

Implements the Linux adapter tracked in #127. Target release acceptance and performance qualification remain separate.

Type of Change

New feature

Testing

Current head: 5c85b1307d1319e6884307f4453e454945bcf443. Every production and test file matches tested repair candidate 36c0bdc610e8d399eb1d6a260d50c430c415e524. Independent review verified all 912 tracked entries. The merge changes only the CI branch filter and preserves preparation ancestry. Broad compatibility checks ran at 4e4cca8fcf215b15c8d0167c000759bdcc22a593. The affected native checks were rerun after the shutdown repair.

Check Result
Complete workspace regression run before shutdown repair 4,501 passed and 17 existing ignores. Two failing targets exposed the regressions repaired below.
Box and containment suites before shutdown repair, all features 1,525 passed, 0 failed, 6 existing ignores. The library callback executable also passed.
ARM64 native integration suites after shutdown repair 121 passed: policy/history, paths, directories, selection, capability removal, and shutdown.
Failure injection and replacement races after shutdown repair 44 passed, including 27 failure cases and 17 identity-race cases.
Selection consistency The existing matrix now checks raw configuration and normalized records against each expected result.
Kernel adapter library tests after shutdown repair 18 passed with loader capabilities, including the actual kernel guard.
Trampoline tests 48 passed. Independent review reran all 6 launch-gate checks.
Positive path-only descriptor transfer 2 probe/handler tests passed in an isolated supported test kernel.
macOS compatibility before shutdown repair All-targets checks passed for Box and containment with all features. The repair changes Linux code and tests only.
Feature-disabled build Box and containment built with no default features.
Scripted examples The repository example runner reported no remaining scripts. No example coverage is claimed.
Formatting and lint Formatting and diff checks passed. Workspace Clippy passed with repository allowances; changed owned crates passed strict Clippy after the final fixes.

The positive O_PATH run uses an isolated Linux 6.18.56 test kernel with upstream O_PATH transfer support backported. The same boot records PATH_HANDLES=true and passes the policy/descriptor handler tests. This is kernel-transfer and handler coverage, not full Box qualification on a stock distribution with that capability.

The complete workspace run exposed callback ordering and initial launch acknowledgment regressions. Both were repaired, and the affected Box and containment suites were rerun. Existing ignored tests remain ignored; no security test was removed or newly ignored.

Adversarial review also found that immediate workload exit could hide a fatal outcome-storage error. The new immediate-exit regression failed before repair. After repair, shutdown returns the original storage error, and the successful control still records its outcome. Independent replay confirmed three failure cases and one successful control.

The hosted review of 4e4cca8 raised two comments. The README now documents all four containment arguments. The selection test now checks agreement between raw configuration and normalized records. Each phase keeps its own traversal because its input representation differs.

Local review included destructive-path controls, readiness callbacks, startup deadlines, and shutdown error propagation. Hosted review assessed the authorization and identity paths. Formal human approval remains separate.

  • 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 workspace lint command uses the existing justfile allowances: clippy::too_many_arguments, clippy::only_used_in_recursion, clippy::await_holding_refcell_ref, clippy::explicit_auto_deref, clippy::chunks_exact_to_as_chunks, dead_code, and non_snake_case. The changed owned crates also pass strict Clippy with --no-deps and without those allowances. An unrestricted strict run stopped on six existing Shell warnings; those files match the base revision.

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

The interface migration and baseline callback regression are in #186. This dependent diff keeps the complete platform adapter, its identity protections, and its tests together. Start with the Linux broker and identity guard, then review monitor lifecycle, containment setup, and tests.


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

## Problem

Selected Linux workloads need filesystem policy checks over their direct system calls. Static filesystem grants alone cannot enforce the authored policy or its shared history.

## Solution

Add the Linux notification adapter and task-bound kernel identity guard. The worker resolves paths under the captured workload root and acts on approved objects. The loader removes its capabilities before runtime threads start.

Containment::apply gains the approved fourth optional native-registration socket argument. Existing callers pass None. Selection fields, policy actions, record versions, and the public broker protocol stay unchanged.

Probe actual path-only descriptor transfer. Refuse unsupported path-only opens and report the limitation. Preserve ordinary symlinks, parent components, mutation suffix requirements, callback ordering, and the initial launch acknowledgment.

## Tests

linux_native_paths covers path resolution, policy denial, path-only handles, and destructive suffix regressions. All 120 native integration cases passed. linux_native_failures and linux_native_entry_races passed 42 failure and identity-race cases. All 18 native kernel library tests passed.

The complete workspace run exposed failures in box_library and the containment trampoline. Both were repaired. The final Box and containment suites passed 1,525 tests with six existing ignores; the callback executable also passed. All 48 trampoline tests passed.

Independent review reran nine suffix controls, callback initialization with and without loader capabilities, and six launch-gate cases. The positive-kernel VM passed both probe/handler tests with path-only transfer enabled. This does not qualify a complete Box run on a stock supported-transfer kernel.

macOS all-targets checks, formatting, workspace lint with repository allowances, and strict owned-crate lint passed. Performance, capacity, metadata/readlink expansion, signed macOS runtime qualification, and target release acceptance are not claimed.
Comment thread crates/containment/README.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment

A large but cohesive single-platform adapter. The enforcement core is carefully written and the authorization model is sound: validate-then-act with pinned objects, host/box identity reconciliation on every path, a BPF token keyed to the worker task's kernel identity to defeat replacement races, fail-safe watchdog/deadline handling, and O_PATH-transfer capability probed before startup. Fault injection is gated behind the box_native_test_faults cfg and is a no-op in production builds, and the descriptor-handoff receiver validates the control message strictly. Test coverage (paths, directories, failures, entry races, research) is thorough and drives real workloads.

Review Categories
  • Interface freeze: Containment::apply gains a fourth optional argument — an observable change to a frozen surface. It is documented in the README table/example and containment/AGENTS.md in the same commit and defaults to None, so it carries its page as required; the only gap is the now-stale README prose (inline comment).
  • Documentation: The containment README section describing apply still says "two arguments" and documents only the egress handoff, which contradicts the updated signature.
  • Maintainability: The native opt-in predicate is computed in two places (selected vs uses_native_filesystem); a minor drift risk worth consolidating.
  • Security / correctness: No issues found in the authorization, identity-reconciliation, or descriptor-handoff paths on the ARM64-Linux scope the PR qualifies.

Nicely engineered and well-tested work; the findings are documentation and tidiness only.

@kevin-orellana
kevin-orellana changed the base branch from main to feature/linux-native-launch-prep October 27, 2026 19:07
@kevin-orellana
kevin-orellana merged commit 83619b9 into feature/linux-native-launch-prep Oct 27, 2026
@kevin-orellana
kevin-orellana deleted the feature/linux-native-policy branch October 27, 2026 19:07
@kevin-orellana
kevin-orellana restored the feature/linux-native-policy branch October 27, 2026 19:12
@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

The two-PR split continues in #186 (preparation) and #188 (native adapter). This PR's existing auto-merge setting fired when its base changed. A forward revert restored the preparation branch to its exact tested tree. main was not changed. #188 preserves the reviewed feature code and links this discussion. Neither replacement PR enables auto-merge.

@github-actions

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed at 36c0bdc (previously reviewed 4e4cca8). The new commit "retain native policy failures through workload shutdown" is a well-targeted fail-safe fix and also resolves both of my earlier comments.

What changed since the last review
  • Race fix (correctness/security): State now records the first fatal reason in a OnceLock<String> via the new fail() helper, and stop() returns that reason after joining the workers/watchdog. This closes the window where an immediate workload exit could win the supervisor's select before the fatal mpsc channel was drained, previously letting a policy-enforcement failure be masked by a successful exit. First-writer-wins and idempotent — correct.
  • Tests: immediate_exit_preserves_a_completed_native_outcome and immediate_exit_cannot_hide_an_outcome_storage_failure exercise exactly that race (the failure workload now skips its gate for the exit op so it exits instantly after the operation). Good coverage of both the success and fault paths.
  • Resolves prior comment ci: Bump taiki-e/install-action from 2.87.21 to 2.87.22 #1 (docs): containment/README.md heading is now "apply takes four arguments" and documents both confirm_fd and native_filesystem_handoff.
  • Resolves prior comment ci: Bump aws-actions/configure-aws-credentials from 4.2.1 to 6.3.0 #2 (duplication): rather than consolidating selected() and uses_native_filesystem(), a test now asserts the two agree for the same inputs, which guards against drift — an acceptable response to the suggestion.

No new concerns. Nicely done.

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.

2 participants