Skip to content

fix(sandbox): mount config.json and config.local.json read-only - #14486

Merged
iamwhatever merged 1 commit into
mainfrom
fix/crew-config-seal
Sep 30, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/crew-config-seal

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The owner's settings files cannot be changed from inside the agent sandbox.

~/.kiro/crew/config.json and config.local.json hold the owner's settings. Some of those settings loosen safety limits. Today a sandboxed agent shell can write both files, while its sibling ceiling files (denied_commands.json, security_policy.json, computer_use.json, ...) are already mounted read-only.

Why it matters

Settings that loosen limits should only be changed by the owner, from the dashboard or their own terminal. They should not be changeable by the process those limits apply to.

Not a goal

What changed (motivation → approach → change)

Part Change
Sandbox config.json and config.local.json are mounted read-only, in every tier, and pre-created when absent
CLI kirocrew config prints a one-line hint when the write is refused
Docs Specs say both files are read-only in the sandbox

Both settings files were writable from inside the sandbox → the settings loader's value clamp only bounds numbers, it cannot stop a valid value that loosens a switch → mount both files read-only, like the other ceiling files.

sandbox.py adds both files to _CREW_READONLY_LEAVES and _CREW_PRECREATE_READONLY_FILE_LEAVES, so Linux can bind-mount them even when the overlay does not exist yet. Reads still work: both are listed as child-readable, since every in-sandbox KiroCrewConfig.load() opens them and neither was ever on the read-gate floor. cli_config.py catches the denial and prints where to change the setting instead. It decides from the failing file name and errno, not from the sandbox env marker, because cli.main() clears that marker before dispatch. The hint names both causes: the sandbox by design, or plain file permissions. security/paths.py shortens the comment that said the loader clamp covers any value written into config.json. Specs (security.md, config.md, decisions.md, messaging.md, subagent.md, aws-control.md, app-kit-platform.md, docs/feature-map/README.md) now say both files are read-only in the sandbox, and security.md records the two residuals below.

Backwards compatibility

Breaking: an agent shell inside the sandbox can no longer run kirocrew config set/unset/defaults. Writer sweep on origin/main: the dashboard, settings API, channel handlers and the user's own CLI all write from the gateway or the user's process, outside the sandbox, and are unaffected. The loader's migration write-back already catches a failed write and logs a warning. MCP servers read config and write through the gateway API.

Residuals, both shared with every other sealed leaf:

  • Linux per-file bind. The seal is a bind mount on the file. Every host writer publishes through temp-plus-rename, and the kernel detaches a file bind whose target is renamed over from another mount namespace. So on Linux the seal holds from spawn until the next gateway save of that file; after that the name is unsealed in that sandbox until it respawns. That save is not only the owner's: the gateway also saves on its own (boot migrations, member-identity publication, memory-store provisioning), and an in-sandbox agent can reach some of those paths indirectly through an ordinary tool call. macOS (Seatbelt, path-based) is unaffected. Compared with main, where both files are writable for the whole session, this narrows the window to "after a save, until respawn". The fix for every sealed leaf together (one read-only directory instead of per-file binds) is sandbox: sealed ceiling leaves publish by rename, which unseals the Linux file bind until respawn (6 leaves incl. config.json) #15143.
  • Second name. A symlinked or hardlinked config.json (a dotfile manager) is sealed by name only; the other name stays writable. The Linux spawn path treats it as it does every sealed leaf: a resolving link warns and continues; a dangling link (target absent) refuses the spawn.

Tests

  • test/test_sandbox_config_seal.py: both files are in the read-only and pre-create sets for every tier and stay child-readable; the CLI hint fires for a denial naming either file with no sandbox env marker set, replaces the generic write error, and does not fire for other files or other errors.
  • test/test_sandbox_protected_name_holds.py: leaf-only count raised by 6 (two root-level leaves × three home spellings). They sit at the data-home root, which no directory mask can hold, the same as credential_redaction.json and redaction-allow.
  • Ran locally: test_sandbox_config_seal.py, test_sandbox_protected_name_holds.py, test_security_gate_liveness.py, test_sandbox_governance_mask.py, test_cli_config_defaults.py, test_cli_commands_coverage.py, test_config_loader.py, test_weixin_qr.py (1604 passed, 1 skipped); black, flake8, isort and mypy clean on the changed files.

