Skip to content

fix: tighten a third sandbox file guard on fresh installs - #36096

Open
bolichen97 wants to merge 1 commit into
mainfrom
fix/10716-signing-key-stub
Open

bolichen97 wants to merge 1 commit into
mainfrom
fix/10716-signing-key-stub

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On a data home where the gateway has not started yet, the agent sandbox protects one more of its protected files from the first agent start, not only once the gateway has created it.

Part of the class of cases tracked in #10716: that issue already describes, in public, how this protection reached a file only once it existed. #30449 and #31810 closed two cases; this PR closes one more.

Why it matters

An agent can be started from the command line before the gateway has ever run on a home. Until the gateway's first start created this file, such an agent could write it, and the gateway would then trust what it found.

Not a goal

What changed (motivation → approach → change)

The sandbox could protect this file only once it existed, and the gateway creates it at its first start. A stand-in will not do here, because a stand-in of the wrong size stops the gateway from starting. So before the first agent start on a home that has none, the sandbox now runs the gateway's own creation step, which leaves exactly the file the gateway would have made. A home that already has the file is not modified. Creation waits while a leftover from an older version is present, so the recovery the docs describe for that leftover stays possible. The security spec in docs records the case.

Backwards compatibility

Compatible: the gateway reads the same kind of file it would have created itself, and a home that already has one is not modified.

Removes nothing: no reader loses access to anything; the change only makes an existing protection apply earlier.

Tests

New tests drive the step on a scratch data home: a home without the file gets one that is owner-only and that the gateway then uses unchanged; a home that has one keeps it untouched and still counts as protected; a leftover from an older version holds the creation off. The existing check that every file the sandbox creates is required at launch now names this file, and the sandbox ordering and facade pins list the new step.

Determinism: the changed test files passed 20 of 20 runs in one process, 10 of 10 with four workers beside two sibling test files, and one run in a shuffled order (seed 22157).

Proof: PROVEN 4 tests fail without the fix (head 7a586a1)

Manual verification

Run on Ubuntu 24.04 (Linux) in a real agent sandbox, each time on a fresh scratch data home with no gateway started:

Before this change With this change
The file when the agent starts absent present, owner-only
The agent reads it nothing there Permission denied
The agent writes its own bytes to it write: ok Read-only file system
What the gateway then loads the agent's bytes the file the sandbox made, unchanged

A home that already had the file kept it byte-identical across an agent start, and the agent could neither read nor change it.

Screenshots / video

N/A — no user-visible change.

Related Issues

Part of #10716

Sibling sweep

Swept: every file the same protection covers, on origin/main @ 00c5418.
Siblings: tracked in #10716 -- the remaining cases each need their own reader review.

Pattern harvest

Not generalizable: each protected file needs its own review of what its readers accept, so no single rule covers the class.

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

Contribution License Agreement

Submitted under the project's Apache-2.0 license.

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 12, 2026 21:28
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/sandbox.py

  • src/kiro_crew/sandbox_argv.py

  • src/kiro_crew/sandbox_staging.py

  • No reasoning template for 7a586a1 yet.

How to clear this check:

  1. The PR author posts the template below as a PR comment, with
    every field filled (N/A needs a reason). Keep the
    Head commit line: it must name the current head SHA.
  2. The check turns green within a minute, with no push.
  3. A new push resets this check: post it again for the new head.

Only the author's comment counts this way. A reviewer can instead
paste the filled template into an "Approve" review on this head.
Merging still needs a reviewer's approval.

## Sensitive change review
- Head commit: 7a586a14c6c24d9d36453ccb79bdee1ad98179a7
- What rule changed:
- Before -> after (what was allowed/blocked, now):
- Worst case if wrong (breaks commands / leaks secret / locks user out):
- Evidence checked (which sandbox result proves it):
- No regression:
  - Tools still work (which tools/commands were run, result):
  - Backward compatible (old config / old data / old callers still work, how checked):
  - Existing tests (which suites passed on this head):
- How to undo:

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

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 7a586a14c6c24d9d36453ccb79bdee1ad98179a7 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 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 7a586a14c6c24d9d36453ccb79bdee1ad98179a7 — 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 calls the gateway's own _load_or_create_secret instead of adding a second key writer, and it closes one more case of the class #10716 tracks.

Notes

  • Item 4 — undeclared: the Not-a-goal says "Any new refusal", but _note_established(established, target) now makes an existing key a required target that fails closed at spawn (sandbox_argv.py:854). Its five siblings already do this, so it is only a note.

What this change ships

Inventory (6 items) — 5 justified

Intent: stop an agent started before the gateway's first run from planting the signing key the gateway later trusts. FIX.

  1. On a fresh home, the first agent start now creates the real owner-only signing key — justified
  2. The agent can no longer read or write that key from its first start — justified
  3. Key creation waits while a pre-upgrade .token_signing.key.*.tmp is present — justified
  4. An existing key is now required at every spawn, which refuses on a name-swap race — undeclared
  5. The launcher process now imports the dashboard key module, only when the key is absent — justified
  6. Security spec entry, plus pin/facade/order test updates naming the new step — justified

[FIRST-PRINCIPLES-REVIEWED] 7a586a1

Description read

[DESCRIPTION-READ] 7ee86d425464bfbb39e37ad212ce17a12d5af3a6a6ba5aef084cf764173366b1

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: running the gateway's own create-once path avoids a key the boot would refuse, and it follows the same materialise-then-require pattern as the .env and refresh_chains.json cases.

Notes

  • Any kirocrew chat launch outside the gateway now imports dashboard.token_secret and can run its link/retry loop. token_secret._load_or_create_secret is the stated cross-process single-creator path, so a launcher racing a first-time gateway still ends up with one key. Keep that function as the only writer if it is refactored later.

[DESIGN-REVIEWED] 7a586a1

Description read

[DESCRIPTION-READ] d0ca8a05068fa139c72345a36fa872e5ae235d65b06b6080311b7e1a4fc51fee

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 7a586a14c6c24d9d36453ccb79bdee1ad98179a7 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 7a586a1

Verdict parsed from the review's SHA-scoped output markers for commit 7a586a14c6c24d9d36453ccb79bdee1ad98179a7.

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

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 7a586a14c6c24d9d36453ccb79bdee1ad98179a7 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7a586a1

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 12, 2026 21:50
@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 12, 2026
@bolichen97
bolichen97 force-pushed the fix/10716-signing-key-stub branch from b7cf0ca to 39e7f52 Compare November 13, 2026 03:52
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/security.md, src/kiro_crew/sandbox.py, test/test_sandbox_refactor_facade.py since this head's CI ran (2f7e9f2 -> b2aac45); CI re-running.

The Build Wheel, Build Desktop and E2E (stub ACP backend) reds on the old head were main's: Cannot find name 'GitFork' in the chat page, fixed on main by #36124, which the new base carries. The three cancelled macOS backend shards hit the 40-minute job limit with no failing test; #36198 raises that limit, so they are not rerun here.

[operator: bolichen97]

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 13, 2026
On a data home where the gateway has not started yet, the agent sandbox
protects one more of its protected files from the first agent start,
not only once the gateway has created it.

Part of #10716
@bolichen97
bolichen97 force-pushed the fix/10716-signing-key-stub branch from 39e7f52 to 7a586a1 Compare November 13, 2026 10:02
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/sandbox_argv.py (a merge conflict: #33589 added a launcher step at the same spot; both kept, in their original order), src/kiro_crew/sandbox.py, docs/system-specs/modules/security.md and test/test_sandbox_refactor_facade.py since this head's CI ran (b2aac45 -> 00c5418); CI re-running.

The reds on the previous head were never verdicts on the code: the CI installation's API rate limit was spent when they ran, so Await Fast Gate and the review lanes failed closed before judging anything. This push re-runs them.

[operator: bolichen97]

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 13, 2026
@KiroCrewCaptain

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 _materialize_signing_key_mask_target, which runs the gateway's own key-creation path (_load_or_create_secret) before each namespace spawn when token_signing.key is absent. The already-masked key therefore exists from the first agent start, and an agent can no longer write a key the gateway would accept. It runs before the legacy-temp sweep, the staging-link cleanup and the hard-link check, so a staging link left behind by key creation is removed before the check could refuse. Creation waits while a pre-upgrade temp is present, matching the sweep's keep-for-rename choice. The ephemeral fallback leaves the name absent and the spawn goes ahead as before, so there is no new refusal. An existing key is never rewritten. The masked set does not grow. The new tests cover creation (the gateway loads the same key, file is owner-only), an existing key and the hold-off, and the existing ordering and required-set tests are updated. No blocking defects found.

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 7a586a14c6 · 115 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The red Backend Tests (3.12, 7) on this head, and the Coverage Gate that fails closed on it, is a flake that main also shows, not this change. test/test_denied_commands_security_cost.py::TestSelfModuleIndexIsLinear::test_the_scan_is_linear_not_quadratic missed its 0.5 s wall-clock bound (2k tokens took 0.532s) here: https://github.com/kirodotdev/KiroCrew/actions/runs/43406040754/job/132067520583. The same node id is red on main (2k tokens took 0.590s): https://github.com/kirodotdev/KiroCrew/actions/runs/43507576055. This PR does not touch the deny gate or that test.

It is tracked in #28212, and #28293 is the open fix. This PR waits for that fix and is rebased onto it once it merges; no rerun is spent on a test with this many reports.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants