Repository navigation
fix(cron): hide every app's secret from cron children, keep own bundle - #16442
Conversation
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The command-text parser that opens read-only windows on any bundle a command names by path has no reported user and goes beyond the Goal's "an app's own crons". Not justified as shipped
What this change shipsInventory (8 items) — 7 justifiedIntent: stop cron children from reading any app's bearer secret while app crons keep running their bundle code. FIX.
[FIRST-PRINCIPLES-REVIEWED] 6200408 Description read[DESCRIPTION-READ] 614579a76315f1325f0013b91b75b2550c082dc9a13c956fea8b82880d607a41 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS The real cause is that a bearer credential sits inside a code bundle. This PR works around it with read-only windows, inode pins and alias scans instead of moving the secret out. Watch
[DESIGN-REVIEWED] 6200408 Description read[DESCRIPTION-READ] 7b1c69f20a237affa9e355f072081abbeb00ec281d58ec367373faa525dc5acc 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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
7d915fa to
e724d8c
Compare
|
span=31cfe0f000f2
|
|
span=31cfe0f000f2
|
|
span=5ed365838321
|
|
span=fb8c0d77e828
|
|
span=85b5bd13d28c
|
e724d8c to
a971d36
Compare
|
span=31cfe0f000f2
|
a971d36 to
5c93111
Compare
|
span=31cfe0f000f2
|
5c93111 to
80684f8
Compare
|
span=31cfe0f000f2
|
|
span=2b51f30c56af
|
|
span=7544dcfc745e
|
|
span=af845734ec19
|
|
span=9f2eb926af9e
|
|
span=e3c2d5c7251b
|
…s own bundle readable A cron script or command child could read any installed app's .app_secret, which is that app's bearer credential. Masking the whole apps tree closed that but also hid the bundle an app cron runs from, so every app cron failed on its first import; that mask was reverted. Both cron exec paths now mask <config_dir>/apps in every spelling the crew home has (a symlinked $HOME reaches it by two names), creating the tree first so the mask covers an app installed mid-run. The bundle the cron runs from comes back as a read-only window: the app whose bundle holds the resolved script, or the job's host-stamped created_by owner. Its data/ stays a writable window and its .app_secret stays masked. A command that names another bundle by path gets that bundle's code read-only, with data/ and the secret masked. Every other app's tree stays masked. A bundle is windowed only when settled: no installer staging beside it, and a secret present as a plain single-linked file. Each window is pinned to the inode planned, and each windowed secret is a required mask, so a swap or a secret moved aside before the child masks it refuses the spawn. When any app secret has a second hard link, no window opens. While any app secret has a second hard link, no bundle window opens. A link at a path outside the masked directories stays readable; that residual is tracked separately. wrap_argv gains extra_readonly_private_dirs (Linux remounts the window MS_RDONLY right after binding it and refuses if the seal did not take; Seatbelt carves it out of the read deny only, and admits a read-only window that holds a hidden leaf; read-write windows are unchanged) and extra_required_mask_targets. Refs #12518
80684f8 to
6200408
Compare
|
span=298d0112641e
|
|
span=f362762bf33b
|
|
span=eb86354028f5
|
bolichen97
left a comment
There was a problem hiding this comment.
Comment-only review at head 6200408ba6. Not approving: this PR edits a spec doc (docs/system-specs/modules/learn-cron-dashboard.md) and carries a declared breaking change plus four open questions, so it needs bolichen97's own call.
What I checked (no code defect found):
- Both gateway call sites (
slack/gateway.pyscript + command) passapp_owner_name(job.created_by)into the newowner_apppositional slot correctly; those are the only production callers. created_byis host-stamped from the app token claim (dashboard/handlers/cron.py:951), so a model cannot pick which bundle gets a window.cron_apps_mask: wholeapps/masked in every home spelling; owned bundle read-only withdata/writable; referenced bundle read-only withdata/masked; every windowed.app_secretmasked and required; no window at all while any secret is hard-linked.- Linux launcher: the nested re-hide loop pins
.app_secretwithS_ISDIR, which is a wrong-kind skip (not a refusal) in_pin_mount_path; the file loop then masks it after the windows are bound. Read-only seal is verified withstatvfsand refuses on failure. - Seatbelt: read-only windows are carved out of the read deny only; write/link denies stay unless under the read-write
data/window. - Builtin app crons are all message (agent) crons, so a builtin without a backend (no
.app_secret, so never windowed) is not broken by this. - Ran
test_cron_apps_secret_mask.py,test_sandbox_mount_checked.py,test_sandbox_mount_pinned_target.py,test_sandbox_refactor_generated_programs.py,test_app_script_cron_sibling_import.py: 213 passed, 3 skipped. Real-namespace test still skips here (no user namespaces on this host), same as the PR notes.
Decisions for bolichen97:
- Breaking: a third-party app cron that authenticates with the on-disk secret via
kirocrew_clientloses app scopes at first fire, with no install-time warning. - Any hard-linked app secret turns off every app's bundle window, so every app script/command cron fails until the link is removed (logged as a SECURITY warning).
- Owned bundles are now read-only: an app cron that writes anywhere in its bundle outside
data/now gets EROFS (Linux) / deny (macOS). - The four "Open questions" in the PR body, and the Design/First Principles point that moving
.app_secretout of the bundle (#16789) would remove most of this machinery.
AI-assisted review, posted at bolichen97's request.
buluoray
left a comment
There was a problem hiding this comment.
LGTM. I checked this at head 6200408ba6.
Every app's secret is hidden from every cron child. Both exec paths apply the apps-tree mask: script crons at cron_script.py:2671-2685 (a vault-granted script gets the full mask and no window at all, since its reader is pinned to crons/), and command crons at :3235-3248, with both gateway call sites passing owner_app. A window opens only for the owner bundle or a bundle the command names by path; each is read-only with its .app_secret masked and required, and a referenced bundle's data/ stays masked. Ownership comes from the host-stamped created_by (dashboard/handlers/cron.py:951 from the app token claim); the MCP cron_add path only reads it, so a caller cannot claim another app's bundle. Secrets never travel as env vars (_clean_cron_env is unchanged), so there is no env-name matching to get wrong.
Fail-closed throughout. A bundle mid-install/update, without a secret, or with a multiply-linked secret stays masked; an inode change before staging, a read-only seal that did not take (statvfs), or a required secret moved aside refuses the spawn. Real Linux-namespace spawns confirm the own bundle is readable with its secret empty, another app's code, secret and directory listing are ENOENT, the bundle root is read-only, and symlink / apps/./other / own/../other spellings to another app's secret all fail. The two documented residuals (a hard link outside the masked paths, #16789; a host-side rename during a Linux child) are fail-open only for that narrow case.
Mutation checks. Removing the script-path mask reddens TestBothExecPathsPassTheMask::test_script_path; the command-path mask test_command_path; dropping secret leaves from windows reddens 11 tests including test_own_bundle_script_reads_its_bundle_and_no_secret; the alias withholding test_any_aliased_secret_withholds_every_window; the staging-sibling check test_a_bundle_mid_update_stays_masked; the referenced bundle's data/ hide test_command_naming_a_bundle_reads_the_code_but_not_its_data; the launcher read-only seal and statvfs check test_a_read_only_seal_that_did_not_take_refuses_the_spawn.
Non-blocking follow-ups
- No test covers the apps mask in the vault-grant script branch (
*apps_mask.hiddenatcron_script.py:2680); deleting it keeps everything green, and that is the branch holding vault secrets. Worth a one-line test. - The
st_nlink != 1check in_settled_bundle_identityreddens nothing when removed (the global alias withholding covers it). - One hard-linked secret on any app withholds windows for every app, so all bundle crons fail to import. Fail-closed and logged, but the warning could name the offending file.
- Not verified here: Seatbelt behaviour for case-variant spellings on case-insensitive APFS, and whether a cron child can read the gateway's
/proc/<pid>/root. Both would apply to every crew mask, not just this one.
Problem / Motivation
Goal: A cron script or command can no longer read any installed app's
.app_secret, while an app's own crons keep running their bundle code.A cron child can read every installed app's
<config_dir>/apps/<app>/.app_secret. That file is the app's bearer credential:dashboard.token_auth.validate_app_secretcompares it and issues that app's scoped token. Script crons undercrons/are model-writable by design, and command crons run model-supplied text, so the least trusted cron code can act as any app (#12518).#13273 closed this by masking the whole apps tree (re-exposing only each app's
data/). That also hid the bundle an app cron runs from, so every app cron failed on its first import (ModuleNotFoundError/MODULE_NOT_FOUND). #16072 (main) and #16075 (release/0.8.0) reverted it, and #12518 is open again.Why it matters
Any host with an OS sandbox backend and at least one installed app is exposed: a cron child can read every app's credential and call the gateway as that app, with that app's scopes, and nothing about the read looks unusual. The previous fix showed the other half of the bar: app crons must keep working, or the protection gets reverted again.
Not a goal
agent.sandbox=offdoes for cron children (see Open questions)..app_secretfrom agent subprocesses; this PR is about the two cron exec paths.wrap_argvreturns the argv unchanged there, so no mask applies, same as every other crew-home mask.What changed (motivation → approach → change)
Symptom: a cron child reads any app's
.app_secret. Root cause: neither cron spawn names the apps tree to the sandbox. The reverted fix masked the tree but gave the cron no way back into its own code.Both cron exec paths mask
<config_dir>/appsin every spelling of the crew home (crew_home_visible_spellings, so/home/uand/local/home/uare both covered), creating the tree first so an app installed mid-run lands under the mask.The bundle the cron runs from comes back as a read-only window: the app whose bundle holds the resolved script, or the job's host-stamped
created_byowner (threaded from the gateway).src/kiro_crew/slack/gateway.pypasses that owner in. Itsdata/stays a writable window inside it; its.app_secretstays masked. A command that names another bundle by path gets that bundle's code read-only, withdata/and the secret masked. Every other app stays masked.A bundle is windowed only when settled: no installer staging beside it, and a secret present as a plain single-linked file. Each window is pinned to the inode planned, and each windowed secret is a required mask, so a swap or a secret moved aside before the child masks it refuses the spawn. When any app secret has a second hard link, no window opens. While any app secret has a second hard link, no bundle window opens, and the inode goes to the Linux launcher's existing alias scan. The gateway calls
app_owner_namedirectly.wrap_argv(extra_readonly_private_dirs=..., extra_required_mask_targets=...)insrc/kiro_crew/sandbox.py: the Linux launcher (src/kiro_crew/sandbox_launcher.py) remounts such a windowMS_RDONLYright after binding it, before any nested window, and refuses the spawn if the seal did not take. Seatbelt (src/kiro_crew/sandbox_seatbelt.py) carves it out of the read deny only, and admits a read-only window that holds a hidden leaf (the bundle's.app_secretkeeps its own deny). Read-write windows are refused exactly as before, so the ACP scratch windows are unchanged.Why not move
.app_secretout of the bundle into a hidden crew-home leaf: that changes the install layout,dashboard.token_auth, the published Python client and every app that reads the secret from its own tree, which is a contract change beyond this fix. It is listed in cron sandbox: a second hard link to an app secret stays readable #16789.docs/system-specs/modules/learn-cron-dashboard.mddescribes the mask and its residuals in place of the open-leak note;docs/app-kit/api-reference.mdsays app crons useScriptContext, not the on-disk secret.Backwards compatibility
Breaking: inside a cron child,
kirocrew_client's on-disk app-secret auth (_read_app_secret) finds no secret, so an app cron that authenticates that way loses app scopes; it must useScriptContext(ctx.notify,ctx.call_tool). Writer sweep on origin/main @ d8e2376: no builtin app cron callskirocrew_client; docs/app-kit/api-reference.md now states the rule. Accepted: reading that secret is the access #12518 removes.Compatible otherwise: an app's script and command crons keep reading their own bundle and writing its
data/; callers that pass no read-only windows get the same launcher and profile behaviour.Reader: src/kiro_crew/cron_script.py:run_script_sandboxed -- cron -- an app bundle script keeps its own bundle as a read-only window with
data/writable; test/test_app_script_cron_sibling_import.pyReader: src/kiro_crew/cron_script.py:run_command_sandboxed -- cron -- an app command cron keeps its
created_byowner's bundle; test/test_cron_apps_secret_mask.py::TestBothExecPathsPassTheMask::test_command_pathReader: src/kiro_crew/cron_script.py:run_command_sandboxed -- cron -- an operator command naming a bundle path keeps that code read-only, its
data/is masked; test/test_cron_apps_secret_mask.py::TestCronAppsMask::test_command_naming_a_bundle_reads_the_code_but_not_its_dataReader: packages/kirocrew-client-py/kirocrew_client/client.py:_read_app_secret -- cron -- finds no secret inside a cron child; app crons use
ScriptContext(ctx.notify,ctx.call_tool), as docs/app-kit/api-reference.md now statesReader: src/kiro_crew/cron_script.py:McpToolClient -- cron -- an MCP server whose code lives under
apps/gets no window; builtin app MCP servers run from the package and are unaffected (see Open questions)Reader: src/kiro_crew/cron_script.py:run_script_sandboxed -- cron -- a
crons/script writing underapps/loses the write on Linux and is denied on macOS (see Open questions)Tests
test/test_cron_apps_secret_mask.py(new): own-bundle.mjs/modules readable and read-only, own and other.app_secretunreadable, other apps' trees masked, unrelatedcrons/script gets no window,created_byowner and unsafe owner names, command-referenced bundles, settled-bundle and pin rules, alias inodes, both spellings of a symlinked home; the Linux launcher's embeddedSENSITIVE_DIRS/SENSITIVE_FILES/PRIVATE_DIRS/READONLY_WINDOWS; the Seatbelt rules; what each exec path handswrap_argv.test/test_sandbox_mount_checked.py: the launcher region binds the bundle, seals it read-only, then binds itsdata/, then hides the secret; a seal that did not take refuses the spawn.wrap_argvandnamespace_argv; the launcher refuses a required secret absent at mask time. A Seatbelt read-write window holding a hidden leaf is still refused (pins the ACP behaviour). The module is POSIX-only and skips on Windows.$VARexpansion, secrets not required, aliases not withholding, absent secret allowed, required not threaded at either layer) each turn these tests red.test_sandbox_refactor_generated_programs.pylauncher digests updated (profile digests unchanged); mount-harness namespaces gainREADONLY_WINDOWS.Manual verification
Not reproduced against a live namespace sandbox: this host runs inside a KiroCrew sandbox, where
unshare(CLONE_NEWUSER)returns EPERM anddetect_backend()isnone, sotest_the_real_sandbox_runs_itskips. Coverage is the built bind/hide lists plus the launcher mount region run under a recording libc. A maintainer on a bare Linux host can runpytest test/test_app_script_cron_sibling_import.py test/test_cron_apps_secret_mask.py.Related Issues
Fixes #12518
Earlier attempts: PR #13273 (reverted by #16072 and #16075) and PR #16061 (closed).
Backport target:
release/0.8.0(where #16075 reverted the mask).Known residual
A second hard link to an app secret, at a path outside the masked directories, stays readable by cron children. The Linux alias scan walks only the working directory and
/tmp, and Seatbelt denies by path. Closing it fully meant refusing every cron while any secret is linked, which was rejected. Follow-up: issue 16789 (link).Open questions
agent.sandbox=offturn off cron sandboxing? This PR does not change it.crons/script that writes underapps/loses that write on Linux (empty mask). Is that acceptable, or should the mask be read-only so the write fails loudly?ctx.call_toolon a third-party MCP server whose code lives in an app bundle gets no window. Should those bundles be windowed read-only too?Pattern harvest
Rule candidate: review-prompt
Pattern: a sandbox mask over a tree must name every window back into it that the spawn's own code needs, and pin each window to the inode it planned.
Checklist