Skip to content

test: cover mount restrictions in nested user namespaces - #267

Merged
kevin-orellana merged 3 commits into
mainfrom
feature/linux-nested-namespace-regressions
Nov 3, 2026
Merged

kevin-orellana merged 3 commits into
mainfrom
feature/linux-nested-namespace-regressions

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem. Box removes Linux capabilities before the workload starts. Creating or entering a nested user namespace can grant capabilities again within that namespace. Existing tests check startup removal and permitted calls, but do not exercise the later mount restrictions. A source comment also attributes mount refusals to capability removal and no_new_privs.

Solution. Add behavioral regression tests for seven namespace creation and entry routes. Each route has a successful, uncontained control in a private mount namespace. The contained route must regain scoped capabilities while mount and fsopen remain refused. A second test checks ordinary process and thread creation. Correct the source comment and the crate agent guidance. Explain the capability boundary in the Linux design guide.

Trade-off. This preserves current namespace behavior and its shared-kernel exposure. It does not establish complete nested-sandbox support or security acceptance.

Description

The namespace test covers unshare with user-only and user-plus-mount flags, legacy clone, clone3, and three setns forms. Those entry forms use an explicit user namespace type, automatic type selection, and a process descriptor with combined user/mount flags.

The probe checks all five startup capability sets, namespace identity, restored capability sets, no_new_privs, and seccomp mode. It observes restoration before another executable runs. Parent deadlines and child alarms bound each probe. Prerequisite failures have explicit skipping: records; a contained refusal after a successful control fails the test.

ordinary_process_and_thread_creation_remain_available exercises fork, pthread_create, and posix_spawn through the production containment trampoline.

Independent mutation checks at a454e8059c30149043a58d11da933512fbe6d86e confirmed that the new tests fail when either mount call is permitted or process creation is refused. The restored source passes again. These temporary changes were confined to a separate review copy.

Earlier manual compatibility checks at a454e8059c30149043a58d11da933512fbe6d86e used the actual strands-box run launcher on non-root Amazon Linux 2023 ARM64, kernel 6.12.113, glibc 2.34:

Workload Result
util-linux 2.37.4, unshare --user The child runs inside Box.
Bubblewrap 0.12.0 with its sandbox enabled The uncontained control passes. Inside Box, capget is refused before the inner payload starts.
unshare --user --map-root-user The uncontained control passes. Inside Box, the identity-map write returns EPERM.

A separate control reproduces the mapping refusal without Box or seccomp by removing only CAP_SETFCAP from a parent namespace with user ID zero. This matches Linux's documented mapping requirement. These results do not measure a browser or Bubblewrap's mount behavior inside Box. They were not repeated after the conflict integration below.

Related Issues

None.

Type of Change

Documentation update

Other: Behavioral regression coverage for existing Linux restrictions.

Testing

Conflict integration on November 2

Merge commit fabc08ba2b080dd0625546c9a9c7618adf268721 incorporates main ef009143f5ed960d18c145c4fcc7063da1e9ec93. The conflict resolution keeps both the nested-namespace probes and the memory probes added by #241/#243. The reviewed namespace tests are unchanged. The resolution changes no runtime implementation and passed independent Codex review.

Local validation used non-root Amazon Linux 2023 ARM64, kernel 6.12.113, Rust 1.98.1, four build jobs, and four test threads. Linux startup consent was enabled. Formatting, the Box/containment build, and repository-configured workspace Clippy passed. The focused suites passed five tests: two namespace tests with all seven routes and no skips, plus three memory tests. The guide's 15 relative links and git diff --check passed.

cargo test --workspace --all-features --locked --no-fail-fast -- --nocapture exited successfully: 4,617 passed, zero failed, 17 ignored, plus the custom library harness. The raw Linux log audit failed because an installed-alias test omitted its assertions when its helper was absent. After the workflow's helper-install step, that test passed in the existing workspace test binary: one passed, 643 filtered, no skips. Its supplemental log audit passed. This completes one previously omitted test; it adds no unique test to the workspace total. An initial binary-target attempt selected zero tests and provides no assertion evidence.

