Repository navigation
Claim scope limits only for controllers the user manager was delegated - #156
Conversation
A trusted systemd-run on disk was taken as proof that the 2.1 native resource jail enforces CPU, memory and pid limits. The limits are applied by the user's systemd manager, which must be reachable and must have been delegated each cgroup controller; without that a scope fails to start or runs without the limit. tinybox_linux::ScopeProbe reads the manager's socket and the controllers delegated to user@<uid>.service. The resource backend claims Cpu, Memory and Pids from it, and a requested limit whose controller is missing is refused before anything starts.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Tiny Sweeper reviewReviewed head: Verdict: Ready for maintainer review · Priority: low Diagnostics and supporting detailsFull summaryPull request purpose (title): Claim scope limits only for controllers the user manager was delegated. Purpose (title): Claim scope limits only for controllers the user manager was delegated. The pull request stops the 2.1 native resource jail (`StartJailedExecWithResources`) from claiming CPU, memory and pid limits as enforced merely because a trusted `systemd-run` and `bwrap` exist on disk: those limits are applied by the user's own systemd manager, which must be running and reachable and must have been delegated the relevant cgroup controller, otherwise a scope either fails to start or starts with the limit silently missing. It adds `tinybox_linux::ScopeProbe`, which reads the manager socket (`$XDG_RUNTIME_DIR/systemd/private` or the session bus socket) and the user manager's `cgroup.controllers`, and the resource backend now claims `Cpu`, `Memory` and `Pids` only for delegated controllers, refusing an unenforceable requested limit with `UnsupportedOperation` before anything starts rather than dropping it. The same diff also downgrades the native jail's `Subprocess` claim to `Unsupported`, makes its kernel-isolation claim conditional on `bwrap` supporting `--disable-userns` (adding that flag to the argv), and makes the MicroVM backend refuse any egress policy at create. Review snapshot
Completeness: Complete What changedThe 2.1 native resource jail's claimed resource support is now derived from a host probe instead of assumed. `tinybox_linux::ScopeProbe` (`detect`, `from_parts`, `constraint_support`) reads the user manager socket under `$XDG_RUNTIME_DIR` (or a `unix:path=` session bus address) plus the user manager's `cgroup.controllers` file, and maps `cpu`, `memory` and `pids` to `Enforced` only when a manager is reachable and that exact controller name is listed. The backend holds that probe (`with_scope` for injection, `detect` by default), reports `Cpu`/`Memory`/`Pids` from it, and refuses a request carrying a limit whose controller is not delegated, returning the unsupported-operation error before binding resources or touching the command. The backend's `Subprocess` claim moves from `Enforced` to `Unsupported`, and its isolation level becomes `Kernel` only when the probed `bwrap` supports `--disable-userns` and `None` otherwise, with that flag threaded into `NativeJailCommand` and emitted by the argv builder on the bwrap side only when requested. The MicroVM backend now refuses any network policy that allows egress, since the VM has no network interface, instead of only refusing an allowlist. Documentation's preflight table gains a native-resource-jail row and a note, but that row still lists Subprocess as Enforced while the code reports `Unsupported`. The latest-push delta is unavailable: only the prior reviewed head and the current head are known, with no trusted base-to-head comparison. Features
Tests
FindingsNo active actionable findings. Before mergeNone. How this fits togetherflowchart LR
n0["NativeResourceBackend<br/>changed"]:::changed
n1["prepare_with_resources<br/>changed"]:::changed
n2["unavailable<br/>changed"]:::changed
n3["..._resource_limits_are_refused_before_spawn<br/>changed"]:::changed
n4["tempdir"]:::impacted
n5["resource_backend"]:::impacted
n6["...r_is_not_delegated_is_refused_not_dropped"]:::impacted
n7["config"]:::impacted
n8["...target_environment_off_every_command_line"]:::impacted
n9["...d_descendants_and_preserves_stream_events"]:::impacted
n1 -->|uses| n0
n1 -->|calls| n2
n3 -->|calls| n4
n3 -->|tests| n4
n3 -->|calls| n7
n3 -->|tests| n7
n5 -->|uses| n0
n6 -->|uses| n0
n6 -->|calls| n1
n6 -->|tests| n1
n6 -->|calls| n4
n6 -->|tests| n4
n6 -->|calls| n7
n6 -->|tests| n7
n8 -->|calls| n1
n8 -->|tests| n1
n8 -->|calls| n4
n8 -->|tests| n4
n8 -->|calls| n5
n8 -->|tests| n5
n8 -->|calls| n7
n8 -->|tests| n7
n9 -->|calls| n1
n9 -->|tests| n1
classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Agent review detailscritique
security
tests
commits
description
Evidence and run details
|
# Conflicts: # crates/tinybox-module/src/tinybus_module/native_jail.rs
Summary
The 2.1 native resource jail (
StartJailedExecWithResources) claimed CPU, memory and pid limits as Enforced once a trustedsystemd-runandbwrapwere on disk. The limits are applied by the user's own systemd manager. That manager has to be reachable, and it can only set a limit for a cgroup controller it was delegated. Without either, a scope fails to start or runs with the limit missing.New
tinybox_linux::ScopeProbereads both:$XDG_RUNTIME_DIR/systemd/private, or the session bus socket) exists;/sys/fs/cgroup/user.slice/user-<uid>.slice/user@<uid>.service/cgroup.controllerslists.The resource backend now claims
Cpu,MemoryandPidsonly for delegated controllers. A requested limit whose controller is missing is refused withUnsupportedOperationbefore anything starts, never dropped.Stacked on #154 (merge it first).
Related issue
Part of #27 (enforcement gaps: claimed versus enforced resource limits).
API or behavior changes
tinybox_linux::ScopeProbe(detect,from_parts,constraint_support).cpu), a 2.1 request for that limit is now refused where it was accepted before.disk_bytesis optional.Validation
On our Linux CI runner (user manager delegating
cpu memory pids,$XDG_RUNTIME_DIR/systemd/privatea socket), at c100cea:cargo fmt --all -- --check: clean.cargo clippy --all-targets --all-features -- -D warnings: 0 errors, same as main.cargo buildandRUSTDOCFLAGS="-D warnings" cargo doc: ok.cargo test -p tinybox-linux probe::scope: 4 passed.cargo test -p tinybox-module native_jail: 22 passed. The live native-resource tests ran (none skipped) and still pass with the probe in place.cargo test -p tinybox-linux -p tinybox-module -p tinybox-microvm: no failures, the same as main.cpufrom the manager alone: both probe tests fail.Tests
probe::scope:cpusetdoesn't count ascpu.a_limit_whose_controller_is_not_delegated_is_refused_not_dropped: with cpu and memory delegated but not pids, a request with a pids limit is refused and the command is left untouched. Everything else in the request is acceptable, so only the missing controller can refuse it.cpufrom the manager alone fails the probe tests.Documentation
docs/specs/constraint-preflight.md(the native resource jail row and note). Rustdoc onScopeProbe.Checklist
#[allow(...)],#[ignore], or relaxed lints.envcontents in the diff or the description