Skip to content

fix(sandbox): pin the parents of every hidden crew-home leaf - #36327

Merged
bolichen97 merged 1 commit into
mainfrom
feat/w5-md-notebook
Nov 14, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
feat/w5-md-notebook

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A sandboxed agent can no longer move a masked crew-home file out from under its mask by renaming a folder above it, on Linux or macOS.

A sandboxed child could rename a parent of a hidden crew-home leaf: apps/meetings/data (above the masked edits/), apps/aws-control (above the masked data/), or the data folder of an app that declares credentialMasks. On Linux the mask is a mount, and a mount moves with its renamed parent, so the child still sees an empty stand-in; but on disk the leaf now sits at a name no mask covers, and the next spawn reads it there. Reproduced through sandbox.namespace_argv on main: os.rename(".../apps/meetings/data", ".../apps/meetings/data-moved") succeeded, and data-moved/edits/ was plain on disk. On Seatbelt the mask is a path rule, so the same rename exposes the leaf in the same session; only the parents of app-declared leaves were guarded there.

Why it matters

The hidden leaves hold credentials and private state (apps/aws-control/data, Meetings' edits, any app's credentialMasks files). A prompt-injected agent could read them with two shell commands across two turns. It also blocks campaign #26967: the owner ruling in #26967 (comment) (item 5) asks for md-notebook to run in the standard sandbox, which means moving its GitHub token into its own data folder under credentialMasks, and that is only safe once that folder cannot be renamed away.