Manual verification

On macOS, from inside a live standard-tier session, confirmed config.json was openable for write before the change. The nested Seatbelt run cannot be repeated here (sandbox-exec cannot nest), so the read-only effect is covered by the set tests above and CI. Linux not run by hand.

Related Issues

Reported privately. Linux per-file bind residual for all sealed leaves: #15143.

Pattern harvest

Rule candidate: review-prompt
Pattern: a file under the crew home whose contents can loosen a safety limit must be in the sandbox read-only set; a per-file bind seal on Linux lasts only until the host's next rename onto that name.

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

@iamwhatever
iamwhatever requested a review from a team as a code owner September 27, 2026 16:46
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Intent: Stop a sandboxed agent process from changing the owner's settings files (config.json, config.local.json), so it cannot loosen its own limits.
Not a goal: Moving settings keys into new files, changing any default, or changing how the gateway/dashboard/user CLI write config.

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

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of afbeced0f7e6154e0a1e39846df3857c01db5e75 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] afbeced

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

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

On Linux the seal is agent-defeatable today: an induced gateway save detaches the bind, reopening the agent.sandbox: "off" escape until respawn.

Watch

The description concedes "an in-sandbox agent can reach some of those [save] paths indirectly through an ordinary tool call" — so on Linux a prompt-injected agent can induce a config.json save (memory-store provisioning, member-identity publication), then write the confinement switch this PR exists to seal. Unlike every prior READONLY leaf (saved only by owner action), this is the gateway's most-rewritten file, so the shared residual is uniquely agent-triggerable here; the change still strictly narrows main, but the headline guarantee holds unconditionally only on macOS, and #15143's priority is now set by this leaf, not the quiet ones.
Clears when: #15143's read-only directory bind lands, or the agent-reachable gateway save paths stop rewriting config.json when its bytes are unchanged (removing the inducible detach).

[DESIGN-REVIEWED] afbeced

Description read

[DESCRIPTION-READ] f458095d6a0c13fa19d02bd73cd331ef3137ae0a8df41a11225fec01acc03ff0

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

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of afbeced0f7e6154e0a1e39846df3857c01db5e75 — 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: PASS

Verify the seal on a real Linux sandbox before merge: the description says "Linux not run by hand," and the new tests pin set membership, not a refused write.

Not justified as shipped

  • Item 4 — rides along: the CLI hint is not the seal itself; it is a declared rider explaining the refusal the fix creates, with 2 counted call sites (cli_config.py:126,533) and no premise risk.

What this change ships

Inventory (7 items) — 6 justified

Intent: stop a sandboxed agent from rewriting the owner's settings files — the switches in them (agent.sandbox: "off", governance.py:173) end its own confinement. This is a FIX.

  1. Inside the sandbox, config.json / config.local.json are read-only in every tier — justified
  2. Both files pre-created when absent, so an agent cannot create the overlay to win the merge — justified
  3. Both classified child-readable for an ENFORCED harness, preserving what a child could already open — justified
  4. In-sandbox kirocrew config set/unset/defaults now exits with a pointer to the dashboard instead of a traceback — rides along: declared rider on the fix, small surface, no premise risk
  5. Eight specs rewritten from "config.json is agent-writable" to "sealed read-only" — justified
  6. security/paths.py comment: the loader clamp bounds numbers, not switches — justified
  7. Leaf-only count pin raised 253→259/260→266/261→267 — justified

The rewritten "deliberately VISIBLE / writing it there is routine" pin is reversed with evidence: the description's writer sweep counts zero legitimate in-sandbox writers, and the clamp claim is shown wrong for switches. The Linux rename-detach residual is declared at its level and deferred to #15143 — accepted-and-deferred.

