Skip to content

feat(containment): share the container's /proc on masked hosts via [containment] private_proc - #58

Open
mufaddalq wants to merge 12 commits into
strands-agents:mainfrom
mufaddalq:fix/26-masked-proc
Open

mufaddalq wants to merge 12 commits into
strands-agents:mainfrom
mufaddalq:fix/26-masked-proc

Conversation

@mufaddalq

@mufaddalq mufaddalq commented Oct 10, 2026 •

Copy link
Copy Markdown

Status (2026-11-19): re-ported onto current main; no conflicts. What changed since the first version: record version 40 instead of 25, the shared /proc is read-only, and --target-env-json stays accepted beside --target-env-fd. box.toml now carries fifteen keys.

Description

Interface change, so it needs a maintainer's explicit call: one new box.toml key, a new record version for boxes that use it, and a new telemetry permit. The decision and its residual are recorded in docs/design/decisions.md.

box run cannot start in a standard, non-privileged Kata pod, or in any container whose runtime masks parts of /proc. The kernel's mount_too_revealing refuses a fresh procfs in a user namespace while those masks exist, whatever the mount call or option (mount, fsmount, hidepid, subset=pid were all measured). Today the only workaround is a privileged pod.

This change adds an explicit, box-wide opt-in:

[containment]
private_proc = false

With the key, the Linux namespace view binds the container's /proc (masks included) into each leaf instead of mounting a fresh one. Without the key, nothing changes. On a masked host, the box refuses and names the key.

