Skip to content

fix(cron): hide every app's secret from cron children, keep own bundle - #16442

Merged
iamwhatever merged 1 commit into
mainfrom
fix/cron-app-secret-mask-12518
Oct 4, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/cron-app-secret-mask-12518

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

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_secret compares it and issues that app's scoped token. Script crons under crons/ 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

  • Changing what agent.sandbox=off does for cron children (see Open questions).
  • Masking .app_secret from agent subprocesses; this PR is about the two cron exec paths.
  • Hosts with no sandbox backend (Windows, or the unsandboxed-exec opt-in): wrap_argv returns the argv unchanged there, so no mask applies, same as every other crew-home mask.
  • Making the shared mask primitive itself read-only outside its windows.

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.

  1. Both cron exec paths mask <config_dir>/apps in every spelling of the crew home (crew_home_visible_spellings, so /home/u and /local/home/u are both covered), creating the tree first so an app installed mid-run lands under the mask.

  2. 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 (threaded from the gateway). src/kiro_crew/slack/gateway.py passes that owner in. Its data/ stays a writable window inside it; 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 stays masked.

  3. 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_name directly.

  4. wrap_argv(extra_readonly_private_dirs=..., extra_required_mask_targets=...) in src/kiro_crew/sandbox.py: the Linux launcher (src/kiro_crew/sandbox_launcher.py) remounts such a window MS_RDONLY right 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_secret keeps its own deny). Read-write windows are refused exactly as before, so the ACP scratch windows are unchanged.
    Why not move .app_secret out 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.

  5. docs/system-specs/modules/learn-cron-dashboard.md describes the mask and its residuals in place of the open-leak note; docs/app-kit/api-reference.md says app crons use ScriptContext, 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 use ScriptContext (ctx.notify, ctx.call_tool). Writer sweep on origin/main @ d8e2376: no builtin app cron calls kirocrew_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.py
Reader: src/kiro_crew/cron_script.py:run_command_sandboxed -- cron -- an app command cron keeps its created_by owner's bundle; test/test_cron_apps_secret_mask.py::TestBothExecPathsPassTheMask::test_command_path
Reader: 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_data
Reader: 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 states
Reader: 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 under apps/ 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_secret unreadable, other apps' trees masked, unrelated crons/ script gets no window, created_by owner and unsafe owner names, command-referenced bundles, settled-bundle and pin rules, alias inodes, both spellings of a symlinked home; the Linux launcher's embedded SENSITIVE_DIRS / SENSITIVE_FILES / PRIVATE_DIRS / READONLY_WINDOWS; the Seatbelt rules; what each exec path hands wrap_argv.
  • test/test_sandbox_mount_checked.py: the launcher region binds the bundle, seals it read-only, then binds its data/, then hides the secret; a seal that did not take refuses the spawn.
  • New cases: a bundle without a secret, any aliased secret, and required-secret threading through wrap_argv and namespace_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.
  • Revert check: 18 mutations (no mask, one spelling, own secret unmasked, no read-only, no data window, no seal, unsorted binds, Seatbelt write carve-out, window every app, mid-update window, no alias ids, no pins, no $VAR expansion, 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.py launcher digests updated (profile digests unchanged); mount-harness namespaces gain READONLY_WINDOWS.

Manual verification

Not reproduced against a live namespace sandbox: this host runs inside a KiroCrew sandbox, where unshare(CLONE_NEWUSER) returns EPERM and detect_backend() is none, so test_the_real_sandbox_runs_it skips. 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 run pytest 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

  • Should agent.sandbox=off turn off cron sandboxing? This PR does not change it.
  • An operator crons/ script that writes under apps/ loses that write on Linux (empty mask). Is that acceptable, or should the mask be read-only so the write fails loudly?
  • ctx.call_tool on a third-party MCP server whose code lives in an app bundle gets no window. Should those bundles be windowed read-only too?
  • Linux residual of the mask primitive: a host-side unlink or rename of a masked file detaches that mask in a running child. An update that fails and rolls back while an owner cron runs can restore that app's own secret into its window.

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

  • At most two commits (one is the norm), with a Conventional Commits title
  • 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

@iamwhatever
iamwhatever requested a review from a team as a code owner October 3, 2026 08:40
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 6200408ba6ce36827e3db7cabd44494108304c78 — 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/CONCERNS are advisory.

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

  • Item 4 — inherited: _command_bundle_refs (shlex split, $VAR/~ expansion, key=value splitting) serves the case "A command that names another bundle by path gets that bundle's code read-only". The Goal names only "an app's own crons", and no issue or report shows an operator command cron that runs code from another app's bundle.
    Subtraction: delete _command_bundle_refs, the command= parameter of cron_apps_mask and the referenced branch. A command cron then keeps only its created_by owner's bundle.
    Clears when: a linked issue or a shipped cron shows a non-owner command cron that runs code from inside apps/<name>/, or the parser is removed.

What this change ships

Inventory (8 items) — 7 justified

Intent: stop cron children from reading any app's bearer secret while app crons keep running their bundle code. FIX.

  1. Script and command cron children can no longer see <config_dir>/apps, under every spelling of the crew home — justified
  2. An app cron's own bundle (from the script's location or the created_by owner) comes back read-only, with data/ writable and the secret masked — justified
  3. Granted (vaulted) scripts get the apps mask with no window — justified
  4. Command crons get read-only code for any bundle their text names by path — inherited
  5. A window opens only for a settled bundle: inode-pinned, the secret required, no window when a secret is hard-linked — justified
  6. New wrap_argv inputs extra_readonly_private_dirs / extra_required_mask_targets, used by the Linux remount seal and the Seatbelt read-only carve-out — justified
  7. The gateway passes the job's owning app into both cron exec paths — justified
  8. The spec and the App Kit doc say app crons use ScriptContext, not the on-disk secret — justified