[FIRST-PRINCIPLES-REVIEWED] afbeced

Description read

[DESCRIPTION-READ] f34a8e271331c0f6bdc3f63c86a3fadf005ddfc6642e88e788702ba7652aa5c8

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

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🟡 CONCERNS

Which legitimate operations does afbeced0f7e6154e0a1e39846df3857c01db5e75 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: the reviewer's own judgement; no confirmed regression.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 11 classified, 0 newly refused, 11 still allowed.
  • ubuntu-latest (platform posix): 11 classified, 0 newly refused, 11 still allowed.
  • windows-latest (platform windows): 5 classified, 0 newly refused, 5 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: CONCERNS

TIGHTENING: OS-sandbox read-only seal of the runtime config pair — sandbox._CREW_READONLY_LEAVES gains "config.json", "config.local.json" (with matching pre-create entries and a cli_config._sandboxed_config_write_hint errno relabel) — refusing the one threat the hunk names: "without it an in-sandbox shell could write agent.sandbox: \"off\" and run its next spawn unconfined" — an in-sandbox agent ending its own confinement through any open()/redirect the file-edit-tool fence never sees.

ADJUDICATED: 14 candidates, 0 confirmed newly-refused
No confirmed rows were handed back in this run; the candidates probe the tool-call deny composite, which this diff does not modify — the security/paths.py hunk is comment-only, and the leaf lists feed sandbox mount construction, not command classification. A zero-flip result over these rows therefore measures that nothing rode along into the composite, not the seal itself.

PLATFORM COVERAGE: posix — home-path reads of both sealed leaves under both _CREW_HOME_PREFIXES spellings (~/.kiro/crew, ~/.kirocrew), the base/overlay diff, and workspace-relative writes to a project's own config.json (> redirect, sed -i), because the seal's mechanics and errno reasoning (EROFS/EBUSY bind mount, EPERM Seatbelt) are written in posix terms and the one-token-off boundary is the ubiquitous workspace filename. windows — the cmd (type %USERPROFILE%\...) and PowerShell (Get-Content $env:USERPROFILE\...) spellings of the sealed-home read, plus a PowerShell workspace config.json write, because no test on this repo's default runner exercises those tokenizers. any — kirocrew config get and git checkout -- config.json, which carry no separator. One assumed platform I could not probe: the diff names no Windows seal mechanism at all (Linux binds and Seatbelt only), so whether a Windows host gains the seal — and whether the errno set EPERM/EACCES/EROFS/EBUSY matches what a Windows denial raises for the CLI hint — is a question no candidate of mine can put to the classifier. The per-leg verdicts are the deterministic fold's to report, after this review is captured.

UNADJUDICATED: The tightening lives almost entirely outside the classifier's reach. The guard is the kernel-level read-only mount of config.json/config.local.json: the gateway spawn builds mount specs from _CREW_READONLY_TARGETS/_CREW_PRECREATE_READONLY_FILE_LEAVES, and every in-sandbox process's open(path, "w") or os.replace(tmp, path) then fails at the kernel, with cli_config._sandboxed_config_write_hint relabeling the errno for kirocrew config set/config defaults --adopt. No shell-composite verdict exists for any of that. The candidate legitimate inputs I would have submitted, in prose:

  • An in-sandbox kirocrew config set <benign key> — an agent asked by its operator to change an ordinary setting (a timeout, a UI key) loses a formerly-working write and is redirected to the dashboard. Deliberate and hinted, but it is a withdrawn operation with no verdict available.
  • The load-time migration write-back inside any sandboxed KiroCrewConfig.load() (sandboxed CLIs, MCP servers) — the diff says it fails soft with a Config write-back failed warning; unverifiable here.
  • The vector-memory <leaf>.lock sidecar acquisition from in-sandbox code — kept writable by exempting the sidecar per the sandbox.py comment; correct on its face, no verdict.
  • In-sandbox reads via the mount layer itself — the _CREW_CHILD_READABLE_LEAVES classification is what keeps every sandboxed KiroCrewConfig.load() booting; my cat rows probe the composite half only, not the mount allowance.
  • The dangling-symlink spawn refusal: by joining the pre-create/readonly leaf set, ~/.kiro/crew/config.json now flows through the pre-existing _refuse_if_dangling_symlink (sandbox.py:2193, raising SandboxCeilingUnsealable). config.json is the most commonly dotfile-managed file in the sealed set (chezmoi/stow hosts routinely symlink it), so a dangling link that yesterday cost nothing now refuses every agent spawn on that host. The diff handles a resolving link with warn-and-continue, but the dangling case is a whole-host over-refusal I can argue and cannot confirm — it is the concern this verdict carries.