Not a goal

  • Moving md-notebook's state or changing any app's manifest. This PR only closes the rename path every hidden leaf shares.
  • The documented rename-detach residual (a writer that replaces a masked file by rename detaches live sessions' masks, security.md); that is a different mechanism.
  • Masking anything new: no leaf is added to or removed from any table.

What changed (motivation → approach → change)

Symptom → cause → change:

  • Cause. sandbox_argv._live_plan_host already guards the parents of every read-only seal against rename (readonly_ancestor_guards: Linux binds each renameable parent over itself, so rename(2) returns EBUSY; Seatbelt write-denies each as a literal). Hidden leaves were left out, except app-declared ones on Seatbelt, on the stated reasoning that "a namespace mask is a mount, which moves with a renamed parent". The mount does move, but only inside that one spawn.
  • Change. The parents of every hidden spelling, core _CREW_HIDDEN_LEAVES and app-declared credentialMasks leaves, in both $HOME spellings and the relocated-home spelling, now join the same guards on both backends. A leaf the spawn lifts (its own app's backend) still leaves its parents unguarded, as before. A retired leaf (the workspace/md-notebook names, which nothing writes any more) guards its parents only while they exist: an absent folder holds nothing to move, and md-notebook's sandboxed backend must be able to create its own home there on macOS. A top-level leaf's parent is the data home, which the seals already pinned, so in practice the new pins are apps, apps/aws-control, apps/meetings, apps/meetings/data, each declaring app's data folders, and workspace / workspace/md-notebook when they exist. scratch (the parent of the masked scratch/.trees.json) joins the list too; it is itself masked and already write-denied as a whole, so nothing changes for it.
  • CI. .github/workflows/ci.yml runs the new namespace test file in the namespace-sandbox job, the one runner with user namespaces (test_coverage_omit_contract.py requires it).
  • Specs. security.md gains the invariant beside the read-only seals' one and its app-declared paragraph says both backends; app-kit-platform.md §37 drops the "namespace plan gains no guard" sentence.

Backwards compatibility

Breaking: inside a sandbox, renaming or removing one of the newly pinned folders themselves fails with EBUSY, and a rename(2) or link(2) that crosses one fails with EXDEV (mv and shutil.move fall back to copying), the cost the seal pins already document. Writer sweep on origin/main @ 6a61c84: the folders under apps/ are renamed only by the app lifecycle (apps/manager_install.py, manager_adopt.py, builtin_adoption_apply.py, manager_uninstall.py), which runs in the gateway outside every sandbox, and kirocrew app applies through the running gateway; apps/manager_builtins.py moves a retired app's metadata files aside inside its folder, never the folder, also in the gateway; nothing renames workspace or workspace/md-notebook themselves; agent_scratch.py moves trees inside scratch, never scratch itself, from the gateway; agent temp files live in their own scratch window (agent_scratch.py), already a separate mount from workspace/.

Reader: src/kiro_crew/sandbox_plan.py:namespace_payload -- chat|cron|subagent|app -- parent_pins carries the added parents to pin_seal_parents (test_a_core_hidden_leafs_parents_stay_in_place)
Reader: src/kiro_crew/sandbox_seatbelt.py:render -- chat|cron|subagent|app -- runtime_ancestor_guards become literal write denies (test_every_parent_of_a_nested_core_leaf_is_a_literal_write_deny)
Reader: src/kiro_crew/apps/backend.py:_spawn_backend -- app -- an app's own backend lifts its declared leaves and keeps their parents unguarded (test_the_leafs_own_backend_may_rename_its_folder)

Tests

  • test/test_sandbox_hidden_leaf_parent_pins.py (new): a child under the real namespace sandbox gets EBUSY renaming apps/meetings/data, apps/meetings and apps (a core leaf's parents) and an app's data folder (a declared leaf's), while a file inside stays renameable and the leaf is untouched on disk; the app's own backend can still rename the folder its lifted leaf lives in; Seatbelt write-denies each parent of a nested core leaf and the namespace plan pins the same ones.
  • test/test_app_credential_masks.py: test_namespace_plans_no_parent_guard_for_a_declared_leaf pinned the old behaviour; it becomes test_namespace_pins_every_parent_of_a_declared_leaf, including the move-aside spelling and the lifted leaf.
  • test/test_sandbox_hidden_leaf_parent_pins.py also pins the retired-leaf rule: an absent workspace/md-notebook gets no Seatbelt deny, and a present one (holding an older build's pat) is guarded on both backends. test_the_notes_backends_own_spawn_can_create_its_home_on_seatbelt renders the Notes backend's OWN spawn profile (its app_backend_visible_targets lift) with nothing, then workspace, then workspace/md-notebook on disk, in every data-home spelling: each absent folder down to the clone root workspace/md-notebook/vaults has no literal deny, and once workspace/md-notebook exists it and workspace are write-denied, so no spawn can rename them. It is red with the os.path.lexists check removed.
  • test/test_sandbox_refactor_generated_programs.py: both goldens gain the new parents of the stand-in table's nested leaves.

Determinism: the 8 tests in test/test_sandbox_hidden_leaf_parent_pins.py pass 5/5 repeats and 3/3 shuffled orders (seeds 11, 22, 33), -n0, on a host with user namespaces; test_namespace_pins_every_parent_of_a_declared_leaf passes with them in the scoped run below. Each builds its own data home under tmp_path; none sleeps or reads a clock.

Proof: PROVEN test/test_app_credential_masks.py::TestThePlanHidesTheDeclaredLeaves::test_namespace_pins_every_parent_of_a_declared_leaf, test/test_sandbox_hidden_leaf_parent_pins.py::TestTheNamespaceChildCannotRenameAParent::test_a_declared_leafs_parents_stay_in_place, test/test_sandbox_hidden_leaf_parent_pins.py::TestSeatbeltGuardsTheParentsOfACoreHiddenLeaf::test_every_parent_of_a_nested_core_leaf_is_a_literal_write_deny, test/test_sandbox_hidden_leaf_parent_pins.py::TestSeatbeltGuardsTheParentsOfACoreHiddenLeaf::test_the_namespace_plan_pins_the_same_parents, test/test_sandbox_hidden_leaf_parent_pins.py::TestARetiredLeafGuardsOnlyTheFoldersThatExist::test_the_notes_backends_own_spawn_can_create_its_home_on_seatbelt (head 0ed9eba)

All 78 test/test_sandbox*.py files plus test_md_notebook_real_sandbox.py, test_app_credential_masks.py, test_app_backend_spawn_env.py and test_live_target_pointer_visibility.py pass locally (3,838 tests, -n 8 --dist loadgroup), on a host with user namespaces. Rebased onto origin/main @ 6a61c84: every test/test_sandbox*.py file plus test_app_credential_masks.py, test_md_notebook_real_sandbox.py, test_coverage_omit_contract.py, test_app_backend_spawn_env.py, test_live_target_pointer_visibility.py, test_search_docs.py, test/test_agent_scratch*.py and test/tracing/test_tracing_otlp.py pass (4,080 passed, 21 skipped, -n 12 --dist loadgroup), and mypy src/kiro_crew is clean.

Manual verification

Reproduced the rename on main and its refusal on this branch with a script driving sandbox.namespace_argv against a scratch data home (the same steps the new namespace tests run). The Seatbelt half is checked on the rendered profile only; no macOS host was used.

Related Issues

Part of #26967

Merge order (md-notebook stack): #36327 (this PR, part 1) -> #36346 -> #36365 -> #36368. Each later PR builds on this one and merges after it.

Sibling sweep

Swept: git grep -n "readonly_ancestor_guards|_renameable_ancestor_guards|_literal_ancestor_guards" -- src/
Sibling: src/kiro_crew/sandbox_argv.py:480 -- changed here
Sibling: src/kiro_crew/sandbox_workspace.py:225 -- not affected -- the voice runtime parents already have their own guards on both backends
Sibling: src/kiro_crew/sandbox_staging.py:54 -- not affected -- materialised hidden dirs are direct children of the data home, whose parent the seals pin

Pattern harvest

Rule candidate: review-prompt
Pattern: a mask or seal placed on a path is only as fixed as every directory above it; a new hidden or read-only row must say who keeps its parents from being renamed

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 (if applicable)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 13, 2026 02:42
@bolichen97
bolichen97 requested a review from Zedmor November 13, 2026 02:42
@bolichen97
bolichen97 enabled auto-merge (squash) November 13, 2026 02:43
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/sandbox_argv.py

  • @bolichen97 posted a complete reasoning template for 0ed9eba.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 0ed9eba664f2d29e7f872c85ba0639b1f980d42b 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 Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 0ed9eba664f2d29e7f872c85ba0639b1f980d42b — 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 fix goes at the cause by putting hidden leaves into the existing readonly_ancestor_guards mechanism, and a reproduction on main backs it. The reversed pin is named and refuted with evidence.

What this change ships

Inventory (8 items) — 8 justified

Intent: stop a sandboxed agent from moving a masked crew-home credential out from under its mask by renaming a folder above it. This is a FIX.

  1. On Linux, the agent can no longer rename the parents of core hidden leaves (apps, apps/meetings/data, apps/aws-control) — justified
  2. On Seatbelt, the parents of core hidden leaves are now write-denied — justified
  3. On Linux, the parents of app-declared credentialMasks leaves are now pinned, which reverses the old "mount moves with parent" pin with a reproduction — justified
  4. The relocated-home spellings, including .vault, guard their parents too — justified
  5. An app's own backend still renames the folders its lifted leaf lives in — justified
  6. The parents of the retired md-notebook leaf are guarded only while they exist, so its backend can still create its home — justified
  7. Inside the sandbox, a move across a newly pinned folder now fails with EXDEV, or EBUSY on the folder itself; the PR declares this break — justified
  8. The namespace-sandbox CI job now runs the new real-sandbox test file — justified

[FIRST-PRINCIPLES-REVIEWED] 0ed9eba

Description read

[DESCRIPTION-READ] 93485d0809e035b393396ed1163e948d92d5148050e81205f456d233855fe349

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 Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 0ed9eba664f2d29e7f872c85ba0639b1f980d42b — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change reuses the existing seal-parent rename guards for hidden leaves on both backends, and a leaf's own backend keeps its lifted parents unpinned.

Notes

  • Pinning apps on Linux makes any sandboxed rename(2) that crosses into or out of apps/ fail with EXDEV. An out-of-tree app backend that stages a temp file outside its data folder and then renames it in would hit this. The writer sweep covers only in-tree writers, so name this in the app-kit docs.

[DESIGN-REVIEWED] 0ed9eba

Description read

[DESCRIPTION-READ] e1c635be949fe5b18b1606b99b712517b791be4212d46960d056b39c9c696d9a

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 Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 0ed9eba664f2d29e7f872c85ba0639b1f980d42b and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 0ed9eba

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 0ed9eba664f2d29e7f872c85ba0639b1f980d42b false-positive: <reason, 20 to 500 characters>

@KiroCrewCaptain

KiroCrewCaptain commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 15% chance that this change introduces a defect, above the 12% limit for approving on its own.

The PR adds the parent folders of every hidden crew-home file (core and app-declared credentialMasks) to the rename guards the read-only seals already use, on both backends. On Linux each parent is bind-mounted over itself; on Seatbelt each gets a literal write deny, which replaces the old Seatbelt-only branch. The spawn that lifts a file (its own app's backend) still leaves that file's parents unguarded. The old md-notebook paths guard their parents only while those parents exist, so md-notebook's sandboxed backend can still create its home. Writer sweep: Meetings and aws-control run their backends in the gateway, no shipped built-in declares credentialMasks, the Meetings parents were already pinned through its read-only notes seal, and md-notebook's state and clone renames stay on one mount. The launcher skips absent names and binds recursively before the seals. The new real-namespace tests, the plan and profile tests and the updated goldens cover both backends and the lifted-file path. I found no blocking defect. Remaining risks: the pin on workspace is broader than the threat needs, and the macOS suites were still pending at review time.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 7761365af9 · 317 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 46b3276
  • What rule changed: sandbox_argv._live_plan_host adds the parents of every HIDDEN crew-home leaf (core _CREW_HIDDEN_LEAVES and app-declared credentialMasks leaves, in every $HOME and relocated spelling) to readonly_ancestor_guards, the rename guards the read-only seals already use. Linux: pin_seal_parents binds each one this uid could rename over itself. Seatbelt: a literal file-write* deny on each.
  • Before -> after (what was allowed/blocked, now): before, a sandboxed child could os.rename apps/meetings/data, apps/aws-control or an app's declared data folder; on Linux the mount moved with it and the next spawn read the leaf at the new name, on Seatbelt the path rule no longer matched. After, those renames (and rmdir of the folder itself) fail with EBUSY on Linux and are denied on Seatbelt. Files inside the folders stay writable and renameable. A leaf the spawn lifts (its own app's backend) keeps its parents unguarded, as before.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands. Inside a sandbox, renaming or removing apps, apps/aws-control, apps/meetings, apps/meetings/data, workspace or workspace/md-notebook themselves fails, and a rename(2) across one returns EXDEV (mv copies instead). Nothing is unmasked and no one is locked out.
  • Evidence checked (which sandbox result proves it): test/test_sandbox_hidden_leaf_parent_pins.py runs children under the real namespace sandbox: EBUSY for the core leaf's three parents and the declared leaf's two, a file inside still renames, the leaf is untouched on disk, and the owning backend can still rename its own folder. On main the same rename succeeded (reproduced through sandbox.namespace_argv).
  • No regression:
    • Tools still work (which tools/commands were run, result): the namespace tests above run real child processes that create and rename files inside the pinned folders; the md-notebook real-sandbox tests (backend writes by temp and rename) pass.
    • Backward compatible (old config / old data / old callers still work, how checked): no table, config or data format changes; app lifecycle renames under apps/ run in the gateway outside every sandbox (manager_install.py, manager_adopt.py, builtin_adoption_apply.py, manager_uninstall.py), and kirocrew app applies through the gateway.
    • Existing tests (which suites passed on this head): all 78 test/test_sandbox*.py files plus test_md_notebook_real_sandbox.py, test_app_credential_masks.py, test_app_backend_spawn_env.py, test_live_target_pointer_visibility.py and test_coverage_omit_contract.py locally, on a host with user namespaces.
  • How to undo: revert this commit; the guards are computed per spawn, so the next spawn after the revert plans without them.

@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 Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 0ed9eba664f2d29e7f872c85ba0639b1f980d42b — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 0ed9eba

Verdict parsed from the review's SHA-scoped output markers for commit 0ed9eba664f2d29e7f872c85ba0639b1f980d42b.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 0ed9eba664f2d29e7f872c85ba0639b1f980d42b false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 13, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in .github/workflows/ci.yml (#36198, the New-test stability job timeout, a different hunk from this PR's namespace-sandbox test list) since this head went green (27e9359 -> d4b588b); CI re-running. Related tests (146) and the lint/type/comment/brand/line-cap gates pass on 46c09d8 locally; writer sweep re-run on d4b588b finds no new renamer of apps/ or workspace/.

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

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: Seatbelt literal guards on the parents of every core hidden leaf

  • span=12ca3e93ed9f Seatbelt write-denies the absent workspace/md-notebook, so the Notes backend cannot create its home

fixed in 5b6ebe5: a retired leaf (_MD_NOTEBOOK_RETIRED_STATE_LEAVES, which nothing writes any more) now guards its parents only while they exist (os.path.lexists); an absent folder holds no leaf to move.
Class swept: an absent hidden-leaf parent that a sandboxed writer must create. Only md-notebook has a spawned backend among the core leaves' apps; aws-control and meetings are in-process, and app-declared parents are already lifted for their own backend.
Pinned by TestARetiredLeafGuardsOnlyTheFoldersThatExist: absent folder gets no Seatbelt deny (red with the check removed), present folder is guarded on both backends.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 5b6ebe5
  • What rule changed: sandbox_argv._live_plan_host adds the parents of every HIDDEN crew-home leaf (core _CREW_HIDDEN_LEAVES and app-declared credentialMasks leaves, in every $HOME and relocated spelling) to readonly_ancestor_guards, the rename guards the read-only seals already use. Linux: pin_seal_parents binds each one this uid could rename over itself. Seatbelt: a literal file-write* deny on each.
  • Before -> after (what was allowed/blocked, now): before, a sandboxed child could os.rename apps/meetings/data, apps/aws-control or an app's declared data folder; on Linux the mount moved with it and the next spawn read the leaf at the new name, on Seatbelt the path rule no longer matched. After, those renames (and rmdir of the folder itself) fail with EBUSY on Linux and are denied on Seatbelt. Files inside the folders stay writable and renameable. A leaf the spawn lifts (its own app's backend) keeps its parents unguarded, as before. A retired leaf (the workspace/md-notebook names, which nothing writes any more) guards its parents only while they exist, so md-notebook's sandboxed backend can still create its own home on macOS.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands. Inside a sandbox, renaming or removing apps, apps/aws-control, apps/meetings, apps/meetings/data, or an existing workspace / workspace/md-notebook themselves fails, and a rename(2) across one returns EXDEV (mv copies instead). Nothing is unmasked and no one is locked out.
  • Evidence checked (which sandbox result proves it): test/test_sandbox_hidden_leaf_parent_pins.py runs children under the real namespace sandbox: EBUSY for the core leaf's three parents and the declared leaf's two, a file inside still renames, the leaf is untouched on disk, and the owning backend can still rename its own folder. TestARetiredLeafGuardsOnlyTheFoldersThatExist pins that an absent workspace/md-notebook gets no Seatbelt deny and a present one is guarded on both backends. On main the same rename succeeded (reproduced through sandbox.namespace_argv).
  • No regression:
    • Tools still work (which tools/commands were run, result): the namespace tests above run real child processes that create and rename files inside the pinned folders; the md-notebook real-sandbox tests (backend writes by temp and rename) pass.
    • Backward compatible (old config / old data / old callers still work, how checked): no table, config or data format changes; app lifecycle renames under apps/ run in the gateway outside every sandbox (manager_install.py, manager_adopt.py, builtin_adoption_apply.py, manager_uninstall.py), and kirocrew app applies through the gateway.
    • Existing tests (which suites passed on this head): all 78 test/test_sandbox*.py files plus test_md_notebook_real_sandbox.py, test_app_credential_masks.py, test_app_backend_spawn_env.py, test_live_target_pointer_visibility.py and test_coverage_omit_contract.py locally, on a host with user namespaces.
  • How to undo: revert this commit; the guards are computed per spawn, so the next spawn after the revert plans without them.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Main red, not this PR: Backend Lint & Type Check (3.12) fails mypy at src/kiro_crew/cli_commands_memory.py:335 (declared reassigned bool over list[str]) after #36114 + #36212, a file this PR does not touch. Tracked in #36458, fixed by #36457. This PR rebases onto that fix once it merges; no override for that red.

@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 Nov 13, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 14, 2026
bolichen97 added a commit that referenced this pull request Nov 14, 2026
Carries #36327 and #36346, which this branch stacks on, as one commit;
review them there.

leaf so the next spawn read the leaf at a name no mask covers. Every
parent of every hidden spelling now joins the rename guards the
read-only seals use (pin_seal_parents on Linux, literal write denies
on Seatbelt); a retired leaf guards its parents only while they exist.

entry of one name ending in "/" now names a directory under the app's
data dir, masked whole, created before each Linux spawn inside an
existing data/, and handed back to the app's own backend while it is
absent or a real directory. App Kit level 7.
@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 Nov 14, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 7761365
  • What rule changed: sandbox_argv._live_plan_host adds the parents of every HIDDEN crew-home leaf (core _CREW_HIDDEN_LEAVES and app-declared credentialMasks leaves, in every $HOME and relocated spelling) to readonly_ancestor_guards, the rename guards the read-only seals already use. Linux: pin_seal_parents binds each one this uid could rename over itself. Seatbelt: a literal file-write* deny on each.
  • Before -> after (what was allowed/blocked, now): before, a sandboxed child could os.rename apps/meetings/data, apps/aws-control or an app's declared data folder; on Linux the mount moved with it and the next spawn read the leaf at the new name, on Seatbelt the path rule no longer matched. After, those renames (and rmdir of the folder itself) fail with EBUSY on Linux and are denied on Seatbelt. Files inside the folders stay writable and renameable. A leaf the spawn lifts (its own app's backend) keeps its parents unguarded, as before. A retired leaf (the workspace/md-notebook names, which nothing writes any more) guards its parents only while they exist, so md-notebook's sandboxed backend can still create its own home on macOS. On this base scratch also joins the list as the parent of main's new masked scratch/.trees.json; it is itself masked and already carries a literal write deny on Seatbelt, so nothing changes for it.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands. Inside a sandbox, renaming or removing apps, apps/aws-control, apps/meetings, apps/meetings/data, or an existing workspace / workspace/md-notebook themselves fails, and a rename(2) across one returns EXDEV (mv copies instead). Nothing is unmasked and no one is locked out.
  • Evidence checked (which sandbox result proves it): test/test_sandbox_hidden_leaf_parent_pins.py runs children under the real namespace sandbox: EBUSY for the core leaf's three parents and the declared leaf's two, a file inside still renames, the leaf is untouched on disk, and the owning backend can still rename its own folder. TestARetiredLeafGuardsOnlyTheFoldersThatExist pins that an absent workspace/md-notebook gets no Seatbelt deny and a present one is guarded on both backends. On main the same rename succeeded (reproduced through sandbox.namespace_argv).
  • No regression:
    • Tools still work (which tools/commands were run, result): the namespace tests above run real child processes that create and rename files inside the pinned folders; the md-notebook real-sandbox tests (backend writes by temp and rename) pass.
    • Backward compatible (old config / old data / old callers still work, how checked): no table, config or data format changes; app lifecycle renames under apps/ run in the gateway outside every sandbox (manager_install.py, manager_adopt.py, builtin_adoption_apply.py, manager_uninstall.py), and kirocrew app applies through the gateway.
    • Existing tests (which suites passed on this head): this head is the same patch rebased onto origin/main 205d08d (which carries fix(guide): rank a page holding every rare query word above a name match #37063, the fix for main's shard-6 test_search_docs red); every test/test_sandbox*.py file plus test_md_notebook_real_sandbox.py, test_app_credential_masks.py, test_app_backend_spawn_env.py, test_live_target_pointer_visibility.py, test_coverage_omit_contract.py, test_search_docs.py and test/test_agent_scratch*.py pass locally (4,001 passed, 7 skipped) on a host with user namespaces, mypy src/kiro_crew is clean, and prove.py reports PROVEN on this head.
  • How to undo: revert this commit; the guards are computed per spawn, so the next spawn after the revert plans without them.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased onto origin/main @ 205d08d, which carries #37063 (the fix for main's test/test_search_docs.py::test_search_docs_ranks_the_page_the_query_is_about_first red that failed Backend Tests shard 6 on Linux, Windows and macOS, and with it Coverage Gate, on 958f39c). The patch is unchanged; Analyze (javascript-typescript) on the old head failed on the installation API rate limit during SARIF upload, not on a finding. CI re-running on 7761365.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 14, 2026
bolichen97 added a commit that referenced this pull request Nov 14, 2026
Carries #36327 and #36346, which this branch stacks on, as one commit;
review them there.

leaf so the next spawn read the leaf at a name no mask covers. Every
parent of every hidden spelling now joins the rename guards the
read-only seals use (pin_seal_parents on Linux, literal write denies
on Seatbelt); a retired leaf guards its parents only while they exist.

entry of one name ending in "/" now names a directory under the app's
data dir, masked whole, created before each Linux spawn inside an
existing data/, and handed back to the app's own backend while it is
absent or a real directory. App Kit level 7.
@bolichen97

Copy link
Copy Markdown
Contributor Author

Backend Tests (3.12, 2) on 7761365 is main's red, not this diff: test/tracing/test_tracing_otlp.py::test_a_traced_turn_reaches_a_loopback_receiver_with_its_vault_header and ::test_the_exit_flush_sends_spans_still_queued expect four spans while #37005 added kirocrew.step (https://github.com/kirodotdev/KiroCrew/actions/runs/43585076014/job/132419615984). Tracked by #37169, fixed by #37171 (auto-merge armed). This PR waits for it and rebases onto main once it lands; no rerun or override for this red.

A sandboxed child could rename a parent of a masked crew-home leaf
(apps/meetings/data, apps/aws-control, or an app's credentialMasks
data dir). On Linux the mask is a mount that moves with the parent
inside that spawn, but on disk the leaf then sits at a name no mask
covers, so the next spawn read it there. On Seatbelt the parents of
core hidden leaves were not guarded either.

Every parent of every hidden spelling, core or app-declared, now joins
the rename guards the read-only seals already use: pin_seal_parents
binds on Linux, literal write denies on Seatbelt. A leaf the spawn
lifts keeps its parents unguarded there. A retired leaf, which nothing
writes any more, guards its parents only while they exist, so
md-notebook's sandboxed backend can still create its own home.
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 0ed9eba
  • What rule changed: sandbox_argv._live_plan_host adds the parents of every HIDDEN crew-home leaf (core _CREW_HIDDEN_LEAVES and app-declared credentialMasks leaves, in every $HOME and relocated spelling) to readonly_ancestor_guards, the rename guards the read-only seals already use. Linux: pin_seal_parents binds each one this uid could rename over itself. Seatbelt: a literal file-write* deny on each.
  • Before -> after (what was allowed/blocked, now): before, a sandboxed child could os.rename apps/meetings/data, apps/aws-control or an app's declared data folder; on Linux the mount moved with it and the next spawn read the leaf at the new name, on Seatbelt the path rule no longer matched. After, those renames (and rmdir of the folder itself) fail with EBUSY on Linux and are denied on Seatbelt. Files inside the folders stay writable and renameable. A leaf the spawn lifts (its own app's backend) keeps its parents unguarded, as before. A retired leaf (the workspace/md-notebook names, which nothing writes any more) guards its parents only while they exist, so md-notebook's sandboxed backend can still create its own home on macOS. On this base scratch also joins the list as the parent of main's new masked scratch/.trees.json; it is itself masked and already carries a literal write deny on Seatbelt, so nothing changes for it.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands. Inside a sandbox, renaming or removing apps, apps/aws-control, apps/meetings, apps/meetings/data, or an existing workspace / workspace/md-notebook themselves fails, and a rename(2) across one returns EXDEV (mv copies instead). Nothing is unmasked and no one is locked out.
  • Evidence checked (which sandbox result proves it): test/test_sandbox_hidden_leaf_parent_pins.py runs children under the real namespace sandbox: EBUSY for the core leaf's three parents and the declared leaf's two, a file inside still renames, the leaf is untouched on disk, and the owning backend can still rename its own folder. TestARetiredLeafGuardsOnlyTheFoldersThatExist pins that an absent workspace/md-notebook gets no Seatbelt deny and a present one is guarded on both backends. On main the same rename succeeded (reproduced through sandbox.namespace_argv).
  • No regression:
    • Tools still work (which tools/commands were run, result): the namespace tests above run real child processes that create and rename files inside the pinned folders; the md-notebook real-sandbox tests (backend writes by temp and rename) pass.
    • Backward compatible (old config / old data / old callers still work, how checked): no table, config or data format changes; app lifecycle renames under apps/ run in the gateway outside every sandbox (manager_install.py, manager_adopt.py, builtin_adoption_apply.py, manager_uninstall.py), and kirocrew app applies through the gateway.
    • Existing tests (which suites passed on this head): this head is the same patch rebased onto origin/main 6a61c84 (which carries fix(guide): rank a page holding every rare query word above a name match #37063 and test: expect the kirocrew.step span in the otlp wire tests #37171, the fixes for main's shard-6 test_search_docs and shard-2 test_tracing_otlp reds); every test/test_sandbox*.py file plus test_md_notebook_real_sandbox.py, test_app_credential_masks.py, test_app_backend_spawn_env.py, test_live_target_pointer_visibility.py, test_coverage_omit_contract.py, test_search_docs.py test/test_agent_scratch*.py and test/tracing/test_tracing_otlp.py pass locally (4,080 passed, 21 skipped) on a host with user namespaces, mypy src/kiro_crew is clean, and prove.py reports PROVEN on this head.
  • How to undo: revert this commit; the guards are computed per spawn, so the next spawn after the revert plans without them.

@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 Nov 14, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Green-age note for 0ed9eba: green_age.py reports STALE on one main commit since this head's base (6a61c84 -> 2304233, #37151). Its only overlap is docs/system-specs/modules/instances.md, a same-directory sibling this PR does not edit; #37151 changes one read in src/kiro_crew/instances/registry.py, which is outside this PR's closure (sandbox_argv.py, its sandbox imports and their tests).

Proof on fresh main: this commit cherry-picks cleanly onto 2304233, and on that tree every test/test_sandbox*.py file plus test_app_credential_masks.py, test_md_notebook_real_sandbox.py and test_instances_hooks_unreadable_write.py pass (3,783 passed, 6 skipped). So I am not pushing a re-sync; the green on this head stands for the tree a merge would produce.

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve on 0ed9eba. This change stops a sandboxed agent from renaming a folder above a hidden crew-home file, which would leave that file readable to the next session. Since the last review the product code is unchanged; the branch was rebased onto main, which carries the type-check fix, and one test was added. The new test renders the Notes backend's own macOS profile and proves each folder on the way to its home stays creatable while absent and is guarded once it exists; it fails if either half of the rule is removed. One older test no longer proves the Linux guard on its own, because main now seals a Meetings folder under the same parents; other tests still fail without the guard, so this is a small follow-up, not a blocker. Decisive lines: src/kiro_crew/sandbox_argv.py:516-526 (hidden_leaf_parents joined into readonly_ancestor_guards on both backends; unchanged since 5b6ebe5), src/kiro_crew/sandbox_argv.py:521 (retired leaf guarded only while its folder exists), test/test_sandbox_hidden_leaf_parent_pins.py:183 (new test for the Notes backend's own spawn), .github/workflows/ci.yml:2342 (one added line: test/test_sandbox_hidden_leaf_parent_pins.py in the backend-test-sandbox pytest file list; no permission, secret, trigger or action change)

@bolichen97
bolichen97 merged commit f43dd14 into main Nov 14, 2026
108 of 116 checks passed
@bolichen97
bolichen97 deleted the feat/w5-md-notebook branch November 14, 2026 12:48
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 14, 2026
buluoray pushed a commit that referenced this pull request Nov 14, 2026
A sandboxed child could rename a parent of a masked crew-home leaf
(apps/meetings/data, apps/aws-control, or an app's credentialMasks
data dir). On Linux the mask is a mount that moves with the parent
inside that spawn, but on disk the leaf then sits at a name no mask
covers, so the next spawn read it there. On Seatbelt the parents of
core hidden leaves were not guarded either.

Every parent of every hidden spelling, core or app-declared, now joins
the rename guards the read-only seals already use: pin_seal_parents
binds on Linux, literal write denies on Seatbelt. A leaf the spawn
lifts keeps its parents unguarded there. A retired leaf, which nothing
writes any more, guards its parents only while they exist, so
md-notebook's sandboxed backend can still create its own home.

(cherry picked from commit f43dd14)
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.

3 participants