Repository navigation
fix(sel): anchor the chain lock on the log directory - #13308
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Fix [DESIGN-REVIEWED] e6def7d |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS On Windows the pin degrades to the by-name junction probe, so the mid-acquire What this change shipsInventory (8 items) — 8 justifiedIntent: FIX — stop the SEL hash chain forking across processes and stop a degraded install destroying its own signing key.
[FIRST-PRINCIPLES-REVIEWED] e6def7d |
GPT 5.6 Review — ✅ human override acceptedHuman judgment by @chenmingwei23 overrides the GPT 5.6 finding for [GPT-OVERRIDE] e6def7d This comment is updated in place on each push. The model was not re-run because an authorized human decision supersedes it. False positive or not applicable? A repository writer can comment: |
Security Scope Review -- 🟡 CONCERNSWhich legitimate operations does Verdict basis: the reviewer's own judgement; no confirmed regression. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: CONCERNS TIGHTENING: The sensitive-path read+write floor ( ADJUDICATED: 16 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix rows cover UNADJUDICATED: Two parts of this tightening are OS-sandbox mask decisions the shell-command classifier settles nothing for. (1) [SCOPE-REVIEWED] 71e3c1e |
Opus 5 Review — ✅ no blocking findingsReviewed Review detailsTwo advisory findings: the new ambiguity guard cannot tell a VANISHED legacy key from a short one, and the newly written prose misstates when the legacy-key fallback applies. FINDING — src/kiro_crew/sel.py:1503 — FINDING — src/kiro_crew/sel.py:3667 — [OPUS-REVIEWED] e6def7d Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
71e3c1e to
b3ee04b
Compare
5bfcaaf to
b66d7dd
Compare
The cross-process chain lock was taken on a path derived from the resolved HMAC key: the trust-dir sidecar when the key had migrated, the legacy key file itself when it had not. That location is per-process state, so during a migration two writers on one log directory locked DIFFERENT inodes and appended unserialized, forking the hash chain the audit log's tamper-evidence rests on. Worse, the legacy-key leg opened that path with O_CREAT, so a writer still pinned to it left a 0-byte file at the key path after a sibling relocated the real key; the migration block then promoted that file over the usable key and every later boot failed init with "too short (0 bytes; require >= 32)", losing the only copy of the signing key. The sidecar's name is now a constant under the trust subdirectory, read from the log directory alone and never from the key. When that directory cannot be created at all, the lock falls back to the legacy key file only when it ALREADY exists, and opens it without O_CREAT, so no acquire can leave the 0-byte artifact behind. The fallback keys off the directory's permissions, a filesystem fact every writer on the install reads alike, where the old one keyed off each process's own migration timing. The hold registry stays keyed on the constant sidecar path, so two instances join one hold rather than taking two real flocks. A migration guard also refuses to promote a legacy file that cannot load as a key over a destination holding a usable one. Anchoring on the directory exposed a second hole in that directory's own trustworthiness. A `trust` symlink planted before the upgrade whose removal fails leaves `_load_or_create_hmac_key` on the legacy key precisely so the linked destination is never used, but `_chain_lock_target` still resolved the lock under `trust/`. `Path.mkdir(exist_ok=True)` cannot see that: its EEXIST check is `is_dir()`, which follows the link and reports the target as a usable directory, so the FileExistsError was swallowed and `(trust/security_events.lock, True)` returned. `is_link_or_junction` and `O_NOFOLLOW` cover only the final component, so the sidecar was then created inside storage the audited agent controls, where it can be unlinked and recreated between two writers' acquires -- two flocks on different inodes and a permanent HMAC chain fork -- and `mode=0o700` is ignored for an existing directory, voiding the protection the code claimed. The lock directory is now refused when it is itself a link, and the refusal routes into the same fallback: the deny-list-protected legacy key when one exists, otherwise the failure. That screen covers the `trust` leaf and nothing above it, which is both the whole reachable threat and the parity `_load_or_create_hmac_key` screens this same directory by. `trust` is the one component below the log directory the audited agent can write. Every ancestor is the operator's own layout -- a home directory that is itself a symlink, a crew dir moved to another volume -- which the agent cannot plant, so refusing on one buys no protection and costs the whole log: the refusal routes into the legacy-key fallback, and an install with no legacy key gets every best-effort audit dropped and every critical operation denied while nothing is wrong. The link-screen gate states that rule directly, in `test_an_ordinary_link_layout_is_not_broken_by_the_hold`: what a screen owes is that it and the use reach the same object, not that no reparse point exists on the host. Also update the owning spec, which described the superseded contract (lock target derived from the key's migration state at init) and stated the legacy-wins rule without this branch's short-legacy-file exception. The new guard makes ``_chain_lock_target`` a screen-then-use site under the link-screen gate: it asks whether the lock directory is a link and then hands the same name to ``mkdir``. It is recorded in the generated baseline (``test/link_screen_sites.py``) via ``test/gen_link_screen_sites.py`` and deliberately NOT added to ``HELD_SITES``, because it refuses every link rather than vetting a target and continuing, so it never traverses one and a held chain would buy it nothing. That is the same treatment its siblings on this directory already have, ``_load_or_create_hmac_key`` and ``_chain_lock``.
b66d7dd to
a329d95
Compare
UX Review (Fable 5) — ⏭️ skippedRevision |
882a524 to
fff8573
Compare
Three security-class findings on the chain-lock change, all reachable by the audited agent because `trust` and `sel_hmac.key` are sandbox read-write leaves (sandbox.py's _CREW_SANDBOX_VISIBLE_LEAVES). The lock directory was screened by name and then created/opened through that same name, so the agent could replace it in the window: both writers' screens pass truthfully while their opens land in different directories, giving them flocks on different inodes -- the forked chain the lock exists to prevent. `_pin_lock_dir` now pins the directory by descriptor (O_DIRECTORY | O_NOFOLLOW | O_NONBLOCK, a descriptor fstat directory check, and a name-to-descriptor identity check), and the sidecar is opened relative to that descriptor, so the directory screened is the directory the sidecar is opened inside. That pin introduced the third finding, and it is the same class one level in: which file gets locked must be decided by a condition no actor can flip BETWEEN two writers' acquires, and a pin refusal is the opposite of that. It fires exactly when the agent replaces `trust` mid-acquire, so it can be true for one writer and false for the next -- and routing it into the legacy-key fallback therefore handed those two writers different inodes on an install whose trust dir is perfectly healthy. The pin now fails the acquire instead, and is taken outside the fallback so it cannot select a target at all. The two screens that still may are filesystem properties every writer reads alike. The fallback's own gate was the same mistake in its admitting condition: it keyed on a file EXISTING at the legacy key path, which the agent can create on a healthy install, and the lock path never reads those bytes so any content sufficed. It now keys on `_hmac_key_file` -- where this process actually resolved its key, settled once at init -- which is the install-wide fact the fallback was always argued from, and which a planted file cannot move. The legacy FILE stays agent-writable, so on an install signing there the agent can still replace it between two acquires; that is left undefended deliberately, because an agent that can rewrite the key signing the chain can forge any MAC on it directly, which is strictly more than forking it. The short-legacy exception retained the destination key on a size test, and length is not trust: truncating the legacy key below the minimum and planting a long-enough destination turned a fail-closed length check into adoption of an attacker-known key. That shape now resolves neither way -- nothing is adopted, nothing is overwritten, both files survive, and init fails closed naming both paths and the remedy. Authenticating against the log was considered and rejected as the worst available anchor: it is a read-write leaf for the same agent, so a forged newest row would turn the check into adoption of a key the attacker knows. Tests pin both new behaviours, and a mutation harness restoring each pre-fix form reddens the matching test (M1 the existence gate, M2 the pin routed into the fallback), so neither pin is a tautology.
fff8573 to
e6def7d
Compare
|
/ai-review override gpt e6def7d: Applied the reachability test; overriding on limb 1, actor already holds a strictly stronger capability. AGENTS.md:117 records sel_hmac.key as VISIBLE with no OS fence, and a spawned shell reaches it via open() outside the tool gate, so this agent reads the audit key and forges any MAC outright, which subsumes forking the chain. The same VISIBLE grant supplies the trust swap. Fail-closed would deny every critical audit on a writable-log, non-writable-dir install. |
Human judgment recorded@chenmingwei23 marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
…15634) Backport of #13308, #14302, #14860, #14961, #15070 to release/0.8.0, cherry-picked in main's merge order. * fix(sel): anchor the chain lock on the log directory (#13308) (cherry picked from commit 998b045) * fix(watchdog): decide the loop-stall exit on the monotonic clock (#14302) (cherry picked from commit 1d37ab1) * fix(ops-mission-control): strict read in ledger resolve_conflict (#14860) (cherry picked from commit b8ea16b) * fix(env): skip a mise candidate whose probe is denied instead of aborting boot (#14961) (cherry picked from commit e054c95) * fix(lessons): retire only a finding on a contradiction verdict (#15070) (cherry picked from commit dd5e840)
Problem / Motivation
Goal: Keep the SEL audit log's hash chain unforkable across processes, and stop a degraded install from silently destroying the key that signs every record it holds.
The SEL audit log's cross-process chain lock was taken on a path derived from the
resolved HMAC key file, not from the log. Those two are not the same thing,
and the key's location differs between processes on one log directory:
trust/sel_hmac.key, so itlocked
<sel dir>/trust/security_events.lock;trustlink) keeps signing from the legacy<sel dir>/sel_hmac.key, and_chain_lock_path()then returned that key file itself as the lock.Two such processes hold locks on different inodes while appending to the same
log. The serialization that keeps two writers from chaining off one
prev_hashis gone, and the hash chain forks.
The legacy-fallback branch carried a second, worse consequence. Because the lock
was opened with
O_CREAT, a process pinned to the legacy path creates a 0-bytesel_hmac.keybeside the log. On the next boot the migration block promotedthat 0-byte file over the real key at the destination, destroying the only copy
of the key that signed every existing record. The minimum-length check then
failed init on every later boot, so the loss was unrecoverable rather than
merely wrong.
Measured on
1fb8c9eeecbefore the fix, read-only:sel_hmac.keysecurity_events.lockFalsesel_hmac.keyexists, 0 bytesAnchoring the lock on the log directory then depends on that directory being
trustworthy, and one case was not. An unremovable planted
trustsymlink ishandled on the key path by design --
_load_or_create_hmac_keydeliberatelystays on the legacy key so the linked destination is never used -- but the lock
path still resolved the sidecar under
trust/.Path.mkdir(mode=0o700, parents=True, exist_ok=True)cannot detect that: CPython'sexist_okcheck isself.is_dir(), which callsstat()and follows the link, sothe target reports as a usable directory and the
FileExistsErroris swallowed.The existing
is_link_or_junctioncheck andO_NOFOLLOWboth cover only thefinal component, so the sidecar was created inside storage the audited agent
controls, where it can be unlinked and recreated between two writers' acquires:
two flocks on two inodes, and the same permanent chain fork.
mode=0o700isignored for a directory that already exists, so the protection the code claimed in
its own docstring was void.
Reproduced on the pre-fix branch: after init the link target is empty, and the
first append creates
security_events.lockinside it --_chain_lock_target()returning(trust/security_events.lock, True).Why it matters
The SEL log is the tamper-evidence record of what an agent was allowed to do. Its
value rests entirely on the hash chain being unforked: a forked chain cannot
distinguish a concurrent append from a tampered one, so
verify_integrity()stops being a meaningful signal about the record it guards.
The key loss is the sharper harm. It is silent when it happens and terminal
afterwards: the gateway raises on SEL init on every subsequent start, and the
records already written can never be verified again because the key that signed
them is gone. There is no recovery short of restoring a backup of the key.
The linked-directory case is narrower but strictly worse in kind, because it puts
the lock inside storage the audited party controls. An agent that can unlink
and recreate that sidecar between two acquires can fork the chain on demand
rather than only under an unlucky race.
All of these need only an ordinary degraded install to trigger: a read-only
config directory, a mixed-binary window during an upgrade, or a link planted
before the upgrade that the migration cannot remove.
Not a goal
lives under
trust/, and its migration keeps the failure modes that made theold lock path vary. This PR removes the coupling that let that non-uniformity
fork the chain; it does not make key resolution itself uniform. That is a
separate change with a separate risk profile.
is in scope here. Other consumers of
trust/are untouched.test_a_contended_write_waits_instead_of_failing. That Windowswall-clock race (
assert 0.29599999999982174 >= 0.3) surfaced on an earlierhead of this PR. Its failure direction cannot be produced by this diff, it
lives in a file this change surface never imports, and it matches closed
precedent CI flake: test_an_unchanged_process_still_gets_its_rate divides by a rewind plus real elapsed time (Windows) #13761. Folding a clock fix for it into a SEL PR would put an
unrelated test in this diff.
What changed (motivation -> approach -> change)
Symptom: two writers append to one log unserialized; a 0-byte key file
appears beside the log and later eats the real key; and on a linked-
trustinstall the lock sidecar is created inside agent-controlled storage.
Immediate cause:
_chain_lock_path()returnedself._hmac_key_filewheneverthe key had not been relocated, so the lock path was a function of migration
state. And
_chain_lock_target()created the sidecar's directory withmkdir(exist_ok=True), whose EEXIST test follows a link.Root cause: the lock's identity was computed from a value resolved per
process. Two processes serializing on one file must agree on that file by
construction, and the key's location is precisely the quantity that differs
between processes on one log directory. Anchoring on the log directory fixes
that, and makes the directory's own trustworthiness load-bearing -- which the
link check did not yet cover, because it tested only the final component.
The fix, part one. The sidecar's path is now a constant under the trust
subdirectory, read from the log directory alone.
_chain_lock_path()returns<sel dir>/trust/security_events.lockand reads nothing about the key, so thevalue is identical in every process whatever the key's state: no candidate key on
the append path, and no in-process transition for the
_CHAIN_HOLDSregistry tostraddle. The sidecar stays where it already was for every healthy install, so
the file the lock is taken on does not move on upgrade.
The fix, part two. The lock directory is refused when it is a link, and
the refusal is raised into the same fallback an uncreatable directory already
took. That restores the guarantee
_chain_lock_path's docstring makes: theaudited agent can neither unlink the sidecar mid-hold nor hold it out from under
the writers.
The screen stops at the
trustleaf, which is both the whole reachable threatand the parity
_load_or_create_hmac_keyscreens this same directory by(
is_link_or_junction(trust_dir)).trustis the one componentbelow the log directory the audited agent can write. Every ancestor is the
operator's own layout -- a home directory that is itself a symlink, a crew dir
moved to another volume -- which the agent cannot plant, so refusing on one buys
no protection and costs the whole log: the refusal routes into the legacy-key
fallback, and an install with no legacy key gets every best-effort audit dropped
and every critical operation denied while nothing is wrong. The link-screen gate
states that rule directly in
test_an_ordinary_link_layout_is_not_broken_by_the_hold: what a screen owes isthat it and the use reach the same object, not that no reparse point exists on
the host.
That guard declares itself to the link-screen gate. Refusing a linked lock
directory means screening a path and then handing the same name to
mkdir, whichis the screen-then-use shape
test/test_link_screen_hold_pin.pyenumerates acrossthe tree, so the guard creates a site that gate did not know. It is declared in the
generated baseline
test/link_screen_sites.py, written bytest/gen_link_screen_sites.pyrather than by hand, and deliberately not addedto
HELD_SITES(test/test_link_screen_hold_pin.py:186, which holds a singlenon-SEL entry): the guard raises rather than vetting a target and continuing, so it
never traverses a link and holding the directory open across the check would buy it
nothing. Its siblings on this same directory,
_load_or_create_hmac_keyand_chain_lock, are already baselined unheld for that reason.What happens when
trust/cannot be used at all. The old fallback existedfor a real reason: an install that cannot create that directory must keep
auditing rather than fail every acquire and thereby drop every best-effort event
and deny every critical action. That reason survives, so the fallback survives,
but it is re-keyed, and the rule it is keyed by is the one every branch of the
resolution now obeys: only a condition no actor can flip between two writers'
acquires may select a lock target. A target that differs across two concurrent
writers is two flocks on two inodes, which is the fork the lock exists to
prevent.
Two conditions qualify, both properties of the filesystem that every writer on
the install reads alike: whether
trust/is creatable, and whether it is areal directory rather than a link. Either refusal falls back to the legacy
key file, opened without
O_CREAT-- which is what removes the 0-byteartifact at the root, since nothing on the lock path can now bring that file into
being.
What admits that fallback is
_hmac_key_file-- where this process actuallyresolved its HMAC key, settled once at init -- not the legacy file merely
existing. The existence test cannot be the gate, because
sel_hmac.keyis asandbox read-write leaf just as
trustis: the audited agent can drop a filethere on a perfectly healthy install, and the lock path never reads its bytes, so
any content would do. Gating on existence therefore let that agent arm the
fallback at will. Keying on where the process signs means a planted file buys
nothing, and it is the install-wide fact the fallback was always argued from: a
process signing at the legacy location is one whose
trust/could not be createdor migrated out of.
A pin refusal fails the acquire and never selects another target. This is
the one refusal the fallback must not reach:
_pin_lock_dirraises preciselywhen it catches
trustbeing replaced mid-acquire, so it is per-acquire andagent-triggered and can be true for one writer and false for the next. It is
taken outside the fallback so it cannot select a target at all.
Where nothing qualifies, the acquire fails, because inventing a lock elsewhere is
worse than failing: an unserialized append forks the chain.
The hold registry stays keyed on the constant sidecar path rather than on the
file finally locked. A key that tracked the fallback would hand two instances in
one process different keys, and two real flocks on two inodes is the fork this
lock exists to prevent; a stable key makes them join one hold instead.
Third fix, for the upgrade window: a legacy file too short to be a key no
longer replaces a destination that holds a usable one. The unconditional
"legacy key wins" rule rests on the two files carrying the same bytes, and a file
that cannot load as a key carries none. The guard is deliberately narrow: only
that one pairing is skipped, so a genuine legacy key still wins over a
pre-existing destination file, and a short legacy file with no usable
destination still reaches the length check exactly as before. This covers the
mixed-binary window where an old process can still leave the artifact behind.
The owning spec is updated in the same change, because both the superseded lock
contract (target derived from the key's migration state at init) and the
unqualified legacy-wins rule were still documented as current.
The fallback is the part most worth a reviewer's attention, because it is the one
place where two files can still be locked on one install. Its remaining exposure
is stated rather than argued away: the legacy file is itself agent-writable,
so on an install signing there the agent can replace it between two acquires and
reach the same fork. That is left undefended deliberately -- an agent that can
rewrite the key signing the chain can forge any MAC on it directly, which is
strictly more than forking it, so a lock-side screen would buy nothing the key's
own protection has not already lost. If a reviewer disagrees with that
reading, that is the sentence to push on.
Backwards compatibility
Compatible. The sidecar's path is unchanged for every install that already has a
real
trust/directory, so the file the lock is taken on does not move onupgrade, and no caller signature or on-disk format changes.
The one behaviour that narrows is deliberate and is the fix: an install whose
trust/is a link previously acquired a lock inside that link and nowrefuses it. That install does not lose its lock -- the refusal
routes into the pre-existing fallback, and it is exactly the install where
_load_or_create_hmac_keyalso met the link and fell back, so the legacy key itis already signing from is present and becomes the lock. The acquire fails only
when there is no legacy key either, which is the behaviour an uncreatable
trust/already had before this PR.
Nothing narrows for an install whose
trust/is a real directory reached througha symlinked ancestor -- a home directory that is itself a symlink is a normal
layout on shared build hosts, and it keeps the real sidecar.
test_symlinked_data_home_still_takes_the_real_chain_lockpins that.Writer sweep on
origin/main@19b157da12c2:_chain_lockis module-privatewith exactly two callers, both in
src/kiro_crew/sel.py-- the append path(
_flush_batch) and the prune path (prune). Both already handle a refusedacquire, which
_flush_batchturns into a rollback plus warning, or propagatesfor a critical audit under the audit-or-deny contract. No caller outside the
module reaches it, and no test outside
test/test_sel.pyasserts the old path.Tests
Six tests in the diff were measured to fail before the fix and pass after.
The first four were measured by copying this branch's test file into a worktree
checked out at the parent commit and running it against that commit's own source;
the last two by neutralising the guard in place, with the source restored from a
copy held outside the repository and verified by
sha256.test_lock_path_does_not_vary_with_the_keys_migration_state. On base one logdirectory yields
trust/security_events.lockfor a migrated process andsel_hmac.keyfor a pinned one; it fails with "the chain lock path divergesbetween two processes on one log dir".
test_short_legacy_file_does_not_destroy_a_usable_migrated_key. On base the0-byte legacy file is promoted over the real key and init then raises
SEL HMAC key ... is too short (0 bytes; require >= 32). It also asserts thepre-existing chain still verifies and that a later boot still initializes.
test_the_fallback_never_creates_a_file_at_the_legacy_key_path. Pins theno-
O_CREATguarantee directly: with the sidecar's directory unusable and nolegacy key present, the acquire must fail and leave nothing at the key path.
test_appends_survive_when_the_trust_dir_is_uncreatablegains an assertionthat the resolved target is the existing legacy key with creation refused, so
the audit-continuity behaviour and the new flag are pinned together.
test_unremovable_planted_link_never_hosts_the_chain_lockpins the linkeddirectory. The pre-existing sibling pin covered init only, and asserted the
link target stays empty at that point; the lock is taken on the first
append, which is why a clean target there proved nothing. The new pin appends
and then asserts
_chain_lock_target(). With the guard neutralised it failsat
test/test_sel.py:2543--assert (PosixPath('.../trust/security_events.lock'), True) == (PosixPath('.../sel_hmac.key'), False)-- and with the guard in place it passes.
test_symlinked_data_home_still_takes_the_real_chain_lockpins the otherdirection, and is what narrowed part two's screen to the
trustleaf. It buildsthe operator layout -- a real
trust/under a data home reached through asymlink, no planted link anywhere -- and asserts the real sidecar is still used
and the append lands. Against the first version of the guard, which also walked
ancestors, it failed with
OSError: SEL chain-lock directory .../link/crew/sel/trust is or resolves through a link,i.e. the whole log refused on a healthy install; against the leaf-only guard it
passes. Disabling the guard entirely passes this pin and fails the planted-link
one, so the two pins bound the screen from both sides.
Two further tests pin the target-selection rule, added after review found the
pin refusal and the existence gate both able to switch targets. Each was proved
discriminating by a mutation harness (
.kc-13308-mutations.sh) that restores thepre-fix form, requires an explicit pytest
N passed/N failedcount, andrestores the source from a copy held outside the repository verified by
sha256-- never
git checkout, which would revert toHEADand delete the fix mid-run.Unmutated control: 2 passed. Both mutations CAUGHT (1 failed each).
test_a_planted_legacy_key_does_not_arm_the_fallback_on_a_healthy_install.This process signs from
trust/; a file is planted at the legacy key path and arefusal is then triggered. The acquire must fail closed, and the planted bytes
must be neither locked nor rewritten. Mutation M1 restores the
legacy_key.exists()gate and the test fails.test_a_mid_acquire_directory_swap_fails_closed_instead_of_switching_targets.Set up in the most permissive state the fallback has -- a legacy key present
and this process signing from it -- so neither condition can be what admits
the refusal. The static screens pass, so only
_pin_lock_dircan refuse, andit must raise rather than return the legacy key. Mutation M2 routes the pin
refusal into the fallback and the test fails.
Also re-run on the amended head:
-k "TestCrossProcessSafety or TestHmacKeyTrustDirMigration"-> 51 passed;mypy src/kiro_crew/sel.py->Success: no issues found in 1 source file;ruff checkclean;docs-lint.shpasses with its own
--testself-check first, so the gate is proved to stillfire before its green is believed.
One further failure was the link-screen gate rather than a test in this diff.
test_every_site_is_declaredscans the tree, and part two's guard made it red onboth
Backend Tests (3.12, 2)andBackend Tests (Windows) (2)until the new sitewas declared. Removing only that one baseline entry reproduces the CI failure
exactly, which is how the entry was confirmed to be the fix rather than a
suppression.
Runs, each read from its own exit status,
-n 0against a scratchKIROCREW_HOME, on this PR's base19b157da12c2:test/test_sel.py+test/test_link_screen_hold_pin.pytest/test_sel.pytest/test_link_screen_hold_pin.py-k "TestCrossProcessSafety or TestHmacKeyTrustDirMigration"Because
test/test_link_screen_hold_pin.pyimportstest/source_corpus.py, andmain changed that module's file enumeration, the baseline was re-derived rather
than trusted: running
test/gen_link_screen_sites.pyon the merged tree leavesthe committed file byte-identical (150 declared sites), so this PR's entry is
exactly what the gate's own condition yields.
Gates, each read from its own exit status, run as CI invokes them on the rebased
tree:
isort --check-only src/kiro_crew test conftest.py xdist_budget.py0,flake8on the same paths 0,mypy src/kiro_crew/0 (1735 files), the baselinedscripts/check_black_formatting.py0 (4 changed files in scope),scripts/check_subprocess_encoding.pyself-test and gate 0,scripts/check_brand_name.py0, andscripts/docs_lint.py0.Manual verification
The linked-directory leak was reproduced by hand on the pre-fix tree before any
code was written, because the two review findings that named it had to be
confirmed rather than taken on trust. With a
trustlink planted so its removalfails, init leaves the key on the legacy path and the link target empty; the
first append then creates
security_events.lockinside the link target, and_chain_lock_target()returns(trust/security_events.lock, True). That is theexact tuple the fix's new pin now asserts against, so the manual reproduction and
the automated pin agree on the same observation.
Related Issues
Closes #7077
Pattern harvest
Rule candidate: grep / semgrep
Pattern: a cross-process lock path derived from a separately resolved sibling
rather than from the resource it serializes.
The defect was not the fallback itself, it was that the lock's identity was
computed from
self._hmac_key_file, a value resolved per process that varieswith migration state. A lock whose path depends on any value that can differ
between two writers of the same resource is forkable by definition, and the fork
is silent: both writers succeed, and only later verification sees it. When a
degraded-mode fallback is genuinely needed, key it off a property of the shared
filesystem, which every writer reads alike, not off per-process state.
A second, narrower candidate from the same commit: opening a key or secret file
with
O_CREATfor a purpose other than reading or writing that secret. Here thelock's
O_CREAT | O_RDWRopen was pointed at the HMAC key path, whichmanufactured a 0-byte key file that the next boot's migration then promoted over
the real key. A file that holds a secret should only ever be created by the code
that owns the secret.
A third:
Path.mkdir(exist_ok=True)as a link defence. Its EEXIST test isis_dir(), which follows symlinks, so a planted link to a directory satisfies itsilently and the
modeargument is ignored for a path that already exists. Amkdirwhose purpose is to establish a trusted directory needs an explicitlink check.
And a fourth, which this PR got wrong first: that explicit check must span
exactly the components the untrusted party can plant, and stop there. Screening
the whole path instead reads as strictly safer against the refusal direction
alone, while refusing the operator's own layout -- a symlinked home, a data dir
moved to another volume -- which no attacker controls. The cost is not a narrower
feature but the subsystem: this screen's refusal path drops every best-effort
audit and denies every critical operation, so an ancestor walk turns a supported
layout into a silently unauditable install. The bound to reach for is the sibling
screen on the same directory, not the widest probe available.
Checklist
fix(sel): ...)docs/system-specs/modules/sel.md)