[SCOPE-REVIEWED] afbeced

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

In-sandbox kirocrew workspace/agent config writes now fail — several with an unhandled traceback — and the new hint is not wired into their path.

FINDING — src/kiro_crew/sandbox.py:597 — sealing "config.json" read-only in every mode (default agent.sandbox: "auto") makes the agent-facing commands its own bundled skill advertises (kirocrew workspace create/update/delete, kirocrew agent delete — builtin_skills/kirocrew-commands/SKILL.md:305-314) reach cli_commands._locked_config_write → loader.update_config_locked → a denial errno, and that helper's except BaseException: … raise propagates to cli.main(), which has no OSError handler, so the command dies on a bare traceback; agent create reaches persist_member_config and prints only Error: [Errno 30] Read-only file system, while _sandboxed_config_write_hint is wired only into cli_config._config_cmd/_defaults_cmd, and the leaf comment's "Every legitimate writer … runs outside the sandbox" does not cover them → Fix: catch the denial in cli_commands._locked_config_write (and the persist_member_config callers) and print cli_config._sandboxed_config_write_hint(exc), or narrow the leaf comment and security.md to name the commands the seal now refuses.

[OPUS-REVIEWED] afbeced

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable afbeced0f7e6154e0a1e39846df3857c01db5e75: <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 Sep 27, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 27, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=2057aee8f94a: fixed

The hint no longer reads KIROCREW_SANDBOX_ACTIVE, which cli.main() pops before dispatch.
It now keys on a denial errno whose filename/filename2 is config.json or config.local.json (_names_sealed_config).
Tests drive the real shape: no env marker, OSError naming the file, both in-place and temp-replace forms. Fixed in f9d8c28.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=6a96966538cb: fixed

Same root cause as the GPT finding: dropped the env check; hint keys on errno plus the failing file name.
config edit's execvp EACCES names the editor, not a sealed file, so it is not mislabelled; a test pins that. Fixed in f9d8c28.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=aec828f504b1: fixed

Rewrote security.md bullets that still called config.json a VISIBLE, agent-writable leaf; the in-sandbox write is now stated as kernel-denied.
Each bullet keeps its own argument (consent lives on the keystone because it is an authorization). Sibling sentence in decisions.md updated too. Fixed in f9d8c28.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=356c4e6acf32: fixed

Kept the read (every in-sandbox KiroCrewConfig.load() needs it) and corrected the _CREW_CHILD_READABLE_LEAVES comment and crew_host_runtime_leaves() docstring.
They now say the pair can hold channel bot tokens and is readable despite that, as the named exception. Comment-only. Fixed in f9d8c28.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=b51c6631d412: fixed

Swept the remaining passages: messaging.md, subagent.md, aws-control.md, config.md, decisions.md, security.md, plus app-kit-platform.md and docs/feature-map/README.md.
Each now states both files are read-only in the sandbox. Fixed in f9d8c28.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=a45c49556509: fixed

Declared in the PR body's Backwards compatibility section: on Linux a running sandboxed process sees spawn-time settings until respawn.
None of those in-sandbox reads is a security decision; new values apply on the next spawn. Body updated for f9d8c28.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=7fe3d5c16e03: fixed

Declared in the PR body: both files are also listed as child-readable because every in-sandbox config load needs them.
The comment now names that the pair can hold channel bot tokens and is readable anyway. Body updated for f9d8c28.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Sep 27, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 28, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: no
mechanism: in-place POSIX config write + static publish guard

  • span=fa7ab943e399: fixed

Fixed in 4fa37f9: on POSIX write_config_atomically now writes in place (write, then ftruncate), so the bind keeps its inode across owner saves.
weixin_qr.py, the one writer with its own rename, now uses the shared writer.
Tests: inode and mode kept for both files; a static guard fails if any source publishes either file via atomic_write/os.replace/rename/write_text.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=356c4e6acf32: fixed

Same root cause as the GPT span on sandbox.py:582. Fixed in 4fa37f9: POSIX config saves keep the inode, so the leaf-only self-bind is not detached by a rename.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=6a96966538cb: rebutted

Disproportional here: the hint is a UX nicety for the two commands an agent is most likely to try. Other in-sandbox writers still fail closed and re-raise the OS error.
No defect: the seal holds either way; only the message wording differs.

@github-actions github-actions Bot removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention labels Sep 29, 2026
@iamwhatever

iamwhatever commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=9ec07ed2ded9: fixed

post-commit bookkeeping can report a successful save as failed (loader.py:1560).
fixed in 9eb4013: the post-fsync os.fstat and the os.close in finally are each wrapped in try/except OSError and log a warning, the same rule the mtime bump already followed. Two tests added (test_a_failing_post_commit_fstat_does_not_fail_the_committed_write, test_a_failing_close_does_not_fail_the_committed_write); both fail without the fix.

Also in 9eb4013: _PACKAGE_LINE_BUDGET re-pinned 27_863 → 27_865 for the two .lock leaves added to paths.py, with the reason written above the number. Rebased onto main df0ea7909c.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=fa7ab943e399: rebutted

Not a defect: same class, same ruling as recorded for head afe4490 (third raise of this span). Nothing in the sandbox can mint the alias: link(2) across the bind mount is EXDEV, unlink/rename of a mount point is EBUSY, macOS emits (deny file-link ...) for every sealed leaf (sandbox.py:8594).
The only reachable shape is an alias planted OUTSIDE the sandbox by the operator's own tooling (stow, chezmoi, rsync --link-dest). That is the documented residual of the MS_RDONLY bind for EVERY leaf in _CREW_READONLY_LEAVES (sandbox.py:2343-2360, 2637-2651); config.json joins denied_commands.json, security_policy.json, computer_use.json under the rule already in force, and the warn fires for it (_CREW_PRECREATE_READONLY_FILE_LEAVES, sandbox.py:1719-1722).
On the base, config.json is writable from the sandbox by ITS OWN name with no alias needed; this PR removes that and leaves the class residual where it already stood. It makes no alias reachable that the base did not.
The proposed fix -- refuse every sandboxed spawn on an aliased config -- is the spawn-path refusal this module records as rejected (sandbox.py:2795-2799) and would break the symlinked-config layout loader.py supports. Refusal belongs at a CONSUMING seam; for agent.sandbox that seam is KiroCrewConfig.load() in the gateway, and refusing there takes the whole gateway down for the same operators.
Override reason a maintainer can paste: /ai-review override gpt 9eb401305987c27953986be499a54324f8f9441d: alias bypass is the recorded warn-not-refuse residual shared by every MS_RDONLY ceiling leaf; the PR narrows the base (unsealed file) and adds no new alias path.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: yes

  • span=964a6ea5f43f: rebutted

Advisory, fourth raise; kept as recorded. The residual is written down in docs/system-specs/modules/config.md: the torn window exists only on Linux, only for the two sealed files, only while an in-place save runs, and a torn snapshot cannot parse (brace-last), so a reader sees old, new, or a parse error -- never a hybrid.
_read_config_text re-reads once, immediately, because KiroCrewConfig.load() runs on the event loop (no-blocking-call-on-event-loop) and may not sleep. The writer's window is write + ftruncate + write(1 byte) into the page cache with no fsync inside it; a reader that lands two full read_text calls inside that window needs the writer descheduled mid-window, which the design accepts as the residual and read_config_for_update() fails closed on.
Both proposed remedies add mechanism to code this PR added (a stat-signature retry loop, or a tear-vs-corrupt classifier in load()) for an advisory edge; this span has grown across five rounds and the smaller shape is kept. A follow-up that wants a bounded retry can add it without touching the seal.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=6a96966538cb: rebutted