Load-bearing decisions:

  1. What the workload still cannot do. It cannot signal any outside process, because the PID namespace still separates it. It cannot trace an outside process or read its memory, environment, descriptors, root, or cwd. The kernel's capability check (cap_ptrace_access_check) refuses ptrace-class access from a user namespace to any process outside it. That holds at ptrace_scope=0 and for dumpable targets. It covers the box daemon, the trampoline's launcher (which keeps its capabilities in the workload's user namespace), and other leaves (sibling user namespaces).
  2. What it can do (accepted residual, pinned by tests, documented in config.md and decisions.md).
    • Read other processes' files: it can read their cmdline, stat, status, mountinfo, limits, cgroup, and net/*.
    • No writes through /proc: the shared /proc is mounted read-only, as the private one on main now is. The earlier version of this PR let the workload raise a same-uid process's oom_score_adj; that residual is closed and a test pins the refusal.
    • PID numbering: /proc keeps the container's PID numbering, so only /proc/self names the workload.
  3. No leaf environment on a command line. Because the process list becomes readable, the trampoline gains --target-env-fd <fd>, and the box always uses it. --target-env-json <json> stays accepted, because the containment tests on main use it; the two are exclusive and one is required. Both are the trampoline's own CLI, not public. The Linux launcher keeps its argv for the box's whole life, so this matters even without the key.
  4. Explicit, never automatic.
    • No silent fallback: Box never falls back to the shared /proc on its own.
    • Telemetry: every leaf that shares records proc:shared, covering the agent, each tool, and each stdio MCP server.
    • macOS: refuses the key, because Seatbelt cannot show the workload other processes.
  5. The refusal points at the key only when that is the cause.
    • Containment's message: it names the masked /proc.
    • Box's hint: the box adds the key hint only when containment's message carries that cause. For the agent, whose stderr goes to the terminal, the box instead re-asks the kernel for a fresh procfs.
    • Why not the mount table alone: a masked host also mounts unrelated filesystems under /proc (binfmt_misc).

Interface changes.

Out of scope:

For maintainers: as an outside contributor, my CI and Auto Strands Review runs wait for approval (action_required / manual-approval). Could someone approve them? Thanks.

Related Issues

Closes #26
Related: #21

Type of Change

New feature

Testing

Re-ported onto main at 3415baa on 2026-11-19 (head 26149c9). Results for that head:

  • Masked host: a non-privileged arm64 container, uid 1000, no capabilities, runtime-default /proc masks. shared_proc_linux.rs 8 passed, box_shared_proc.rs 4 passed. a_shared_proc_workload_reads_mounts_and_sockets_and_cannot_write_an_oom_score pins the read-only mount.
  • Linux aarch64, privileged container: clippy with -D warnings is clean for strands-box and strands-box-containment. strands-box-containment, and the strands-box lib, box_telemetry, and four_inputs tests pass, except five tests that need a non-root account (nonroot_directory_grants_preserve_creation, a_failed_workload_fork_terminates_the_namespace_reaper, two hardening tests, and an_unreadable_server_cannot_later_claim_a_grammar_permit).
  • macOS arm64: strands-box-containment passes. strands-box passes except denied_executable, shell_dependency_guard, and one intermittent runtime_terminal test; each fails the same way on unmodified main on the same host.
  • Not run on this head: fork CI, x86-64, and a real Kata pod. The Kata result below is from the earlier head.

Results below are from before the re-port.

  • Rebased onto main at 069c39c on 2026-10-19; fork CI on the rebased head: run. The run below is from before the rebase.
  • Fork CI (run): every job green, including both Containment / Deterministic legs (ubuntu-24.04-arm, macos-latest), both Unit Tests legs, Lint, and Verdict. On the first attempt the macOS Deterministic job failed one harness unit test, test-integ egress::tests::a_stream_accepted_during_stop_is_shut_down_and_stop_stays_bounded (a stop-race timing test in a file this PR does not touch); all 129 deterministic cases passed in that attempt too, and the rerun was green.
  • Real Kata, the issue's environment. EKS 1.37 with Kata 4.2.0 kata-qemu on c6g.metal (guest kernel 6.18.35), in a non-privileged pod running as uid 1000 with CapEff=0 and the runtime's /proc masks. The acceptance script passed 7/7:
    • With the key:
      • box run succeeds.
      • The workload sees the strands-box run process.
      • It cannot open that process's environ, mem, fd/0, maps, or root, and kill -0 fails.
    • Without the key: the box refuses: containment setup failed during containment apply: set [containment] private_proc = false in box.toml ….
    • Positive control: the same probe opens the workload's own environ, mem, and root.
    • Timing: a no-op box run takes about 805 ms (debug build). The privileged-pod baseline was 775 ms (release build).
  • Masked host locally: a non-privileged arm64 container, uid 1000, no capabilities, runtime-default /proc masks.
    • shared_proc_linux.rs, 8 tests, covering:
      • no reach to an outside same-uid process, to the launcher, or to a second contained workload
      • a positive control for the probe
      • residual pins for cmdline, mountinfo, net/tcp, oom_score_adj, and PID numbering
    • box_shared_proc.rs, 4 tests: end to end with the key, the refusal naming the key, no reach to the box process, and no declared env value on any process's cmdline.
  • Linux aarch64, privileged container, rust 1.98.1: strands-box-containment all pass.
    • strands-box: every failure also fails, identically, on main (83075df) in the same environment:
      • two hardening tests (root container)
      • box_shell::a_signalled_host_binary_records_128_plus_the_signal_in_history
      • box_direct_filesystem::this_boxs_authority_survives_a_rename_of_its_parent (EBUSY)
      • runtime_mcp_start, runtime_mcp_policy_staging, and native_egress_mcp (the fixture's list grant has no Linux lowering)
  • macOS arm64: cargo test -p strands-box-containment -p strands-box --all-features, 0 failures.
  • Lint: cargo fmt --check, and cargo clippy --workspace --all-targets --all-features -- -D warnings with CI's allow-list, are clean.

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

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

🤖 Generated with Claude Code

muffadalq and others added 10 commits October 19, 2026 13:10
The trampoline took the composed environment as --target-env-json <json>.
On Linux the launcher that waits outside the PID namespace keeps that argv
for the box's life, so /proc/<pid>/cmdline exposed every leaf's declared env.
Box now writes it to a private file beside the containment config and passes
--target-env-fd <n>; the trampoline reads it before apply and closes it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…g the container's /proc

A host that masks /proc refuses every fresh procfs in a user namespace. For
AllowAll the view now binds the container's /proc recursively, masks
included, and remounts only the top mount nosuid,nodev while keeping any
flag the kernel locked. Isolated still mounts a fresh procfs.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…/proc with every leaf

Adds a tenth top-level box.toml key, [containment], with one field,
private_proc (default true). false maps to ProcessInfoMode::AllowAll for
the agent, every tool, and every stdio MCP server, and stores the box at
record version 25 so an older build refuses it; every other box keeps the
version main gives it. macOS refuses it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…r's /proc

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A masked host also mounts unrelated filesystems under /proc (binfmt_misc),
so the mount table alone pointed every Apply failure at private_proc. A
leaf's refusal now needs containment's own wording in its detail; the
agent's never reaches the box, so the box asks the kernel for a fresh
procfs itself.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The cross-leaf test probed the first workload's launcher, which the
capability check protects whatever happens to the workload. It now
probes the workload, by the PID it reads in the shared /proc.

New pins and docs for what the final review measured: an outside
process's mountinfo and net tables are readable, a same-uid process's
oom_score_adj is writable, and /proc keeps the container's PID numbering
so only /proc/self names the workload.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@mufaddalq

Copy link
Copy Markdown
Author

Status: this branch now conflicts with main in 14 files, and record version 25, which it claimed for private_proc, has since been assigned (FILE_ATTRIBUTES_RECORD_VERSION). Bringing it up to date is a re-port onto the current config and trampoline code, not a plain rebase, and it needs a new record version.

main still has no way to start in a masked-/proc container, so #26 is unchanged and I still intend to do that re-port. Because it carries an interface change (the [containment] private_proc key, a record version, and a telemetry permit), I would like a maintainer's call on the approach before I redo it: is an explicit opt-in that shares the container's /proc, with the residual listed in the description, acceptable in principle?

muffadalq and others added 2 commits November 19, 2026 10:04
## Problem

This branch conflicted with main in 14 files. Record version 25, which it
used for `[containment] private_proc = false`, now belongs to
`file-attributes`. Main also made the private procfs read-only and moved
mounts onto pinned targets.

## Solution

- `private_proc = false` is stored at record version 39.
- The shared `/proc` is established through a pinned mount target, like
  every other bind, and is remounted read-only. A workload can no longer
  write a same-uid process's `oom_score_adj`.
- The trampoline accepts `--target-env-fd` beside `--target-env-json`. The
  two are exclusive, and one is required. The box always passes the
  descriptor, so no environment text is on a command line. The inline flag
  stays because the containment tests on main use it.
- `box.toml` now carries fourteen keys.

## Tests

- Masked `/proc`, uid 1000, no capabilities, arm64 container:
  `shared_proc_linux` 8 passed, `box_shared_proc` 4 passed.
  `a_shared_proc_workload_reads_mounts_and_sockets_and_cannot_write_an_oom_score`
  pins the read-only mount.
- Privileged arm64 container: `strands-box-containment` passes except
  `nonroot_directory_grants_preserve_creation` and
  `a_failed_workload_fork_terminates_the_namespace_reaper`. `strands-box`
  lib, `box_telemetry`, and `four_inputs` pass except three lib tests.
  All of these need a non-root account. Clippy is clean.
- macOS arm64: `strands-box-containment` passes. `strands-box` passes
  except `denied_executable` and `shell_dependency_guard`, which fail the
  same way on main on this host.
- Not run: x86-64, and a real Kata pod.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
## Problem

Seven commits on main conflicted with this branch in ten files. Main
assigned record version 39 to `[secret-source]`, and added that key.

## Solution

- `private_proc = false` is stored at record version 40.
- `box.toml` now carries fifteen keys.
- The agent's masked-`/proc` hint is kept inside the shutdown path that
  main added to `Contained::wait`.

## Tests

- Masked `/proc`, uid 1000, no capabilities, arm64 container:
  `shared_proc_linux` 8 passed, `box_shared_proc` 4 passed.
- Privileged arm64 container: clippy is clean. `strands-box-containment`
  and the `strands-box` lib, `box_telemetry`, and `four_inputs` pass,
  except five tests that need a non-root account.
- macOS arm64: `strands-box-containment` passes. `strands-box` passes
  except `denied_executable`, `shell_dependency_guard`, and one
  intermittent `runtime_terminal` test. Each fails the same way on main on
  this host.
- Not run: x86-64, and a real Kata pod.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@mufaddalq

Copy link
Copy Markdown
Author

I went ahead with the re-port instead of waiting, so the branch is reviewable again. It is merged with main at 3415baa and has no conflicts.

What differs from the first version:

  • Record version 40, not 25. main has assigned 25 through 39.
  • The shared /proc is read-only. main made the private procfs read-only, so the shared one now matches, and it is established through a pinned mount target like every other bind. This closes the residual I listed before: a workload can no longer raise a same-uid process's oom_score_adj. The test that pinned the residual now pins the refusal.
  • --target-env-json stays. The box always passes the environment by --target-env-fd, so no environment text is on a command line. I kept the inline flag on the trampoline because about twenty containment tests on main use it; the two flags are exclusive and one is required.
  • box.toml is fifteen keys, with [secret-source] and [containment].

Tested on this head: the masked-/proc container as uid 1000 with no capabilities (shared_proc_linux 8 passed, box_shared_proc 4 passed), a privileged arm64 container, and macOS. The description lists the failures that need a non-root account or that also fail on main. I have not rerun a real Kata pod or x86-64 on this head, and the upstream workflows still need a maintainer to approve them.

My question above still stands: is an explicit opt-in that shares the container's /proc acceptable in principle?

This branch has not been deployed

No deployments
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.

[FEATURE] Linux: run in an unprivileged container with a masked /proc (e.g. Kata pods)

1 participant