The two other prerequisite omissions and all 17 ignored cases remain as described below. Workspace compilation emitted eight warnings in unchanged shell tests. Bare strict Clippy, local deterministic tests, mutation checks, and manual compatibility probes were not repeated for this merge. The policy performance output still reports the existing issue #150 latency target miss; passing tests do not establish that requirement.

Main subsequently advanced to db481935ec27d183e8b3aa4a87a518c0f55ece21 through #217. A read-only merge check found no conflict. Hosted checks for fabc08ba2b080dd0625546c9a9c7618adf268721 passed; the separate Verdict job was skipped. Automated review approved that head with one non-blocking documentation suggestion. This status refresh confirms the check conclusions. It does not add a new audit of hosted checkout revisions or aggregate test counts.

Earlier revision evidence

The following local and hosted results cover the earlier revisions named here. Local validation covers a454e8059c30149043a58d11da933512fbe6d86e, based on e4ca8b80359b2213d684de31cd6ef32e0d61478a. Follow-up 829770eddf3bc2bf4fd3d5920ab9e029f5552aef only corrects the crate agent guidance; Rust and test files are unchanged. That documentation delta passed independent review and git diff --check.

Check Result
Build Box and containment with --all-features Passed.
Focused namespace integration suite Two tests passed; all seven routes executed; no skips.
Independent mutation checks All three expected failures observed; restored tests passed.
Deterministic containment suite GREEN: 124 passed, nine macOS-only cases skipped, zero failures or errors.
Workspace suite (bash scripts/test-all.sh) 4,597 passed, zero failed, 17 ignored; one additional custom harness passed. Two existing prerequisite omissions are listed below.
Example build Passed. No scripted examples exist; the SDK tutorial was not executed.
Formatting cargo fmt --all --check and cargo fmt --all passed.
Repository-configured workspace lint Passed with the seven allowances from justfile. No new warnings.
Strict workspace lint (-D warnings only) Failed on six diagnostics in unchanged strands-shell code.
Containment build without default features Passed with 66 unused-code warnings in unchanged files.

Hosted tests used merge revision ae284cac0f6c098b914c8491eaa9a4051aed15ee. Its tree matches earlier head 829770eddf3bc2bf4fd3d5920ab9e029f5552aef's tree, 30be544f60490534c8c769833c469a08343b0f78.

Hosted check Result
Linux workspace Passed: 4,597 tests, zero failures, 17 ignored; all seven namespace routes ran.
macOS workspace Passed. Aggregate numeric totals remain unverified because the log parser could not pair every target with a final result.
Linux deterministic cases 124 passed, nine macOS-only cases skipped, zero failures.
macOS deterministic cases 121 passed, 12 Linux-only cases skipped, zero failures.

Linux's log audit confirms both new tests and only the two existing prerequisite omissions described below. The macOS job hides successful-test output, so its passing status does not prove that every prerequisite-dependent assertion ran. All scheduled checks passed. The separate Verdict job was intentionally skipped because its tool sources were unchanged.

  • 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 earlier strict command ran but did not pass. This conflict update reran the configured gate instead. Its six diagnostics concern argument count, recursion, a borrow across an await, and automatic dereferencing. The configured gate uses these allowances:

-A clippy::too_many_arguments
-A clippy::only_used_in_recursion
-A clippy::await_holding_refcell_ref
-A clippy::explicit_auto_deref
-A clippy::chunks_exact_to_as_chunks
-A dead_code
-A non_snake_case

The workspace skipped a live credential-daemon test because the daemon was absent. It also omitted the existing alias read-denial assertion; that test's write assertions ran. Its 17 ignored cases comprise six child probe entry points, five known behavior gaps, three long measurements, two live HTTPS fixtures, and one documentation example. Parent tests invoke the child probe entry points. The namespace suite had no skips or ignored cases in those earlier runs.

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

At Kevin's request, Codex reviewed this conflict resolution and recorded its validation. Formal human maintainer approval remains required.


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

## Problem

Linux can restore capabilities within a nested user namespace after Box clears
startup capabilities. Existing coverage does not check the later mount refusals.
A source comment incorrectly treats startup capability removal as a permanent
mount backstop.

## Solution

Add behavioral tests for seven namespace creation and entry routes. Each route
compares contained execution with a successful private-namespace control.
Check startup capability removal, namespace identity, scoped capability
restoration, and continued mount and fsopen refusals. Also check ordinary
process and thread creation through the production containment trampoline.

Correct the comment and document the capability boundary in the Linux design
guide. Runtime behavior, public interfaces, and namespace permissions stay
unchanged. The final namespace restriction policy remains undecided.

## Tests

- nested_user_namespaces_restore_scoped_capabilities_and_keep_mount_refusals
  passed all seven routes without skips. Both mount operations succeeded in
  matching uncontained controls and returned EPERM inside containment.
- ordinary_process_and_thread_creation_remain_available passed fork,
  pthread_create, and posix_spawn controls inside and outside containment.
- Three isolated mutation checks failed as expected when mount or fsopen was
  permitted, or process creation was refused. Both restored tests passed.
- bash scripts/test-all.sh passed 4,597 tests and one custom harness. It reported
  17 ignored cases and two existing prerequisite omissions: the credential
  daemon and an alias read-denial assertion. The example build passed, but no
  scripted examples remain. The SDK tutorial was not executed.
- bash test-integ/run.sh reported GREEN: 124 passes, nine macOS-only skips,
  zero failures, and zero errors.
- All-feature builds, formatting, configured workspace Clippy, and the
  containment build without default features passed. Bare strict Clippy failed
  on six diagnostics in unchanged strands-shell code. The configured lint gate
  uses the seven existing justfile allowances; the changed code has no warnings.
  The build without default features reported 66 unused-code warnings in
  unchanged files.

Validation ran on non-root Amazon Linux 2023 ARM64, kernel 6.12.113. Actual Box
runs plain unshare --user. Bubblewrap setup stops at refused capget; root mapping
stops at the identity-map write. Matching uncontained controls passed. These
observations do not establish complete nested-sandbox support. Native macOS,
browser compatibility, and security acceptance remain unverified.
@github-actions github-actions Bot added documentation Improvements or additions to documentation Area - Agent Containment strands-running labels Nov 2, 2026
@kevin-orellana kevin-orellana changed the title Test mount restrictions after nested user namespace changes test: cover mount restrictions in nested user namespaces Nov 2, 2026
@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 2, 2026 06:45
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Important (non-blocking): This PR fixes the wrong reason for mount refusal in syscall.rs, but crates/containment/AGENTS.md still gives the same wrong reason.

Example: In the "Nothing here refuses or detects root" list, the uid_map entry says: "Capabilities are still all dropped, so no flag or mount authority survives — but nothing detects the collapse." The new test nested_user_namespaces_restore_scoped_capabilities_and_keep_mount_refusals shows that this is false. After unshare/clone/clone3/setns, CapPrm, CapEff and CapBnd all become full again, and unshare(CLONE_NEWNS) succeeds. The seccomp filters are what keep mount and fsopen refused, not the capability drop. The new section in docs/design/linux-enforcement.md now says the correct thing, so two documents give opposite reasons for the same fact. Root AGENTS.md says "Docs ship with the code … in the same commit" and "One fact has one owner." The crate AGENTS.md is the file that agents read before they change the seccomp tables. With this sentence there, an agent can decide that the mount/fsopen MEDIATED entries are redundant.

Suggestion: Change that clause so the seccomp filters are the reason. For example: "Startup clears every capability set, and a nested user namespace restores them inside that namespace. The seccomp filters refuse the mount API (nested_user_namespaces_restore_scoped_capabilities_and_keep_mount_refusals)." If a crate AGENTS.md edit needs maintainer approval, mark it as a follow-up in the PR description instead.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Comment

The tests and the design-guide section are correct for every case I traced. I found one remaining issue: a stale copy of the corrected claim in crates/containment/AGENTS.md (see the separate comment). Nothing blocks the merge.