[FIRST-PRINCIPLES-REVIEWED] 6200408

Description read

[DESCRIPTION-READ] 614579a76315f1325f0013b91b75b2550c082dc9a13c956fea8b82880d607a41

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 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — 🟡 CONCERNS

Design-level review of 6200408ba6ce36827e3db7cabd44494108304c78 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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

  • A simpler fix was not weighed. The real problem is that .app_secret lives inside <config_dir>/apps/<app>/, the same tree cron children have to import code from. The PR handles that with read-only windows (extra_readonly_private_dirs) on both sandbox backends, the "settled bundle" checks, per-window inode pins, a hard-link alias scan and required masks. It still documents residuals: a hard link outside the masked tree, and "an update that fails and rolls back while an owner cron runs can restore that app's own secret into its window". Moving the secret into its own crew-home leaf (for example app_secrets/<name>) would let it take the existing HIDDEN disposition. The bundle tree would then need no mask, no windows and no Seatbelt read-only carve-out, and those residuals would go away. The cost is a one-time migration plus readers in token_auth, apps/manager, apps/backend and kirocrew_client. Without that comparison, the new launcher and Seatbelt surface becomes permanent code that every later sandbox change has to work around.
    Clears when: the description says why relocating .app_secret into a HIDDEN crew-home leaf was rejected, or the PR adopts it.
  • Third-party app crons that call kirocrew_client will stop authenticating. The description lists _read_app_secret as a reader and says it "finds no secret inside a cron child". For any app cron that authenticates with the on-disk secret, this is a runtime contract break, and the only notice is a doc paragraph. It fails at first fire, with no warning when the app installs.
    Clears when: either the client raises a clear "use ScriptContext inside a cron" error when it runs inside a cron child, or the description lists this under Breaking: and accepts it.

[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 .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 3, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 6200408ba6ce36827e3db7cabd44494108304c78 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6200408

Verdict parsed from the review's SHA-scoped output markers for commit 6200408ba6ce36827e3db7cabd44494108304c78.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 6200408ba6ce36827e3db7cabd44494108304c78: <one-sentence reason>

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

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 6200408ba6ce36827e3db7cabd44494108304c78 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6200408

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 6200408ba6ce36827e3db7cabd44494108304c78: <one-sentence reason>

@iamwhatever
iamwhatever force-pushed the fix/cron-app-secret-mask-12518 branch from 7d915fa to e724d8c Compare October 3, 2026 18:19
@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 Oct 3, 2026
@iamwhatever

iamwhatever commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

span=31cfe0f000f2
[operator: iamwhatever] fixed in e724d8c — Update rollback restores a credential into the live bundle window

The trigger needs the launcher to skip an absent secret mask. Each windowed .app_secret is now a REQUIRED mask (extra_required_mask_targets -> namespace_argv _required_targets -> launcher require_present), so a secret moved aside after planning refuses the spawn instead of being skipped.
A bundle is windowed only with its secret present, a plain file with one link (_settled_bundle_identity); a bundle without one stays masked, so a secret written later cannot surface.
Seatbelt denies by path, so a later file at the name is already covered there.
Residual (shared mask primitive, recorded in learn-cron-dashboard.md): a host-side rename of a file already masked in a running Linux child detaches that mask.
Tests: test_each_windowed_secret_is_a_required_mask, test_a_required_secret_moved_aside_refuses_the_spawn, test_a_bundle_without_a_secret_stays_masked.

@iamwhatever

iamwhatever commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

span=31cfe0f000f2
[operator: iamwhatever] fixed in e724d8c — App-secret aliases remain readable through owned data windows

cron_apps_mask now opens NO window when any app secret (or installer staging copy) has a second hard link, so a link planted in an owner's data/ stays under the masked apps tree on both backends.
A bundle whose own secret has more than one link is never windowed either.
The inode ids still go to extra_alias_credential_ids for the existing pre-exec scan of $CWD and /tmp.
Test: test_any_aliased_secret_withholds_every_window.

@iamwhatever

iamwhatever commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

span=5ed365838321
[operator: iamwhatever] fixed in e724d8c — duplicate cron_owner_app wrapper

The wrapper is deleted; both slack/gateway.py call sites use apps.cron_sdk.app_owner_name directly.

@iamwhatever

iamwhatever commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

span=fb8c0d77e828
[operator: iamwhatever] fixed in e724d8c — app auth path inside an app's own cron

The owner's own secret stays masked: a cron child runs model-influenced code, and a readable owner secret would let any job stamped for that app act as it.
The body now carries Reader: packages/kirocrew-client-py/kirocrew_client/client.py:_read_app_secret -- cron -- ..., and docs/app-kit/api-reference.md states app crons use ScriptContext (ctx.notify, ctx.call_tool).

@iamwhatever

iamwhatever commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

span=85b5bd13d28c
[operator: iamwhatever] fixed in e724d8c — owning spec still described the leak as open

learn-cron-dashboard.md now describes the apps mask, the owned and referenced bundle windows, the settled-bundle and required-secret rules, and the residuals listed under Open questions.

@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 3, 2026
@iamwhatever
iamwhatever force-pushed the fix/cron-app-secret-mask-12518 branch from e724d8c to a971d36 Compare October 4, 2026 06:00
@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=31cfe0f000f2
[operator: iamwhatever] fixed in a971d36 — Seatbelt discards app-secret hardlink protection

wrap_argv now calls _refuse_path_only_alias_ids on the sandbox-exec branch and on the darwin delegation fallback: any extra_alias_credential_ids refuse the spawn with SandboxCeilingUnsealable, because a path-rule profile cannot follow an inode to a link in /tmp or the cwd.
Both cron exec paths pass the ids, so a macOS cron with an aliased app secret does not run.
Tests: TestSeatbeltRefusesUnfollowableAliases (refuses with ids, spawns without); revert of the check turns the refusal test red.

@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 Oct 4, 2026
@iamwhatever
iamwhatever force-pushed the fix/cron-app-secret-mask-12518 branch from a971d36 to 5c93111 Compare October 4, 2026 06:50
@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=31cfe0f000f2
[operator: iamwhatever] fixed in 5c93111 — Linux still exposes app-secret hardlinks outside the scan roots

Both cron exec paths now refuse the run before wrap_argv whenever cron_apps_mask reports any app-secret alias inode (_APP_SECRET_ALIAS_REFUSAL), on every backend; the job errors with a find -samefile remedy and runs again once the link is gone.
Tests: test_script_path_refuses_while_a_secret_has_a_second_link and test_command_path_refuses_while_a_secret_has_a_second_link (link at ~/leak, child never spawned); dropping the refusal turns both 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 Oct 4, 2026
@iamwhatever
iamwhatever force-pushed the fix/cron-app-secret-mask-12518 branch from 5c93111 to 80684f8 Compare October 4, 2026 16:59
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 4, 2026
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 4, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=31cfe0f000f2
[operator: iamwhatever] accepted-and-deferred in 80684f8 — app-secret hard links outside the masked paths (Linux scan roots, unreadable enumeration)

Maintainer decision: the global refusal is removed, because one linked secret (e.g. a hard-link backup tool) would stop every cron on the host.
What remains: no bundle window opens while any secret is linked, and the inodes still reach the Linux alias scan. A link outside the masked directories stays readable; the PR body and learn-cron-dashboard.md record it.
Tracked in #16789 (security, area: cron). An unreadable apps root yields no alias ids, which is the same open residual.
Masked app-state writes under apps/ from a crons/ script are an Open question in the PR body, not new data loss for the bundle cron, whose data/ is a real writable window.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=2b51f30c56af
[operator: iamwhatever] fixed in 80684f8 — ride-along Seatbelt window admission

The contained-target admission now applies only to READ-ONLY windows (extra_readonly_private_dirs, passed only by the cron paths). Read-write windows go through _private_window_spellings unchanged, so acp/client.py and acp/runtime.py are unaffected and the profile digests do not move.
Test: test_seatbelt_still_refuses_a_read_write_window_holding_a_hidden_target; granting the admission to every window turns it red.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=7544dcfc745e
[operator: iamwhatever] fixed in 80684f8 — unreachable alias refusal

_refuse_path_only_alias_ids and both cron refusals are deleted. The () if alias_ids branch in cron_apps_mask is reachable again (the cron paths no longer return early), and test_any_aliased_secret_withholds_every_window covers it.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=af845734ec19
[operator: iamwhatever] fixed in 80684f8 — pin reversed without mention

The flip is reverted for read-write windows, so the pinned macOS behaviour of the pre-existing producers holds; test_sandbox_caller_pinned_ids.py passes unchanged. The read-only admission is declared in What changed.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=9f2eb926af9e
[operator: iamwhatever] rebutted in 80684f8 — relocate the secret instead

Moving .app_secret out of the bundle changes the app install layout, token_auth, the published Python client and every app that reads it, which is a contract change beyond #12518. It is listed as an option in #16789.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=d8b944341fc0
[operator: iamwhatever] fixed in 80684f8 — one app can stop every cron

The global refusal is removed (maintainer decision). A linked secret now only withholds bundle windows; the residual is tracked in #16789.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=e3c2d5c7251b
[operator: iamwhatever] rebutted in 80684f8 — published client inside a cron child

Reading another app's or its own secret from a cron child is exactly what #12518 removes; the client already treats a missing secret as no app auth. docs/app-kit/api-reference.md states app crons use ScriptContext, and the body lists the client as a Reader.

…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
@iamwhatever
iamwhatever force-pushed the fix/cron-app-secret-mask-12518 branch from 80684f8 to 6200408 Compare October 4, 2026 17:32
@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=298d0112641e
[operator: iamwhatever] rebutted in 6200408 — _command_bundle_refs for a non-owner command cron

main's own regression pin needs it: test/test_app_script_cron_sibling_import.py::TestACommandCronRunningBundleCode runs python <bundle>/run.py as a command cron with no created_by owner and requires the bundle to stay readable. Without the parser that case fails on every host with a sandbox, which is the #16072 regression.
It earns only read-only code: that bundle's data/ and .app_secret stay masked.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=f362762bf33b
[operator: iamwhatever] fixed in 6200408 (description) — relocating the secret was not weighed

What changed now states why moving .app_secret into a hidden crew-home leaf was not taken here: it changes the install layout, dashboard.token_auth, the published Python client and every app reading its own secret. Listed as an option in #16789.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

span=eb86354028f5
[operator: iamwhatever] fixed in 6200408 (description) — kirocrew_client inside a cron child

Backwards compatibility now carries a Breaking: line for that client path with a writer sweep on origin/main d8e2376 (no builtin app cron uses kirocrew_client), and states the rule: app crons use ScriptContext. Accepted, because reading that secret is the access #12518 removes.

@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 4, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) October 4, 2026 22:33

@bolichen97 bolichen97 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.

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.py script + command) pass app_owner_name(job.created_by) into the new owner_app positional slot correctly; those are the only production callers.
  • created_by is 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: whole apps/ masked in every home spelling; owned bundle read-only with data/ writable; referenced bundle read-only with data/ masked; every windowed .app_secret masked and required; no window at all while any secret is hard-linked.
  • Linux launcher: the nested re-hide loop pins .app_secret with S_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 with statvfs and 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:

  1. Breaking: a third-party app cron that authenticates with the on-disk secret via kirocrew_client loses app scopes at first fire, with no install-time warning.
  2. 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).
  3. Owned bundles are now read-only: an app cron that writes anywhere in its bundle outside data/ now gets EROFS (Linux) / deny (macOS).
  4. The four "Open questions" in the PR body, and the Design/First Principles point that moving .app_secret out of the bundle (#16789) would remove most of this machinery.

AI-assisted review, posted at bolichen97's request.

@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.

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

  1. No test covers the apps mask in the vault-grant script branch (*apps_mask.hidden at cron_script.py:2680); deleting it keeps everything green, and that is the branch holding vault secrets. Worth a one-line test.
  2. The st_nlink != 1 check in _settled_bundle_identity reddens nothing when removed (the global alias withholding covers it).
  3. 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.
  4. 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.

@iamwhatever
iamwhatever merged commit 69ee108 into main Oct 4, 2026
153 of 154 checks passed
@iamwhatever
iamwhatever deleted the fix/cron-app-secret-mask-12518 branch October 4, 2026 22:46
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 4, 2026
iamwhatever pushed a commit that referenced this pull request Oct 5, 2026
…he cron's own bundle readable (#16442)"

This reverts commit 69ee108.
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.

cron: a script cron child can read every installed app's .app_secret bearer credential

3 participants