Repository navigation
fix(cloud): stage the launch source tarball in a launcher-owned directory - #13640
Conversation
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Unmeasured AWS CLI floor for Watch
[DESIGN-REVIEWED] a970a3e |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The ancestor walk ( Not justified as shipped
What this change shipsInventory (8 items) — 6 justifiedIntent: make
[FIRST-PRINCIPLES-REVIEWED] a970a3e |
a08642f to
f8649ed
Compare
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5 Review — ✅ no blocking findingsReviewed Review detailsNothing blocks: the staging relocation, the descriptor-only write path and the build-time checksum pin all hold under falsification; three advisory issues remain. FINDING — src/kiro_crew/cloud/source.py:352 — every cleanup for the relocated staging temps ( FINDING — src/kiro_crew/cloud/source.py:414 — the single refusal message appends FINDING — docs/system-specs/modules/cloud.md:620 — the "Secret hygiene in source shipping" section is the owning spec for [OPUS-REVIEWED] a970a3e Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
f8649ed to
6f3402b
Compare
6f3402b to
a20b4fd
Compare
a20b4fd to
98b14ae
Compare
98b14ae to
5e55500
Compare
|
@bolichen97 the symlinked- Head:
Two details worth flagging, both agreeing with your reading: Resolving widened coverage rather than narrowing it. A world-writable parent of a relocated home is refused now, which the lexical walk could not reach at all. There is a pin for exactly that, and another accepting a sticky world-writable ancestor this account owns, so the check does not reject an ordinary host. The error message you called unactionable now names the path and the command that fixes it, since the data home is the operator's own setting. This head also carries a separate fix for a finding on the staging write path: every staged tarball is written through the descriptor its minter holds, so a name rebound between the mint and the write cannot redirect tarball bytes onto a governance file.
|
d04f248 to
8b99ae7
Compare
8b99ae7 to
fb87189
Compare
…tory The tarball is handed to `s3api put-object` as `--body <path>`, so the AWS CLI re-opens it by name after the builder has closed it. All three builders left it in the stdlib temp root, whose location tempfile takes from TMPDIR/TEMP/TMP with no guarantee it is owner-only or sticky -- a staging root another account can write makes the closed file swappable before the CLI opens it, and the launch would ship a tree that was never packaged. Resolve the staging directory from the data home instead (0700, re-checked after mkdir) and pass it as `dir=` at every builder. The body still passes by name; no descriptor seam and no new shared helper. A failed fallback build now removes its own half-written tarball, which matters because the data home is not cleared by a reboot. A link at or above the data home is followed, not refused. That is where this module's trust anchor sits -- the same split atomic_write._link_trust_anchor draws and workflows.md records for the data home -- so a symlinked $HOME, a dotfile-managed ~/.kiro and a data home moved onto another disk all keep working. They have to: the DEFAULT data home is lexical (`Path.home() / ".kiro" / "crew"`), only a KIROCREW_HOME override is resolved, so on a host whose $HOME is a link the guard fired on the path every user gets and aborted `cloud launch` on grounds they could not satisfy. Following it gives up no coverage, because the hazard was never the link: it is an ancestor of the REAL directory being swappable, and _first_replaceable already walks the RESOLVED chain. The ownership and mode tests therefore land on the directories that actually hold the tarball rather than on a lexical chain that may not -- a world-writable parent of a relocated home is invisible to a lexical walk and refused by this one. Below the anchor nothing is followed: a link at the `cloud-src-staging` leaf this module creates is still refused before the mkdir and again after it. Refs #13370 test/link_screen_sites.py records cloud/source.py::_staging_dir. That gate is new on main since this branch was cut, and _staging_dir is a screen-then-resolve site it had no way to know about: it screens the leaf with is_link_or_junction and then mkdirs and resolves the same name. It refuses every link it screens rather than vetting one and continuing, so per the gate's own split it takes a baseline entry and not a HELD_SITES hold. Generated with test/gen_link_screen_sites.py, never hand-edited. The ancestor mode test refused S_IWOTH only, so a GROUP-writable ancestor passed it. That left the residual argument for following a link at or above the data home wrong as stated: it claimed a parent another account can write is refused, and a shared-group parent is writable by another account and was not. _group_shared_with_another_account settles the membership instead of the bit -- a group holding this account alone is private and stays accepted, which is the user-private-group host the bit alone would have refused -- and it fails closed, so a group whose privacy cannot be proven counts as shared. Both halves of membership are needed: gr_mem lists supplementary members only, so a group shared by PRIMARY membership presents an empty gr_mem and would read as private. Sticky still exempts, and the lookup is skipped when it does. The leaf never had this hole: _lock_to_owner already refuses any group or other bit. The ancestor walk is no longer what stops a substitution, because it cannot be: every check it can run lands BEFORE the AWS CLI re-opens `--body` by name, which is the wrong side of the window. Three review rounds bore that out, each naming a class the previous walk missed -- world-writable, then shared-group-writable, then symlink-side components, POSIX ACLs and Windows DACLs -- and the enumeration has no natural end. `upload_source` now pins the BYTES instead: `_write_tar_gz` is the single place a final tarball is produced, it digests each byte on its way to the file, and that digest goes to S3 as `--checksum-sha256`. S3 compares it against what it actually received, so a swapped or rewritten tarball is a refused upload rather than a stored one. The check therefore sits downstream of the CLI's open, the one place a pre-flight inspection cannot reach, and it covers an in-place rewrite of the staged file that no ancestor test can see. The digest is taken at the write, never from a read-back: hashing the finished file would only shrink the window from "our close until the CLI's open" to "our close until our own re-open", and a window one layer down is the same hole. It is deliberately NOT paired with `--checksum-algorithm`, which asks the CLI to compute the digest itself and would hash whatever it re-opened, certifying a substitution instead of catching it. The uid, mode and membership tests stay as a pre-flight that names an actionable `chmod` instead of surfacing as an opaque S3 digest error, but they are defence in depth now, not the gate.
… its own descriptor Two holes on the staging path, both found in review. A shared checksum accumulator spans two tarball attempts. _use_git_archive SWALLOWS a mid-write _refilter_archive failure so it can fall through to the tarfile fallback, and by then the gzip header has already gone through _HashingWriter. One shared accumulator folds those discarded bytes into the fallback's checksum, so the pin describes bytes the named file does not contain and S3 refuses a good tarball. Each attempt now owns its accumulator. Resolving a staged temp's name a second time is a window. The staging leaf sits under the data home, which a same-uid process can write, so between a mint that closes its handle and a write that reopens the name, that name can be rebound -- to a link at a governance file such as security_policy.json, or a hard link to it, which a check on the final component does not catch. The tarball would land on that target while the launch reported success, and an absent or unparseable ceiling resolves to the permissive default. _write_tar_gz takes the open handle its caller holds instead of a path, and _use_git_archive streams git archive through that handle as stdout rather than handing the child an -o pathname. mkstemp creates the temp with O_CREAT|O_EXCL, so the handle names an inode nothing can substitute. _discard_staged closes before unlinking, the order Windows requires. Tests: a link planted at the staged name takes no tarball bytes, and the writer resolves that name zero times. test/test_cloud_source.py is 83 passed.
bolichen97
left a comment
There was a problem hiding this comment.
Changes-requested (5316588407) is addressed on a970a3e: reproduced locally with HOME -> symlink, ~/.kiro -> link, ~/.kiro/crew -> link, and combined -- _staging_dir() succeeds under the real config_dir(); only the cloud-src-staging leaf is refused when it is a link. test/test_cloud_source.py 84 passed, link-screen gate 17 passed. Two Low nits for a follow-up, not blocking: (1) _staging_dir refusal text always says chmod go-w even for the foreign-owner / unreadable reasons (source.py ~405-415) -- suggest 'set KIROCREW_HOME under your home' there; (2) _use_git_archive success path: if _discard_staged(out) raises after _refilter_archive returned, the filtered tarball leaks (source.py ~559-563) -- try/finally. Approving.
Problem / Motivation
Goal: A
kirocrew cloud launchuploads the source tree the launcher actually packaged, or it fails — it never silently ships bytes someone else substituted.kirocrew cloud launchpackages the local checkout into a tarball and uploads itwith
aws s3api put-object --body <path>. Passing a path means the AWS CLIre-opens the file by name after the builder has written and closed it, so
there is a window in which the bytes on disk are not the bytes that were
packaged. Nothing downstream compares them.
All three tarball builders in
src/kiro_crew/cloud/source.pyleft the file in thestdlib temp root:
with no
dir=.tempfiletakes that root from the environment (TMPDIR/TEMP/TMP), so where the tarball lands is decided by the launcher'senvironment, and nothing guarantees the directory is owner-only or sticky. A
staging root another account can write makes the closed file swappable in that
window.
Every
s3api put-objectcall site, with its verdictsrc/kiro_crew/cloud/source.py,upload_source--body str(tarball)src/kiro_crew/apps/builtins/aws_control/backend/storage.py,put_file--body local_pathsrc/kiro_crew/publish/personal_drive.py,_put--body pathsrc/kiro_crew/apps/builtins/aws_control/backend/storage.py,create_folder--bodyat allwebsite/electron/scripts/sign-windows.js--body filePath.github/workflows/publish-cli.yml,publish-installer.yml,publish-linux.yml,publish-windows.yml,sign-and-notarize.yml--body <file>Why it matters
The launch tarball is the entire source tree the cloud instance runs. The box
downloads it with its own IAM role and executes what is inside. If the file the
CLI uploads is not the file the launcher built, the operator gets a running
KiroCrew instance whose code they never packaged, and nothing in the launch
output says so: the upload succeeds, the owner pin passes, the stack comes up.
The exposure needs no unusual privilege: only write access to whatever directory
the launcher's temp root points at.
Not a goal
(
put_file,personal_drive.py::_put) are named in the table above anddeferred onto the
run_awsdescriptor seam that open PR fix(aws-control): bind the backup archive's bytes to one descriptor from build to upload (#13259) #13272 is alreadybuilding. This PR does not add a second descriptor parameter.
cases it can name from ownership and mode. It does not enumerate POSIX ACL
entries, Windows DACLs, mount options or immutable flags, and it is no longer
the check that stops substitution — see the GPT disposition on ancestor
substitution rights.
cloud-src-stagingleafshould be masked from in-sandbox agents the way
aws-control-stagingistouches
security/paths.pyandsandbox.pyand needs a ruling on whether asandboxed agent may launch at all. Left open and stated under Review
dispositions.
boto3has zero matches ininstall_requires(itis the optional
voice-awsextra), so passing a file object instead of a pathwould be a new core dependency riding a security fix.
run_awschokepoint. Every AWS call in the productgoes through it, carrying the agent-session guard, the sandbox wrapper and the
cgroup ceiling. This diff stays inside
cloud/source.py.What changed (symptom -> root cause -> change)
The symptom is "the CLI may upload bytes we did not package". Walking it back:
our
close()and itsopen().That gives two independent changes, and they are not alternatives — the first
narrows who can reach the file, the second makes a swap detectable no matter who
reached it.
1. The bytes are pinned, and the pin is verified downstream of the CLI's open
Every check this process can run sits before the CLI opens the body, so any
of them can be defeated by acting after it returns. The one verifier that cannot
be is S3 itself:
S3 hashes what it receives and refuses the object when the digest does not match.
So a substituted or rewritten tarball ends the launch with a refused upload
instead of shipping.
For that to be sound the digest must describe the bytes we produced, not
bytes we read back. A digest computed by re-opening the finished file would only
move the window — from "our close until the CLI's open" to "our close until our
own re-open". So
_write_tar_gzis now the single place a final tarball's bytesare written, and it digests them on the way through:
fhis the handle its caller already holds on the temp it minted, not a freshopenof that temp's pathname. The descriptor is the security boundary, not thename. The staging leaf sits under the data home, which a same-uid process can
write, so between a mint that closes its handle and a write that resolves the
name again, the name can be rebound — to a link at a governance file such as
security_policy.json, or a hard link to it, which a check on the finalcomponent does not catch. The whole source tarball would then land on that
target while the launch still reported success, and an absent or unparseable
ceiling resolves to the permissive default.
mkstempcreates the temp withO_CREAT|O_EXCL, so the handle names an inode nothing can substitute.git archivewrites through the same handle as its stdout rather than to-o <path>, because a pathname handed to a child is a name that child opensitself.
All three builders (
_use_git_archive,_refilter_archive,_tar_fallback) gothrough it and take the accumulator as a keyword argument, so a future writer
that bypasses it is a test failure rather than a silent hole.
build_source_tarballreturns aStagedSourceNamedTuple carrying the path andthe Base64 digest together, because the two must not be derived independently.
Two details are deliberate. The digest is Base64, not hex — that is what
--checksum-sha256takes. And it is passed without--checksum-algorithm,which asks the CLI to compute a checksum itself and would defeat the point of
supplying one.
2. The staging location narrows who can reach the file at all
_staging_dir()resolves acloud-src-stagingleaf directly under thedata home and checks the whole chain ROOT-FIRST, so each check runs only after
everything above it is known good.
config_dir()is the trustanchor
atomic_write._link_trust_anchoralready uses: at or above it a link isthe operator's layout -- a symlinked
$HOME, a data home on another disk -- andbelow it every directory is one Kiro Crew created itself. Resolving first is
also what puts the real chain in scope, which a lexical walk cannot see:
stat'ing a relocated home follows the link and reads the target's own sound
0o700, so a world-writable directory holding that target never appears.mkdir(exist_ok=True), becauseexist_ok=Truehappily accepts a pre-existinglink. The leaf is the one node this module creates, so a link there is never
the operator's layout.
_first_replaceable()refuses when a directory in scope is unsafe, and its modeis only one of the two ways it can be. Ownership first: a directory's owner
can replace what is inside it whatever the mode says, so a directory owned by
neither this process nor root is unsafe at
0755exactly as much as at0777.Root is trusted because a root that wanted to substitute the tarball does not
need a directory to do it. Then the write bits, with the sticky exemption
they carry: under the sticky bit an entry may be renamed by the entry's own
owner, by the directory's owner, or by root -- so sticky makes a directory
safe only once its owner is already trusted, which is why the two tests are
ordered and not alternatives.
definition. GROUP-writable asks one more question first, because the bit cannot
answer it: the same
0o775means a foreign writer on a shared group and nobodyat all on a user-private one.
_group_shared_with_another_account()settles whichfrom the MEMBERSHIP, and both halves are needed --
gr_memlists supplementarymembers only, so a group shared by PRIMARY membership presents an empty
gr_memand would read as private. It FAILS CLOSED: a group whose privacy cannot be
proven, including on a host whose passwd database will not enumerate, counts as
shared. Sticky exempts as it does for others-writable, and the lookup is skipped
when it does.
_chain_the_launcher_owns()says which directories are in scope. The data homeand everything up to and including the operator's own home, when the home sits
inside it. A directory above that belongs to the administrator, or in a
container to a uid not mapped into this namespace -- on a sandboxed host even
/reads as an unmapped owner (measured:
/,/home,/local,/local/homealluid 65534). If one of those is hostile then every program the account runs isalready substituted and a check on one tarball buys nothing, while refusing there
would reject an ordinary container. A data home the operator moved outside
their own account gets the whole chain instead, because that premise does not
cover it: a relocated home is exactly the shared-host case where an ancestor can
belong to a local peer.
Only the leaf, which this module owns, is locked down.
_lock_to_owner()locks the leaf and refuses unless it actually is owner-only.Two steps, because neither stands alone:
platform_compat.restrict_dir_to_owneris the owner-only lockdown for adirectory on both platforms and is fail-loud by contract, so a mount that
rejects the change stops the launch instead of warning and staging anyway; and
applying a mode is not the same as having it, since a filesystem with a fixed
permission mask (FAT, exFAT, a CIFS mount with a permissive
dir_mode) acceptsthe call, keeps its own mode and reports success. So the mode is read back.
Windows mode bits and uids carry no ACL information, so there the lockdown's own
success is the guarantee and every mode and ownership read stands down.
_use_git_archiveand_tar_fallbackdo so on an INTERRUPT as well, which isnot a fallback case and so propagates straight past the fallback path's own
cleanup. This is part of the same change, not a spare fix: the data home is not
cleared by a reboot the way a tmpfs temp root is, so a leak there is permanent,
and every cancelled launch would otherwise leave a copy of the whole checkout.
What the walk is for now. It is no longer the gate — the checksum is. It
stays because it fails the launch early and actionably: an operator whose data
home sits under a directory a peer can write gets a message naming
chmod go-w <dir>, rather than an opaque S3 digest mismatch after the uploadattempt. Defence in depth, with the diagnosis in the cheap layer.
Backwards compatibility
Breaking, narrowly, and only for one host shape.
config_dir()'smkdir(parents=True)leaves~/.kiroat0o775under umask 002. On a host withumask 002 and a shared primary group, that directory is now refused where it
previously passed.
That refusal is ACTIONABLE, which is what separates it from the one this PR
removes: the ownership test has already established the node belongs to this
account or root, so the message names
chmod go-w <dir>and one command clearsit. A user-private group on the same host is still accepted and needs nothing —
that is the case the earlier
0o022form got wrong, and the membership lookup iswhat tells the two apart.
Writer sweep:
_staging_diris new in this PR and has no callers outside it.build_source_tarball's return type changed fromPathto theStagedSourceNamedTuple; every caller is in this repository and in this diff, and the sibling
suites that exercise them (
test_cloud_cli.py,test_cloud_ec2.py,test_launch_engine_ref.py) pass unchanged.--checksum-sha256needs a reasonably modern AWS CLI. This package pins no CLIversion, though
--expected-bucket-owneron the same call already assumes one, sothe floor moves little if at all. I did not measure the exact minimum.
Tests
TestTarballStagingDirectoryintest/test_cloud_source.py. Each staging casepins the data home and the process temp root at two different directories, so
a builder honouring the temp root and one resolving the data home cannot both
pass.
The checksum pins, which are the load-bearing ones:
computed independently
implementation produces and S3 would reject it
handle the caller already holds — and reading the file back is never attempted.
This is the only way the no-window property can be pinned: a read-back yields
the same digest on a quiet host, so no value comparison can tell a sound
implementation from an unsound one — only the absent name resolution can
write takes no tarball bytes: the file it points at is byte-identical
afterwards. Mutating the writer to resolve the name again fails this pin, so it
discriminates rather than passing vacuously
cannot bypass it silently
The staging pins:
left completely empty (the git-archive case captures both names it creates,
since
_refilter_archivestages a second file)0o700, and a pre-existing leaf left0o755isre-restricted
does not take also refuses (the fixed-permission-mask case)
at an ancestor above the home are followed -- the default
~/.kiro/crewislexical, so refusing those would refuse any host whose
$HOMEis itself asymlink
AWSError, not a bareFileExistsError:mkdir(exist_ok=True)forgives an existing directory andnothing else, and
cli_cloudcatches onlyAWSError,ValidationErrorandCloudActionDenied, so an unguardedmkdirreaches the operator as a tracebacknaming no remedy. Restoring the unguarded call fails this pin, so it
discriminates rather than passing vacuously
cannot reach at all: that is the pin proving resolving widened coverage rather
than narrowing it
/tmpshape), so the check does not reject every ordinary host
not exempt one -- that case makes exactly one node foreign, because a blanket
euid change would let a sticky-first short-circuit pass on a later node's refusal
refused when it is shared; sticky exempts one without asking the group at
all; privacy fails closed on a host that will not enumerate; and both
halves of the membership lookup are load-bearing, pinned separately because on
a shared-group host both fire at once and either alone would look sufficient
0o755home is accepted, which is what a plainmkdirleaves under umask 022_chain_the_launcher_ownsdirectly: a home insidethe account starts the walk at that home and excludes the filesystem root, a home
relocated outside it starts at the root
still there after the refusal
git archivethat is interrupted, eachleave no tarball behind
The link cases use
conftest.make_dir_link, notsymlink_to: a directorysymlink needs
SeCreateSymbolicLinkPrivilege, which an unelevated Windows shelllacks, so a symlink would skip on exactly the host whose junction branch of
is_link_or_junctionthe leaf refusal depends on.The sibling files run because
build_source_tarball's return type changed:test_cloud_cli.py,test_cloud_ec2.py,test_launch_engine_ref.py. None broke.The third file in this diff is one generated line.
test/test_link_screen_hold_pin.pylanded on main after this branch was cut, and it enumerates functions that screen a
path for links and then resolve or read the same name.
_staging_diris such afunction and is new here, so that gate had no way to know it:
test_every_site_is_declaredreddened on both python and Windows namingcloud/source.py::_staging_dir. Per the gate's own split, a site that refuses everylink it screens takes a baseline entry and not a
HELD_SITEShold --_staging_dirraises on a linked leaf rather than vetting one and continuing -- so the remedy is a
declaration. Recorded with
test/gen_link_screen_sites.py, never hand-edited, whichis that file's own requirement.
Mutation-verified, restoring the pre-fix form at every site that maintains
the state, each from a pristine copy outside the repository and each restored to a
byte-identical sha256. Each mutation was confirmed to redden its own pin by
node id, not merely to produce a non-zero exit:
_write_tar_gztest_the_digest_never_re_reads_the_staged_filefails--checksum-sha256from the uploadtest_upload_sourcefails--checksum-algorithmalongside ittest_upload_sourcefailstest_digest_is_base64_not_hexfailstest_every_tarball_writer_goes_through_the_hashing_writerfailsdir=at all 3 builder siteschmod_safeformbase.resolve()->base)0o077) instead of write bits (0o022)S_IWOTHonly)gr_mem) half of the membership check_use_git_archive's interrupt cleanup arm.copy())StagedSourceTwo harness defects are worth naming, because both produced a green-looking
result that proved nothing. The sticky-ordering mutation did not redden at
first: a blanket euid change made every node foreign and a later node refused
anyway, so the pin was rewritten to make the sticky node the only problem. And
the checksum harness's first run scored six of six CAUGHT while naming no pin —
-qsuppresses the failure summary and ANSI codes broke the parse — so it hadonly established that something failed. Re-run with
-rf --color=no.Two cases also had to stop reading the operator's real
~. They asserted againstan unisolated
Path.home(), which passes on a host whose chain happens to hold aforeign-uid directory and fails on a runner whose
/and/homeare bothroot-owned, so each now pins
Path.home()undertmp_pathand CONSTRUCTS theforeign-owned ancestor rather than probing for one. That is a defect in the tests,
not a behaviour change: the scope bound they cover is unchanged, and the
full-chain mutation still reddens both.
Also green on the changed files:
black --check,isort --check-only,flake8,mypy, the comment-history gate, andsemgrep scan --config p/python --config p/security-auditat 0 findings (the deliberate loose-mode test fixtures carrynosemgrepwith a stated reason; removing one takes the scan back to 1 blockingfinding, which is how the suppressions were checked to be doing only that).
Manual verification
End-to-end on a host that is the affected layout (
/home/u -> /local/home/u),which is the layout
bolichen97's finding named:The reported digest was then recomputed independently with
openssl dgst -sha256 -binary <file> | base64and is identical.One correction to method, since an earlier run of this repro was cited in a PR
comment.
kiro_crewis installed editable against a different checkout onthis host, so a script with no
sys.pathpin imported that tree rather than thisbranch, and its verdict described whichever branch that tree was on. The script
now pins
sys.pathand refuses to run against any other tree; the output above isfrom the re-run, and the conclusion is unchanged. The test evidence was never
affected —
setup.cfgsetspythonpath = src, so pytest loads this worktree.Any other suggestions on the work
The other two by-name product sites are deferred on purpose, not overlooked.
put_fileandpersonal_drive.py::_putboth need a descriptor parameter on thesame
engine.run_awsthat open PR #13272 is extending withstdin_fd. Doingthem now would mean a second descriptor parameter and a second verified-open
helper on a function that is already growing one, so both halves should follow on
#13272's seam once it merges. That is sequencing, not a dead end. Either of them
could take the checksum pin from this PR instead, which needs no seam at all.
A refused upload currently reads as an opaque CLI error. When S3 rejects the
digest, what the operator sees is whatever
aws s3apiprints, not a sentencenaming substitution as the cause. Mapping that into a launch-level message is
worth doing and is deliberately not in this diff.
The issue's own premise is corrected on the issue. #13370 states that
put_filealready avoids the by-name re-resolution and that two other sites donot. On current
mainput_filepasses--bodyby name as well, and nodescriptor seam (
body_fd,stdin_fd, a verified-open helper) exists anywhereunder
src/kiro_crew/. The full six-site table above is posted as a comment onthe issue so the record is right.
sign-windows.jsand thepublish-*/sign-and-notarizeworkflows are leftalone. They run on the release signing host and on CI runners, not in shipped
product code, and the signing path compares a sha256 either side of the upload,
which fails it closed.
Pattern harvest
Rule candidate: semgrep
Pattern: a file staged with
tempfile.NamedTemporaryFile(...)ortempfile.mkstemp(...)with nodir=, whose path is then handed to a subprocessas an argument.
That shape is the whole defect class here, and it is mechanically detectable: the
staging root comes from the environment, and passing the path means an external
process re-opens the name after the writer closed it. The rule would want a
matching allowance for a path that never leaves the process. All three builders in
this file matched it, and the two deferred product sites in the table above match
it too, so the rule has live subjects the moment it lands.
Review dispositions
GPT 5.6, BLOCKING (fenced), a non-directory staging entry crashes the CLI --
TAKEN.
_staging_dirrefused a link atcloud-src-stagingbut let a plainregular file fall through to
staging.mkdir(exist_ok=True), which forgives anexisting directory and nothing else.
cli_cloudcatchesAWSError,ValidationErrorandCloudActionDeniedonly, so theFileExistsErrorreachedthe operator as a traceback naming no remedy. The
mkdiris now guarded andraises the module's own staging refusal, which names the path and the fix. This is
the other half of the leaf refusal added in the same function, not a new site.
Fixed rather than overridden. The adjudication is right that the required state is
out-of-band and the outcome is a loud fail-closed crash with nothing staged or
uploaded, so the fence's own class does not fit -- but the fix is four lines and
one pin, and an override would have left a real traceback on a supported path
behind a correct-looking clearance.
test_a_regular_file_at_the_staging_leaf_is_refused_as_an_awserrorasserts theexception type, which is the whole contract; restoring the unguarded
mkdirfails it with the exact
FileExistsErrorthe finding named.GPT 5.6, BLOCKING, failed archive attempts contaminate the fallback checksum --
TAKEN, and it was a real defect introduced by this PR's own checksum work.
build_source_tarballminted ONEhashlib.sha256()and handed that sameaccumulator to each tarball attempt in turn.
_use_git_archivedeliberatelySWALLOWS a mid-write
_refilter_archivefailure so it can fall through to thetarfile fallback, and by then the gzip header has already passed through
_HashingWriter. The fallback's checksum therefore covered bytes that were not inthe file it named, and S3 would have refused a perfectly good tarball. Each
attempt now owns its accumulator, and no digest is read except for the attempt
that filled it.
This finding was machine-fenced as security-class with a pre-drafted override
rationale. It was fixed rather than overridden, and the fence is not the reason:
the mechanism is reachable on a supported path, and the adjudication that
accompanied it put the real fix cost at "small". An override would have left a
live defect behind a correct-looking clearance. The adjudication is also right on
the narrower point that this never weakened the substitution pin -- a digest
carrying extra bytes can only make S3 refuse, never match a substituted file --
so the harm was a failed launch, not a shipped one. That is what made it a
correctness bug rather than a hole, and it is fixed on those terms.
Two pins cover it, because one alone would not.
test_each_tarball_attempt_gets_its_own_digeststates the invariant as objectidentity, so it holds however a future producer fails.
test_a_failed_archive_attempt_does_not_contaminate_the_fallback_digestruns thereal
_use_git_archiveand the real_refilter_archive, stubbing onlygit archiveitself and stubbing it to succeed with a corrupt archive -- whichis what makes the re-filter raise after it has begun writing. That the mid-write
failure genuinely dirties the digest is not asserted by inspection: the mutation
restoring the shared accumulator reddens that pin, which it could only do if bytes
had reached the digest.
GPT 5.6, BLOCKING, ancestor validation misses real substitution rights
(symlink-side components, POSIX ACL writers, Windows
FILE_DELETE_CHILD) --ANSWERED, by removing the ancestor walk from the load-bearing path rather than
extending it. The finding is right that the walk does not see those classes, and
right that it could be extended to see two of them on POSIX. It was not extended,
because the enumeration has no natural end: three accepted rounds on this one
function each closed a class and each drew the next one (
0o022refused asupported host;
S_IWOTHalone left shared groups; membership left ACLs andDACLs). The question the walk was trying to answer -- can anyone swap this
directory before the upload reads it -- is now answered downstream instead, by
--checksum-sha256, which S3 verifies after the CLI's open and which no ancestorright can get in front of. Every class the finding names, including the Windows
one, produces a refused upload rather than a substituted one.
A file-descriptor hold was investigated first and rejected on measurement, not
preference: no filesystem path names an inherited Windows HANDLE, so
--bodycannot reference one, and Windows is a supported launcher platform. A POSIX-only
fd hold would have retired two of this finding's three classes and left the
Windows one, which is the class it names explicitly. An fd is also strictly
weaker against an in-place rewrite -- it pins the inode, and the rewrite changes
that inode's contents -- where the checksum refuses it.
GPT 5.6, BLOCKING, group-writable ancestors still permit tarball substitution --
TAKEN, and it was a real hole in the residual argument. Narrowing the mode test to
S_IWOTHleft the case a shared GROUP can write, and the reasoning offered forfollowing a link at or above the data home leaned on exactly that gap: it said a
parent another account can write is refused by the ownership and mode tests, and a
shared-group parent is writable by another account and was not refused. Both
reviewers were right and the mode bit cannot serve both of them, because
0o775means a foreign writer on a shared group and nobody at all on a private one. The
membership settles it instead, which is what this finding asked for ("unless their
group is proven private") and what the walk's own docstring had already named as the
only thing that could. Measured obtainable rather than assumed: on a corporate host
pwd.getpwall()enumerated and reported 23 accounts sharing the primary gid, andthe helper fails closed where it does not enumerate.
That round also found a mislabelled pin, unprompted:
test_a_group_writable_ancestor_is_acceptedclaimed to represent "a group holdingonly the operator" while inheriting
tmp_path's gid, which on this host is sharedby 23 accounts. It asserted the permissive behaviour unconditionally and its
verdict depended on the test host. It now states the membership explicitly and is
host-independent.
bolichen97, CHANGES REQUESTED, the guard refuses a default data home reachedthrough a symlinked
$HOME-- TAKEN, and the cause was mine. Verified live on ahost that is the affected layout (
/home/u -> /local/home/u): pre-fixbuild_source_tarball()returnedREFUSED -- an ancestor of the data home is a link, and the same launch succeeds onorigin/main, so this PR introduced therefusal rather than exposing an older one. The two blanket refusals were removed
and the walk now resolves at
config_dir(). They bought nothing:_chain_the_launcher_ownsalready opened withresolved = base.resolve(), so theownership and mode tests were never reading the lexical chain -- the refusals
propped up only that function's own docstring sentence, which is corrected in the
same commit.
GPT 5.6, BLOCKING, Windows stands the ancestor walk down entirely -- NOT taken
as asked, and now moot. The finding is right about the mechanism:
_first_replaceablereturnsNoneon Windows. Its remedy is to enumerate everyancestor's owner plus its substitution-capable ACL rights across SIDs and group
memberships, and
platform_compathas no reader for a directory's owner or DACLat all, so that is a new Windows-only mechanism -- which the finding's own
adjudication calls "genuinely large". This repository's own blocking
Cross-Platform Portabilitygate also asks for precisely the platform stand-downthe finding wants removed. The checksum pin closes the gap the finding is about
on both platforms without it.
Opus 5, BLOCKING, two new cases assert against the operator's real
Path.home()-- FIXED. Correct and reproduced._pin_home_and_temp_rootpinsthe data home under
tmp_pathwhilePath.home()stays the runner's real home,so
_chain_the_launcher_ownstakes its whole-chain branch andchain[0]is thefilesystem root; the sibling case finds no foreign-uid ancestor at all on a runner
whose
/and/homeare both root-owned. Both now pinPath.home()undertmp_pathand construct the foreign ancestor.Opus 5,
if mode & 0o022also refuses a GROUP-writable ancestor -- FIXED, thenSUPERSEDED. This one refused a supported host:
config_dir()'smkdir(parents=True)leaves~/.kiroat0o775under umask 002 and only~/.kiro/crewis tightened, so everycloud launchon a user-private-group hostaborted with "is writable by other accounts" for a group containing only the
operator. The mode test was narrowed to
S_IWOTHonly, which was too wide; thegroup bit is a refusal again, decided on membership rather than on the bit, so the
host this finding protected is still accepted. The residual trade is stated under
Backwards compatibility rather than left implicit.
Opus 5,
_use_git_archivecleans up only(OSError, SubprocessError, TarError)-- FIXED. An interrupt during the 120s
git archivepropagated past thefallback path's own cleanup and left a full source tarball in the data home, which
no reboot clears, so repeated cancelled launches accumulated copies of the whole
checkout. It now carries the same
BaseExceptionarm_tar_fallbackhas, with itsown pin.
Opus 5, the
cloud-src-stagingleaf is visible while the identical-shapeaws-control-stagingis hidden -- DEFERRED, the same open question as Design'sbelow. Opus names the exact constants (
sandbox._CREW_HIDDEN_LEAVES,_CREW_PRECREATE_HIDDEN_DIR_LEAVES,security.paths._CREW_SECRET_LEAVES) and acloser precedent than the one recorded below, and marks it advisory because those
files are untouched here. Two independent reviewers now name the same residual. It
is the single disposition this PR does not settle, for the reason under Design's
entry.
GPT 5.6, BLOCKING, foreign-owned ancestors remain replaceable -- FIXED, and the
finding caught a genuine gap in this PR's own stated premise. The sticky
exemption was justified here as "only an entry's own owner may rename it", which is
incomplete: under the sticky bit a directory's own owner may rename entries
inside it too, so a foreign-owned
1777ancestor reached the same swap. And aforeign-owned
0755ancestor never met an ownership test at all. Both are nowclosed by the ownership predicate, ordered before the write-bit test.
One measured limit on the finding's literal remedy, disclosed rather than
skipped. It asks to "reject ancestors owned by a non-root UID other than the
launcher". Applied to the full chain that refuses every containerised host: inside
this repository's own agent sandbox,
/,/home,/localand/local/homeareall owned by
uid 65534, the unmapped owner, so a literal full-chain ownershiptest refuses before reaching anything the operator could fix. The scope bound above
is the reconciliation -- the ownership test applies to the chain the launcher is
answerable for, and a data home relocated outside the account still gets the whole
chain, which is the shared-host case the finding describes.
GPT 5.6, BLOCKING, Windows skips the link/junction invariant (earlier head) --
FIXED as named. The three link cases use
conftest.make_dir_link, which createsa junction on Windows and needs no privilege. This also mattered beyond the skip:
is_link_or_junctionshort-circuits onos.path.islink, so its junction branchwas exercised on no host at all.
GPT 5.6, BLOCKING, a replaceable data-home parent (earlier head) -- FIXED.
Nothing above the data home was mode- or link-checked, so a home under a shared
writable parent could be replaced wholesale after
_staging_dir()returned. Closedby the chain walk over the resolved chain, and now also by the checksum pin. Its
suggested remedy was "upload through a pinned descriptor instead of reopening the
staged pathname"; that is the fd route measured and rejected above, and the
checksum reaches the same goal on both platforms.
GPT 5.6, BLOCKING,
_staging_dirpermission failure leaves staging swappable(earlier head) -- FIXED.
chmod_safeswallows everyOSErrorwith a warning, soa mount that refused the mode change left the leaf at whatever the umask gave
mkdirwhile the build carried on. It is nowrestrict_dir_to_owner(fail-loud)plus a mode read-back.
First Principles, item 3, the
IS_POSIXbranch respellsrestrict_dir_to_owner-- SUBTRACTION TAKEN. The branch is gone and theexisting helper is called unbranched, which also removed the POSIX fail-soft /
Windows fail-loud asymmetry the review named.
Design,
_lock_to_owner(base, ...)silently chmods the operator's data home --SUGGESTION TAKEN. The home is verified and never rewritten, and a pin asserts the
mode the launch found is still there afterwards. Narrowing the mode test to
others-writable came out of the same review: the swap needs the write bit, so a
0o755home -- what a plainmkdirleaves under umask 022 -- is accepted ratherthan refused.
Design, the new
cloud-src-stagingleaf has no stated sandbox disposition --DISPOSITION OPEN, and the review's premise checks out. The leaf is VISIBLE: it
is not in
security.sensitive_home_dirs(), so an in-sandbox agent can write it,resting on the tool gate alone. The temp root it replaces is masked per session
(
sandbox.py:360, masked "as a WHOLE so one session tree cannot open another's"),so this trade is real rather than theoretical -- it closes the cross-account swap
and opens an in-sandbox one for a launcher packaging a checkout the agent cannot
reach. The owner-only lock and the chain rule are filesystem-permission
boundaries and do not substitute for a mask against a same-UID agent.
The repository already has the exact shape for the remedy:
_MD_NOTEBOOK_STAGING_LEAFis a staging directory masked as a whole directory,with its owning writer getting it back through
extra_visible_dirsbecause themask alone would break that app. Applying it here means touching
security/paths.py,sandbox.pyand the leaf pin test, and it needs a decisionon whether a sandboxed agent may run
kirocrew cloud launchat all -- if it may,the mask needs the same
extra_visible_dirsroute. That is wider than this PR'sscope, so it is called out here rather than decided quietly inside it.
CI notes
Backend Tests (Windows) (2)failed on the first head and is base-owned, notin this diff. The failing case is
test/test_subagent_reap_attribution.py::test_a_user_stop_is_reported_as_a_stop_not_a_runtime_deathand its assertion is an asyncio teardown warning ("Task was destroyed but it is
pending!"). This branch does not touch that file, and the test arrived in commit
4d4e184d11, which is already an ancestor of this branch's base. CI evaluates themerge ref, so the branch inherits it. It has not recurred on a later head.
Backend Tests (Windows) (3)carriedtest_history_consolidation_retry.py::TestRotationReleasesTheBudgetForNewContent::test_unstamped_accounting_keeps_the_capon one head and went green on the next with no change touching history
consolidation. Its failure is
PermissionError: [WinError 5]insideatomic_write.replace_with_retry, whose retry is bypassed on a running eventloop; #14212 is open on that exact mechanism.
Several review lanes also failed on
API rate limit exceeded for installation,which is the GitHub App budget rather than anything in the diff. Those runs
published no marker naming the head they ran on.
Related Issues
Refs #13370