Checked and held
  • The new syscall.rs comment is accurate. SyscallPolicy::compile builds the permit filter with Errno(EPERM) for every number not listed, so open_tree_attr (467) is refused.
  • mount and fsopen are Disposition::Deny in MEDIATED and are absent from WORKLOAD_PERMITTED. So a contained EPERM comes from the filter, and the author's mutation check shows that the test fails when the filter permits the calls.
  • The expected full mask (u64::MAX >> (63 - cap_last_cap)) is correct. It matches the kernel, which resets the bounding set to full in a new user namespace.
  • Each route that does not apply on a host prints a skipping: record and does not fail. This follows root AGENTS.md ("skip rather than fail"). The view-control gate matches what Box itself needs (procfs in a new PID namespace).
  • The aarch64-only cfg matches the scope of linux-enforcement.md (ARM64) and the CI Linux runner (ubuntu-24.04-arm).
  • No frozen surface or premise changes. The diff touches only tests, a comment, and docs/design/.
  • I could not run the suite locally because the review runner is x86_64.

The uncontained control beside each contained route makes these regression tests trustworthy.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

Addressed in 829770e.

The crate guidance now separates startup capability removal from privileges restored within a nested user namespace. It attributes the mount and fsopen refusals to seccomp and names the regression test that verifies them. The separate root identity-mapping issue remains open.

The documentation-only delta passed independent review and git diff --check. Rust and test files are unchanged from the locally validated commit. Hosted checks are running for the updated head.

This resolves the capability-wording finding.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Approve

I re-reviewed at 829770e. The only change since a454e80 is in crates/containment/AGENTS.md (+4 −2); the Rust and test files are unchanged. The new wording resolves the earlier capability-wording finding, and I have no new findings.

Checked and held
  • The uid_map entry now says the right thing. Startup clears the capability sets, a nested user namespace restores them only inside that namespace, and seccomp refuses mount and fsopen. Each case I traced gives a result that matches the new text: a root-mapped workload with no nested namespace, a nested user plus mount namespace, and a nested uid_map write. The uid_map write is refused because of CAP_SETFCAP, which matches the PR's measurement.
  • The entry names the regression test instead of citing file.rs:LINE, as root AGENTS.md docs rule 3 requires.
  • The entry names only mount and fsopen. That is not wrong, because the same file already lists the full mount-creation API as denied.
  • All the checks from the earlier review still hold, because the code they cover is unchanged.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Approve (one non-blocking suggestion)

I re-reviewed at fabc08b, which merges main (ef00914). The PR's own diff is unchanged from 829770e; only hunk offsets moved, and the merge resolved cleanly. main now mounts the workload /proc read-only (view.rs, writable: false), and the new tests are unaffected: the contained probe only reads /proc/self/status, /proc/sys/kernel/cap_last_cap, and /proc/<pid>/ns/user (O_RDONLY/pidfd_open), and it writes no identity map.

Suggestion (non-blocking): After the merge, docs/design/linux-enforcement.md states the nested-user-namespace fact in two places, and the section this PR adds misses the half that main added.
Example: The read-only /proc paragraph from main says "The filters permit creation of nested user namespaces, but read-only /proc prevents writes to their user and group identity maps." The new "Capabilities inside nested namespaces" section, about fifteen lines later, says again that the filters permit unshare/clone/clone3/setns. It does not mention the identity maps, and the unmapped maps are a large part of why restored capabilities give little authority. Root AGENTS.md docs rule 3 says: "One fact has one owner."
Suggestion: Move the identity-map clause into the new section, for example: "…and the namespaces it owns. Read-only /proc prevents writes to their user and group identity maps." Then remove that sentence from the /proc paragraph, or link it to #capabilities-inside-nested-namespaces.

Checked and held
  • PR diff ef00914..fabc08b equals e4ca8b8..829770e (same seven files, same +815 −8), so the earlier checks still hold.
  • The read-only /proc, PR_SET_DUMPABLE, and terminal ioctl changes on main do not touch unshare/clone/clone3/setns/mount/fsopen or WORKLOAD_PERMITTED for those calls.
  • The crate AGENTS.md uid_map entry is still accurate after the merge.
  • One small point on the description, not the code: the unshare --user --map-root-user row ("identity-map write returns EPERM", attributed to CAP_SETFCAP) was measured before main made /proc read-only. On this head, the open for writing should now fail first, with EROFS. Consider noting that the row was measured on a454e80.

@kevin-orellana
kevin-orellana merged commit ab6c52c into main Nov 3, 2026
23 checks passed
@kevin-orellana
kevin-orellana deleted the feature/linux-nested-namespace-regressions branch November 3, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Agent Containment documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants