Skip to content

fix: keep the owner-only switches sealed after a save on linux - #31833

Merged
bolichen97 merged 1 commit into
mainfrom
fix/15143-toggle-seal-keeps-inode
Nov 12, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/15143-toggle-seal-keeps-inode

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On Linux, a running sandbox can no longer change the owner-only computer use, decision consent and credential redaction switches after the owner saves one of them.

On Linux, once the owner saved one of these three switches, a sandbox that was already running could change that switch itself until the sandbox was restarted.

Why it matters

Each switch is a permission the agent must never grant itself: control of the desktop, sending message text to an outside provider, or showing raw credentials in the owner's file view. Each owner save reopened that for every running sandbox on the host.

Not a goal

What changed (motivation → approach → change)

After the owner saves the decision consent or credential redaction switch, a running Linux sandbox still cannot change it. The save rewrites the existing record in place, as the Shared Crew preview switch already does, so the read-only protection the sandbox holds over it stays in force. One shared writer (src/kiro_crew/atomic_write.py) serves these three switches (src/kiro_crew/decisions, src/kiro_crew/security, src/kiro_crew/shared_crew). The preview switch writes the same bytes as before and gains what the shared writer adds: the failed-write rollback below, and creating a missing data folder.

The computer use switch keeps the save main gives it. Main already ignores a change made to that record from inside a sandbox and holds the change for the owner to review (#31066), so this PR leaves that record alone.

An in-place save is not all-or-nothing on a crash, so two edges are handled. A save whose write fails puts the previous record back before it reports the error. A record that save created goes back to {}, the document a sandbox spawn pre-creates, and no record is ever removed, since a sandbox spawned meanwhile may already hold it sealed. If both writes fail (a full disk) or the gateway crashes inside the rewrite, the record can be left empty. An empty record reads as the switch's safe default: not consented, redaction on, preview off. The consent save reads the record before it writes, so it refuses an empty one as corrupt, as main does, and never drops the browser opt-outs a crash erased. The owner then removes the record to save again and restarts running agent sessions, because on Linux removing the record lifts its seal in them, as it does on main. The security spec in docs and the sandbox notes (src/kiro_crew/sandbox_precreate.py) describe the new behaviour.

Backwards compatibility

Breaking: a decision consent or credential redaction save now fails when the record is a link or has a second hard link (a hard-link backup of the data home makes one); the owner sees the save fail, and the gateway log names the record and the cause; the provider route, which carries a standing consent over to a new endpoint, reports that consent as not carried instead. Main replaced the record with a fresh file. The Shared Crew preview save already refused both on main. The in-place save and these refusals apply on every platform; only the seal it keeps is Linux's. Writer sweep on origin/main @ ed833a5: the redaction and preview switches each have one writer, their owner-only dashboard route; the consent record has two, the owner-only consent route and the owner-only provider route that carries a standing consent over to a local model; each route already reports a failed save to the owner, and nothing else writes these records.

Removes nothing: every switch keeps its location, its format and its readers. An empty record reads as the default and is refused by the consent save, which reads before writing, both as on main.

Tests

  • One added test per switch this PR changes (consent, redaction): a save keeps the existing record in place, which is what the running sandbox's protection depends on.
  • An empty consent record is refused as corrupt and left as it is, not saved over.
  • A consent save whose write fails leaves the previous record, browser opt-out included, and a first save whose payload write fails keeps the record it created as {}, which reads as not consented and does not block the next save.
  • The four consent tests sit in test/test_decisions_consent_in_place.py, which keeps test/test_decisions_consent.py under the file line cap. Existing tests that intercept the consent write follow it to the shared writer; no assertion changed.

Proof: PROVEN test/test_credential_redaction_switch.py::TestSwitchedOffInsideOwnerView::test_a_save_rewrites_the_existing_record_in_place, test/test_decisions_consent_in_place.py::TestInPlaceSave::test_a_save_rewrites_the_existing_record_in_place (head 0416471)

Determinism: the five added tests ran 20/20 at -n0, 10/10 for their four files at -n 4 --dist loadgroup --max-worker-restart=2, and green together with every test of those files in a shuffled order (seed 23562).

Manual verification

N/A — unit coverage sufficient: the tests drive the real writer on the real file, and the Linux protection it keeps is the one the Shared Crew preview switch already relies on. Not run against a live Linux sandbox.

Related Issues

Part of #15143

Sibling sweep

Swept: every writer of the protected records #15143 names that still exist on main (git grep -n "atomic_write(" -- src/kiro_crew beside each record's path function).
Sibling: src/kiro_crew/computer_use/enable_state.py -- not affected -- main holds this record by its endorsed copy (#31066)
Sibling: src/kiro_crew/config -- tracked in #15143

Pattern harvest

Not generalizable: each remaining protected record needs its own placement decision, and the one #15143 still tracks needs a reviewed design of its own.

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

Contributed under the project's Apache-2.0 license.

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 6, 2026 21:45
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] test/test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget fails on main independently of this change (tracked in #31648); this PR leaves that package's line count unchanged, so the red clears when that fix lands.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/sandbox_precreate.py

  • src/kiro_crew/security/redaction_switch.py

  • @buluoray: missing the ## Sensitive change review heading

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: 04164719f6b79d389c95019492b1cce9aa740969
- 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 6, 2026
@bolichen97
bolichen97 enabled auto-merge (squash) November 6, 2026 22:13
@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 6, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 04164719f6b79d389c95019492b1cce9aa740969 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The diff only touches backend writers, tests and docs. It adds or changes no dashboard control, label or string. The new refusal messages are written to the gateway log, and the routes keep their existing failed-save reporting.

[UX-REVIEWED] 0416471

Description read

[DESCRIPTION-READ] dc9fb44abe35ff7fcc5584391eabd7bc9e35a168e202ddc368008e680bf12ba3

That sha256 names everything this verdict read: the PR description, plus the 3 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 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks. The change moves the in-place writer that preview.py already proves into a shared helper. The new risk, a record left torn or empty, falls back to each switch's safe default, and the description explains how to recover.

Notes

  • The **Goal:** line includes "computer use", but the body says "this PR leaves that record alone". The PR is not doing what its Goal says for one of the three switches. Say so in a PR comment instead of editing the frozen Goal.
  • If a crash empties the consent record, read_state_strict refuses the next save until the owner deletes the file by hand. Make sure the save error message tells the owner to do that. Right now the steps are only in the PR description.

[DESIGN-REVIEWED] 0416471

Description read

[DESCRIPTION-READ] 0eae31872803ffc4e6b199a3a67893e4e060499402e729c589b670f47eb95425

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 04164719f6b79d389c95019492b1cce9aa740969 — 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 writer that keeps the inode already existed in preview.py and is now shared, and the inode tests fail on base. The open item is the rename-published sealed leaves this PR leaves for later.

Not checked: whether a Linux bind mount stays sealed across an in-place ftruncate and rewrite in a live sandbox.

Notes

What this change ships

Inventory (6 items) — 5 justified

Intent: on Linux, a sandbox that is already running can no longer change the consent or redaction switch after the owner saves it. This is a FIX.

  1. Saving the consent or redaction switch keeps the same file (inode), so a running Linux sandbox's read-only seal stays in place — symptom-level
  2. One shared in-place writer rewrite_in_place now serves the Shared Crew preview, consent and redaction saves (3 importers), replacing the preview's private copy — justified
  3. A failed save puts the previous record back; a record the save itself created goes back to {} — justified
  4. A consent or redaction save now refuses a record that is a link or has a second hard link — justified
  5. The preview save now creates a missing data folder — justified
  6. The security spec and the sandbox pre-create notes describe the in-place saves — justified

(The chat-panel hunks in the patch are #34110, which is already on base, and are not part of this PR.)

[FIRST-PRINCIPLES-REVIEWED] 0416471

Description read

[DESCRIPTION-READ] 33ca595d1184970fe89383e9e5dec4b0e321ce5f22d8cf6cfd4d9a6c2da59c89

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

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 04164719f6b79d389c95019492b1cce9aa740969 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 0416471

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

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 04164719f6b79d389c95019492b1cce9aa740969 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 0416471

Verdict parsed from the review's SHA-scoped output markers for commit 04164719f6b79d389c95019492b1cce9aa740969.

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

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/15143-toggle-seal-keeps-inode branch from 246db7b to 6367ba1 Compare November 7, 2026 03:06
@bolichen97

bolichen97 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=f0a9d0e3d281 An interrupted save silently widens permissions on re-enable
    self-added: yes
    mechanism: empty-record-means-{} shortcut in the two read-before-write save paths
    resolution: removed

fixed in 6367ba1: the computer use and consent save paths no longer read an empty record as {}; an empty or cut-off record is refused as corrupt (as on main), so a patch save can never drop the app restrictions or browser opt-outs a crash erased. The fail-soft enforcement readers still read it as off / not consented.
A first save whose write fails now removes the file it created instead of leaving an empty one, so the refusal cannot block a retry on a fresh data home.
Red/green: test_an_empty_keystone_is_refused_not_saved_over and test_refuses_to_save_over_an_empty_file fail with the shortcut and pass without it; test_a_failed_first_save_leaves_no_record fails before the removal and passes after.

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

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ human override accepted

@bolichen97 overrode this lane for 04164719f6b79d389c95019492b1cce9aa740969 via /ai-review override (this commit only).

[SCOPE-REVIEWED] 0416471

@bolichen97
bolichen97 force-pushed the fix/15143-toggle-seal-keeps-inode branch from 6367ba1 to 09cb54a Compare November 7, 2026 04:20
@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 7, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: remove a record rewrite_in_place created when its write fails
resolution: removed

  • span=cf01e525e42f Failed first-save rollback removes a concurrently sealed keystone

fixed in 09cb54a: rewrite_in_place no longer unlinks anything. A record it created and failed to write stays on the same inode, empty, so a sandbox that sealed it meanwhile keeps its seal; the fail-soft readers read it as off / not consented / redaction on.
The cost is the one already recorded for a crash inside a rewrite: the computer use and consent saves refuse that empty record as corrupt until it is removed by hand. No restriction is dropped and no seal is detached.
Red/green: test_a_failed_first_save_keeps_the_record_it_created fails on the previous head (the record was removed) and passes here.

@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 7, 2026
@bolichen97
bolichen97 force-pushed the fix/15143-toggle-seal-keeps-inode branch from 09cb54a to e375e1c Compare November 7, 2026 07:18
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: rollback of a record rewrite_in_place created
resolution: narrowed

  • span=e9570d5cb5eb A first save that fails leaves a 0-byte record that strict saves refuse

fixed in e375e1c: a record this save created rolls back to {} (the document a sandbox spawn pre-creates, read as absent), not to zero bytes, so a failed payload write no longer blocks the next save. test_a_failed_first_save_keeps_the_record_it_created is red on the previous head and green here.
Residual kept by maintainer decision: if the rollback write fails too (a full disk) or the gateway crashes inside the rewrite, the record can still be left empty. It fails closed (computer use off, no consent) and the owner removes the file to save again.
Closing that residual needs a publish-then-link step, which leaves a second writable name for the sealed record if the gateway dies between the link and the temp removal; that is a seal bypass, so the fail-closed residual is the chosen trade-off.

@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 readiness: checking Automated validation is still running labels Nov 7, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Rebased: main moved in the line-budget and platform collect-ignore tests (fixed on main by #32252 and #32209) since this head went red (b65af1a -> f58c3cf); CI re-running. The patch is unchanged (git range-diff shows the same commit); local scoped tests, flake8, isort and mypy pass, and local GPT and Opus reviews of 6e6162e passed.

AI-assisted, posted on behalf of bolichen97

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/15143-toggle-seal-keeps-inode branch from 6e6162e to a183500 Compare November 9, 2026 04:45
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/computer_use/enable_state.py and src/kiro_crew/dashboard/handlers/computer_use.py (#31066), which conflicted with this PR, and in src/kiro_crew/atomic_write.py, src/kiro_crew/sandbox_precreate.py, src/kiro_crew/security/redaction_switch.py, test/test_credential_redaction_switch.py and docs/system-specs/modules/security.md since this head went green (f58c3cf -> 63d560b); CI re-running.

Main now holds computer_use.json by an endorsed copy and holds any change made to it from inside a sandbox for the owner to review, so the conflict resolves to main's computer use save: the new head drops this PR's change to that save and its two computer use tests. The shared writer's failed-write rollback keeps its coverage through the consent save, in test/test_decisions_consent_in_place.py, which also takes the consent tests this PR adds so test/test_decisions_consent.py stays under the line cap. The decision consent, credential redaction and Shared Crew preview saves are unchanged from the previous head.

[operator: bolichen97]

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

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

Approving. Consent and credential-redaction saves now rewrite the record in place (same inode), so a running Linux sandbox's read-only bind mount stays sealed after an owner save (atomic_write.py:1748, decisions/consent.py:589, 610, security/redaction_switch.py:311). The preview switch's existing in-place writer moves into the shared helper with the same behavior, plus a rollback on a failed write (shared_crew/preview.py:85). Sensitive Change Review still needs the author's template.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The red Fast Gate on a183500 comes from main, not from this change: test/test_pid_reader_ratchet.py::test_owner_marked_sites_match_the_recorded_count failed the same way on main at 456d804, and #33695 fixed it on main after this head's base (63d560b). The CI, Coverage Gate and PR Readiness reds follow from that one gate.

The next push rebases this branch onto a main that carries #33695. The Sensitive Change sign-off belongs on that new head, because a push dismisses the current approval.

A save of an owner-only switch could leave a running sandbox able to
change that switch until the sandbox restarted. The record now keeps
its identity across a save, so the read-only protection a running
sandbox holds over it stays in force.

Part of #15143
@bolichen97
bolichen97 force-pushed the fix/15143-toggle-seal-keeps-inode branch from a183500 to 0416471 Compare November 10, 2026 15:11
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/sandbox_precreate.py and docs/system-specs/modules/security.md, and fixed the Fast Gate red this head carried from main (test/test_pid_reader_ratchet.py::test_owner_marked_sites_match_the_recorded_count, fixed by #33695), since this head was built (63d560b -> ed833a5); CI re-running.

The patch is unchanged: git range-diff shows the same commit, and main's change to sandbox_precreate.py is in a different list of that file. The previous approval was for a183500 and does not carry the Sensitive change review template, so this head needs a maintainer's approval with that template filled in.

[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Security Scope Review red on 0416471 held by the per-head floor

Rebutted: not a finding. The lane measured this head clean: its comment reads PASS, 0 newly refused on every leg (macos-latest 9, ubuntu-latest 9, windows-latest 4 classified).
The red is only the per-head floor. The first attempt of run 42841935159 produced no verdict (no platform leg reported while the API rate limit was spent) and failed closed; attempt 3 measured success and was held at that earlier failure.
On a same-repo PR a re-run cannot clear a prior unmeasured run (docs/ci/ci-and-reviews.md, Security Scope Review); the SHA-scoped scope override is the documented exit.
[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

/ai-review override scope 0416471 not-applicable: agent: not a finding. This head's lane comment reads PASS, 0 newly refused on every leg; the red is the same-repo per-head floor holding attempt 1 of run 42841935159, which produced no verdict while the API rate limit was spent. Attempt 3 measured success and was held at it; a re-run cannot clear it. Widens no restriction.

[operator: bolichen97]

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@bolichen97 recorded a not-applicable release (class not-applicable) for the scope AI finding on 04164719f6b79d389c95019492b1cce9aa740969.

agent: not a finding. This head's lane comment reads PASS, 0 newly refused on every leg; the red is the same-repo per-head floor holding attempt 1 of run 42841935159, which produced no verdict while the API rate limit was spent. Attempt 3 measured success and was held at it; a re-run cannot clear it. Widens no restriction.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 12, 2026
@bolichen97
bolichen97 merged commit 13f385f into main Nov 12, 2026
117 of 129 checks passed
@bolichen97
bolichen97 deleted the fix/15143-toggle-seal-keeps-inode branch November 12, 2026 12:30
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 12, 2026
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.

2 participants