Advisory, same ruling as heads f9d8c28 and d4a4134: cli_commands._locked_config_write (workspace add/update/delete, crew delete) is untouched by this diff and already fails closed with the OS error when the sandbox refuses the lock file, so the seal holds and only the message wording differs.
Routing those arms through _sandboxed_config_write_hint is new cross-module wiring in a file this PR does not change, outside the frozen goal. The kirocrew-commands skill already names those commands as writes the user runs outside the sandbox.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=d8106aed7d29: accepted-and-deferred

Agreed on the premise: a rename-publish puts a fresh, unsealed inode at the name for every running sandbox, and four sibling sealed leaves still publish that way. Out of the frozen goal (the owner's settings files), as the item itself says.
Tracked in #15143 (label deferred-finding, assignee iamwhatever, Due 2026-10-13): route the four writers through the same in-place publish, or record the residual in security.md. The maintainer question from head afe4490 (span de9489da3726) is the same one; the issue is where it gets answered.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=c7c5a5398602: rebutted (kept, declared)

The live-read side effect is not a rider: it is the direct consequence of writing in place, which is the only shape that keeps the bind's inode. It is declared in the PR body and in security.md, and the same lane recorded it as fixed for span a45c49556509.
No in-sandbox read of these files is a security decision; a loosened value still applies only on the next spawn.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=1068e6800191: rebutted (kept, guidance only)

The skill note exists because this PR creates the refusal: without it the kirocrew-commands table still steers the agent into config set inside the sandbox and a bare EROFS. Same ruling as spans dd653d172816 and c66530b5eb52; guidance, no code path.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 9eb4013: alias bypass is the recorded warn-not-refuse residual shared by every MS_RDONLY ceiling leaf; the PR narrows the base (unsealed file) and adds no new alias path.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@iamwhatever marked the gpt AI finding as false positive, not applicable, or explicitly accepted for 9eb401305987c27953986be499a54324f8f9441d.

alias bypass is the recorded warn-not-refuse residual shared by every MS_RDONLY ceiling leaf; the PR narrows the base (unsealed file) and adds no new alias path.

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

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in test/test_apps_registry_coverage.py / registry_pipeline since this head went green (df0ea79 -> 003bd2a, picks up #15081 which fixes the Windows (1) symlink tests); CI re-running on 5d1ddd5.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: migration write-back defers when an event loop runs on the calling thread

  • span=9ec07ed2ded9: fixed in f77705a -- _persist_config_migration returns False without writing when asyncio.get_running_loop() succeeds on its thread.

Legitimate: load() -> _persist_config_migration -> write_config_atomically -> _write_config_in_place ran os.fsync/os.close on the loop; no-blocking-call-on-event-loop is blocking: true.
Fix: the on-loop case declines exactly like the existing held-lock deferral (info log, return False, nothing written, no .bak); the migration is retry-on-next-load by construction.
Convergence: kirocrew gateway calls KiroCrewConfig.load() before asyncio.run (cli.py:772) and every asyncio.to_thread(KiroCrewConfig.load) site is off-loop, so the write-back lands on the first of them.
Test: test_config_loader.py::test_a_load_on_the_event_loop_defers_the_migration -- under asyncio.run returns False and leaves the file byte-identical; the same call off-loop writes. Fails without the fix.
test_config_live.py::_write_settled now settles the migration on a worker thread, since a load inside an async test is on the loop.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: yes

  • span=899036fb5180: fixed

weixin_qr.py now holds config.json.lock across the whole read-modify-write: _stage_and_commit takes the sidecar, then runs _stage_weixin_config (the read) and _commit_credential_and_config (the publish) inside it; _atomic_write no longer takes the lock itself. Fixed in 67d6279.
Lock order is now config.json.lock then .env.lock; every other .env.lock holder (cli_setup.py:740, secrets/migrate.py:358, messaging.py:4822) writes only .env inside it and uses try_acquire, so no holder takes them the other way round.
Regression test test_stage_and_commit_holds_the_config_lock_across_read_and_write probes the sidecar from inside both steps; fails on the old code.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=9ec07ed2ded9: rebutted

Not a defect this diff can close without a recovery sidecar the maintainer has declined: a sidecar under the crew home is agent-writable, so a "last-good copy" becomes a second way to feed the loader a forged document.
The adjudication's "save() can make the loss permanent" leg does not hold: the only KiroCrewConfig.save() call site in the tree is cli_config.py:385, guarded by if not p.exists(), so a torn (existing) file is never overwritten; every other writer is a read-modify-write through read_config_for_update, which fails closed on the unparseable file (loader.py:1349). The torn bytes stay on disk for hand repair.
Window is the write itself (fsynced, brace-last, rollback on every catchable error); only SIGKILL/power loss inside it applies, Linux, two files. Recorded in config.md as the accepted residual; Design's WATCH names "maintainer explicitly accepts the documented residual in review" as its clear condition.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=d5b35f23d24c: rebutted

Accepted residual, recorded in config.md: Linux, two files, SIGKILL/power loss inside one fsynced write. A last-good copy would sit in the agent-writable crew home and become a second forgeable input to the loader; the maintainer declined it as disproportionate. The torn file is never overwritten (save()'s single call site is guarded by not p.exists(); RMW writers fail closed), so hand repair stays possible.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=9ae6cf50dfc8: rebutted

Accepted as spawn-warn-only, same ruling as on 9eb4013: an owner's editor rename is the owner acting outside the sandbox, and the next spawn re-seals the new inode. A mid-session notification is a new surface beyond this PR's goal (seal the two files); it belongs with the sibling read-only leaves that share the same residual, tracked in #15143.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Scope reduced at head fd19e9a. This PR is now the seal only: config.json and config.local.json join _CREW_READONLY_LEAVES (plus pre-create), with the CLI hint and spec updates. The in-place writer and everything built on it (rollback, fsync, brace-last ordering, torn-read retry, lock sealing, mtime bump, on-loop deferral, the WeChat lock scope, the overlay re-read) are removed; every writer keeps temp+rename.

Why: keeping the inode gave up every property rename provides for free and each had to be rebuilt by hand. It grew config/loader.py by ~340 lines, drew a review finding per round, and the last round's Integration failure showed it marking a healthy config.json corrupt at boot under concurrent loads. Wrong shape for the problem.

What that leaves open: on Linux a per-file bind is detached when the host next renames onto that name, so the seal holds from spawn until the owner's next save, then that sandbox sees the file unsealed until it respawns. This is the same residual every other sealed leaf already carries and is recorded in security.md. Closing it for all six leaves at once (one read-only directory instead of per-file binds) is #15143. Compared with main, where both files are writable for the whole session, this PR narrows the window; it does not close it on Linux.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=fa7ab943e399: rebutted — unreachable as described. The delegated (kiro-cli) sandbox's writable set is the workspace subtree. Any workspace that reaches <crew-home>/config.json also contains its sibling cloud.json, and the delegated overlap guard already refuses that lexically (sandbox.py _DELEGATED_OVERLAP_LEAF_REASONS branch, ~L10148); darwin's voice guard refuses it a second time. Adding the two leaves to that table violates its set-equality assert with the no-follow lists (~L1654), and no pre-existing READONLY leaf (denied_commands.json, security_policy.json, computer_use.json) is on that guard either, so this PR adds no new delegated path. Opus adjudication reached the same conclusion. Security-class, so this stays for a human override.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=aec828f504b1: fixed in 39aefdc (docs only). (a) security.md residual (2) now states the real split: a RESOLVING second name warns and continues; a DANGLING link refuses the spawn with SandboxCeilingUnsealable via _refuse_if_dangling_symlink, the same as every pre-created leaf. No code change: refusing a dangling name is the existing precreate contract, and skip-and-warn for these two leaves alone would leave a sandbox with no seal on the name an agent would then create. (b) The hot-reload bullet's residual clause now names the Linux rename-detach window alongside the outside-the-sandbox write, instead of claiming the residual is outside-only. The PR body carries the same two corrections.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=b6aa4c8f5577: fixed in 39aefdc (docs only). The residual note in sandbox.py, security.md and the PR body now says the seal holds until the NEXT GATEWAY save, not the operator's, and names the trigger population: boot migrations, member-identity publication and memory-store provisioning (memory_stores.py via update_config_locked), the embedding-model stamp — some reachable indirectly from an in-sandbox tool call. sandbox: sealed ceiling leaves publish by rename, which unseals the Linux file bind until respawn (6 leaves incl. config.json) #15143 is updated to record the same and is framed as the completion of this change (directory bind for all six sealed leaves), not a generic follow-up.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=aac405b471c4: accepted as stated — the CLI hint rides along with the seal. It is declared in the body ("kirocrew config prints a one-line hint when the write is refused"), exists only to name the refusal the seal itself creates (bare EPERM otherwise), and carries no premise of its own. Kept.

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

config.json and config.local.json join the read-only crew leaves (sandbox.py ~597, with matching child-readable and pre-create entries), so an agent can still read its config but can no longer rewrite it. The leaves were never read-gated, so this narrows write access only; read scope is unchanged. The one intended casualty, kirocrew config set/unset/defaults run from the agent shell, is the declared breaking change and now exits 1 with a pointer to the dashboard (cli_config.py ~120-130, ~529-535). The operator's own terminal and the dashboard keep write access.

In-sandbox writers: migration write-back in KiroCrewConfig.load() is best-effort and logs "Config write-back failed" (config/loader.py ~4414). A mutate that returns None returns from update_config_locked before writing and only touches the .lock sidecar. The MCP servers write no config directly (learn_add, cron_add and set_project go through the gateway). The pre-created config.local.json is {}, which every overlay reader treats as a no-op.

Mutations (baseline 669 passed): dropping the pair from _CREW_READONLY_LEAVES reddens test_config_leaf_is_read_only_in_every_mode and test_every_non_hidden_leaf_is_classified_for_a_foreign_child; from the pre-create list reddens test_config_leaf_is_precreated_so_the_linux_bind_has_a_file; making the hint always None reddens 11 reports_the_seal_* tests; checking only filename and not filename2 reddens publishing_rename. test_sandbox_governance_mask.py needed no edit because its pin is structural and goes red when the child-readable entry is dropped. security.md records both residuals (the Linux per-file bind detach tracked in #15143, and a second-name alias).

Bot dispositions: the earlier in-place-write spans no longer apply, since the final diff keeps temp+rename. The hint-wording spans are addressed. The rebuttal on agent create/workspace create showing a raw traceback holds, since those fail closed. The GPT alias/hardlink rebuttal holds (EXDEV across the bind, Seatbelt denies file-link, and it's documented).

Non-blocking follow-ups:

  1. builtin_skills/kirocrew-commands/SKILL.md ~352-356 still lists config set/defaults with no note that they fail inside the sandbox. An earlier disposition says a note was added, but it isn't in the final diff.
  2. Comments still say "config.json is agent-writable" in apps/routes.py (4551, 4690), config/sections.py:174, computer_use/types.py:351, autonudge_service/judge_tick.py:55 and apps/registry_pipeline/sources.py:354.
  3. In-sandbox knowledge search can reach _verify_custom_model, which writes the custom embedding-model stamp. Under the seal it degrades to custom:unavailable until the gateway records the stamp. That fails closed, but it's worth moving to the gateway.
  4. The body's "Ran locally" list names test_weixin_qr.py, which the final diff no longer touches.

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