Skip to content

fix(sandbox): inherit permanent userns probe verdict - #20822

Merged
KiroCrewCaptain merged 1 commit into
kirodotdev:mainfrom
rubencu:fix/userns-probe-inherit-verdict
Oct 29, 2026
Merged

KiroCrewCaptain merged 1 commit into
kirodotdev:mainfrom
rubencu:fix/userns-probe-inherit-verdict

Conversation

@rubencu

@rubencu rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A gateway on a Linux host without usable user namespaces logs the permanent probe failure once per boot instead of once per sandbox child.

The user namespace probe caches its permanent verdict only in the process that runs it. Each sandboxed child starts a new Python process with a cold cache, repeats the fork and unshare probe, and writes the same WARNING with its own PID. One affected host logged 17 duplicate warnings in 57 minutes.

Why it matters

Repeated warnings hide actionable log events and make one permanent host limitation look like many new failures. Each child also repeats a probe whose permanent result is already known by its parent.

Not a goal

  • Changing the user namespace probe.
  • Changing backend selection or sandbox policy.
  • Caching or inheriting transient probe failures.
  • Changing the operator guidance for an unavailable backend.

What changed (motivation → approach → change)

In src/kiro_crew/sandbox_spawn.py, sandboxed_spawn_argv stamps every returned child environment with KIROCREW_SPAWNED and KIROCREW_SANDBOX_TOOL, including the degraded and no-backend paths. It writes the parent process's permanent Linux user namespace failure reason and remedy beside those stamps. It removes the value when no permanent verdict exists, so a transient failure and a caller-supplied stale value cannot propagate.

In src/kiro_crew/sandbox_wrap.py, a Linux child accepts the verdict only when both spawn stamps have their exact KiroCrew values. The child seeds its direct and background probe caches from the inherited permanent verdict. It neither probes nor logs. A child without the hint follows the existing probe and WARNING behavior. The src/kiro_crew/sandbox.py compatibility facade and test/test_sandbox_refactor_facade.py ownership inventory expose and pin the new owner names.

The hint cannot widen capability. It can only seed a permanent failure and select the same none result that an identical probe returns. It cannot select the namespace backend. The chokepoint overwrites or removes any caller value after the environment scrub. A process that can choose all three values for another process already controls that descendant's exec environment, and existing kernel confinement survives exec.

The per-process SECURITY: no OS-level sandbox warning from _warn_no_isolation is unchanged, deliberately. It states that this process's own agent subprocesses run without credential isolation, so each child still logs it once. agent.sandbox_allow_no_isolation remains the operator's acknowledgment that downgrades it to INFO. Only the host probe's permanent verdict is inherited.

Backwards compatibility

Compatible: parent probe behavior, backend selection, failure guidance, and transient retries keep their existing contracts.

Removes nothing: the change carries one already-known permanent verdict into a child process.

Tests

test/test_sandbox_backend_cache.py covers the production and rejection paths through the real sandboxed_spawn_argv environment chokepoint:

  • A parent with a permanent verdict and no KIROCREW_SANDBOX_ACTIVE marker replaces a forged caller value, spawns a child, and the child performs no direct or background probe and emits no probe log.
  • A child without the hint probes and logs as before.
  • A hint outside a KiroCrew-stamped process tree is ignored.
  • A transient verdict is not inherited, and a stale caller value is removed.

The current head is 09585d82a1, one commit directly on 37e010610c and a clean rebase of 8f5a4776d6. Main's changes since then (in sandbox.py, sandbox_wrap.py, test_sandbox_backend_cache.py and test_sandbox_refactor_facade.py) moved only context around this change's hunks: every per-file patch ID is identical. It was validated as 67e406fea7, the same patch on 83986247fb; main's five newer commits touch none of this change's files. There, the complete sandbox selection (every test_sandbox*.py and test_*sandbox*.py module) passed (3,593 tests, 20 skipped), and Black, subprocess encoding, isort, flake8, mypy, Comment History, brand, docs lint, file line cap, harness parity, and the flake-pattern and wait-discipline ratchets pass. On this head, the repository-wide facade-mirror, link-screen and dashboard-files composition guards pass (147 tests). On f2ac3dab44, the focused cache, facade, create-guard, and spawn-audit selection passed 663 tests, and the new tests passed 20 times serially, 10 times with four workers beside their neighbors, and in reverse order; the related-test local gate's 84 failures and seven collection errors on that base reproduced on pristine main at the time.

Manual verification

On a Linux host where unshare(CLONE_NEWUSER) fails with EPERM, at f2ac3dab446f with an isolated KIROCREW_HOME, a parent ran the real probe and logged one permanent WARNING. It built each child through the real sandboxed_spawn_argv (first-party no-backend path, systemd-run scope). Fresh child interpreters importing kiro_crew.sandbox resolved none on both the direct detect_backend and the warm_backend paths, with zero _probe_unshare_once calls and no probe log. The same child with only _KIROCREW_USERNS_FAILURE removed probed once and logged the WARNING.

Related Issues

Closes #20811

Pattern harvest

Rule candidate: review-prompt
Pattern: a parent process caches a permanent host capability verdict but repeatedly spawned children do not inherit it and repeat the same probe and warning.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (not applicable because behavior and configuration do not change)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license. See the Licensing section of CONTRIBUTING.md.

@rubencu
rubencu requested review from a team and KiroCrewCaptain as code owners October 15, 2026 12:30
@rubencu
rubencu requested a review from cruisercohen October 15, 2026 12:30
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 09585d82a1cef09ba2f0dfa1a069ae31a969ab9f touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 09585d82a1cef09ba2f0dfa1a069ae31a969ab9f via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the inherited hint can only seed the same permanent failure that a fresh probe returns, and the spawn chokepoint overwrites or removes any value a caller supplies.

Notes

  • The hint assumes a child's probe result matches its parent's. That stops holding if a child is exec'd under a different AppArmor profile from the parent, since Ubuntu's userns restriction applies per profile. Children run as the same Python interpreter today, so this is not a problem now. A comment on _INHERITED_USERNS_FAILURE_ENV should state the assumption.

[DESIGN-REVIEWED] 09585d8

Description read

[DESCRIPTION-READ] 8170f4ad6f66b238c58606638b1a1d748382a8e51f8232bc8b3ab9c1a66abee5

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 09585d82a1cef09ba2f0dfa1a069ae31a969ab9f via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks: the change handles one reported defect (#20811) where it starts, and the env handoff is its only new surface.

What this change ships

Inventory (4 items) — 4 justified

Intent: on a Linux host without user namespaces, the gateway should log the permanent sandbox-probe failure once per boot, not once per sandboxed child. FIX.

  1. Sandboxed children inherit the parent's permanent no-userns verdict, so they skip the probe and its WARNING. — justified
  2. Each sandbox child environment gets _KIROCREW_USERNS_FAILURE when a permanent verdict exists, and loses it otherwise (transient or forged values are dropped). — justified
  3. A child's background warm thread resolves to none straight from the inherited verdict, without probing. — justified
  4. The sandbox.py facade and its ownership test list six new private names. — justified

[FIRST-PRINCIPLES-REVIEWED] 09585d8

Description read

[DESCRIPTION-READ] 2c3a6b157138ebd0ed409e96273990e8af0cc12ac953a475367b5f0a9ad16d0f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 09585d82a1cef09ba2f0dfa1a069ae31a969ab9f via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

Notes:

  • docs/system-specs/modules/security.md does not yet describe the _KIROCREW_USERNS_FAILURE handoff from parent to child. AGENTS.md asks for the owning spec to change in the same commit.

[OPUS-REVIEWED] 09585d8

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 09585d82a1cef09ba2f0dfa1a069ae31a969ab9f via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 09585d8

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 15, 2026
@rubencu
rubencu force-pushed the fix/userns-probe-inherit-verdict branch from 59c117c to fe7278c Compare October 15, 2026 16:07
@rubencu

rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition for an earlier head, kept for the record (no longer a ledger record):

  • Fallback path now receives the inherited verdict

fixed: sandboxed_spawn_argv stamps and carries the permanent verdict on the degraded and no-backend paths at fe7278c. The regression test sets no active-sandbox marker.

@rubencu

rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition for an earlier head, kept for the record (no longer a ledger record):

  • Inherited verdict has spawn provenance

fixed: the child requires the exact KIROCREW_SPAWNED and KIROCREW_SANDBOX_TOOL stamps. The chokepoint overwrites or removes a caller hint, and an unstamped forged hint is ignored at fe7278c.

@rubencu

rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition for an earlier head, kept for the record (no longer a ledger record):

  • Permanent shortcut cannot choose a stronger backend

fixed: the accepted value can only seed a permanent failure and the same none result as the skipped probe. It cannot produce namespace, while the spawn provenance blocks an unstamped hint at fe7278c.

@rubencu

rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition for an earlier head, kept for the record (no longer a ledger record):

  • Production shape is covered

fixed: the test starts with a permanent parent verdict, no KIROCREW_SANDBOX_ACTIVE, and the real returned spawn environment. It asserts no direct or background probe and no probe log at fe7278c.

@rubencu

rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition for an earlier head, kept for the record (no longer a ledger record):

  • The handoff reaches the no-backend child

fixed: the permanent hint is written beside the two chokepoint stamps on every returned child environment, including the fallback path that has no namespace launcher at fe7278c.

@rubencu

rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition for an earlier head, kept for the record (no longer a ledger record):

  • The shortcut no longer depends on the launcher marker

fixed: the child reads the hint from exact spawn provenance and the test confirms KIROCREW_SANDBOX_ACTIVE is absent at fe7278c.

@rubencu

rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition for an earlier head, kept for the record (no longer a ledger record):

  • The affected host path executes the fix

fixed: direct and background warm paths consume the inherited permanent verdict from a no-backend spawn environment without invoking the probe at fe7278c.

@rubencu

rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition for an earlier head, kept for the record (no longer a ledger record):

  • Both probe entry points honor the inherited verdict

fixed: _probe_unshare and _background_warm return from the inherited permanent cache. The production-shape test fails either path if _probe_unshare_once runs at fe7278c.

@rubencu

rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition for an earlier head, kept for the record (no longer a ledger record):

  • Removing the handoff would reopen the reported defect

rebutted: deletion was proportional only while the mechanism could not reach the fallback path. At fe7278c the smaller complete mechanism reaches that path and rejects unstamped hints.

@rubencu

rubencu commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition for an earlier head, kept for the record (no longer a ledger record):

  • The regression test reproduces the emitting process

fixed: the test uses the real child environment from a permanent no-backend parent, sets no launcher marker, and proves the child neither probes nor logs at fe7278c.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 15, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention labels Oct 20, 2026
@rubencu

rubencu commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

First Principles' pre-merge check on 8e9c6e8e2e: a forged _KIROCREW_USERNS_FAILURE with both spawn stamps reaches the same none path as a real EPERM probe, and nothing weaker.

  • The value is read only as a permanent failure. _read_inherited_userns_failure returns (False, reason, remedy) or nothing. With it, _probe_unshare() returns False and detect_backend() caches none, which is exactly what a permanently failing probe records. It cannot select namespace or sandbox-exec.

  • Everything after that depends on the backend and the transient flag, never on the reason text. wrap_argv's backend == "none" branch makes the same decisions in both cases:

    • it refuses unless agent.sandbox_allow_unsandboxed_exec is set;
    • a governance sandbox.min_level floor overrides that opt-in;
    • the first-party carve-out applies only to an audited fixed argv on a no_backend host.

    _classify_unavailable(transient) reads only the flag and macOS nesting, so a forged verdict and a real EPERM land in the same class.

  • A forger chooses only the reason and remedy text in that refusal or warning. On a host whose probe would succeed, a forged value makes that child pick none, so it refuses unless the operator opted in. It never grants a stronger backend and never skips the refusal. Placing all three values means choosing the child's exec environment. The sandboxed_spawn_argv chokepoint never lets a caller do that, because it overwrites or removes the value after the environment scrub. Any kernel confinement the writer is under survives exec.

  • Tests: test_inherited_permanent_failure_skips_probe_and_warning pins the first point through the real chokepoint: a forged caller value is replaced, and the child resolves none without probing. test_hint_outside_a_chokepoint_tree_is_ignored pins that a value without the stamps is ignored.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 21, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at 8e9c6e8 for a human maintainer. No code finding.

This changes how a sandbox child chooses its isolation backend. The child now trusts an inherited _KIROCREW_USERNS_FAILURE instead of probing, and sandbox changes are reserved for human review.

The change reads as fail-closed:

  • The child accepts the hint only on Linux, only with both exact spawn stamps, and only as a permanent failure, so it can select none but never namespace (sandbox_wrap.py#L90-L120).
  • The chokepoint writes or removes the value after the env scrub (sandbox_spawn.py#L615), and reset_backend() drops the inherited verdict.

Every lane passes or reports no findings, and the First Principles pre-merge check has a traced reply. Sensitive Change Review is red as the fork sensitive-path gate. A maintainer's approval or the author's reasoning template clears it.

— crew-pr-reviewer (r116)

@iamwhatever
iamwhatever enabled auto-merge (squash) October 21, 2026 21:16
auto-merge was automatically disabled October 23, 2026 05:08

Head branch was pushed to by a user without write access

@rubencu
rubencu force-pushed the fix/userns-probe-inherit-verdict branch from 8e9c6e8 to 8f5a477 Compare October 23, 2026 05:08
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention labels Oct 23, 2026
@rubencu
rubencu force-pushed the fix/userns-probe-inherit-verdict branch from 8f5a477 to 09585d8 Compare October 29, 2026 01:36
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 29, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD for a maintainer at 09585d8.

This changes how a sandbox child picks its isolation backend: it trusts an inherited _KIROCREW_USERNS_FAILURE value instead of probing. Sandbox changes are reserved for human review, and Sensitive Change Review is red on this fork head until a maintainer takes it over on a repository branch.

The head is a rebase of the 8e9c6e8 we held in r116, and I still found no defect. The child accepts the hint only on Linux, only under both exact spawn stamps and only as a permanent failure, so it can select none but never namespace (sandbox_wrap.py#L88-L146), and the chokepoint overwrites or removes any caller value after the env scrub (sandbox_spawn.py#L728). All AI lanes are clear on this head.

AI findings judged non-blocking: Design suggests a comment on _INHERITED_USERNS_FAILURE_ENV stating that a child runs under the same AppArmor profile as its parent. It is a comment-only suggestion, and the hint can only select none.

What clears the hold: a maintainer takeover so Sensitive Change Review passes, plus a human review of the env-based backend handoff.

— crew-pr-reviewer (r135)

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on behalf of the watch holder (bolichen). Design and First Principles pass on this head (or skipped / author override), UX skipped or pass, no conflict, no open change request.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 29, 2026 20:00
@KiroCrewCaptain
KiroCrewCaptain merged commit 9907aec into kirodotdev:main Oct 29, 2026
104 of 114 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sandbox children repeat the permanent userns probe warning

4 participants