Skip to content

fix(aws-control): restore the version this install recorded when a key is overwritten - #12565

Merged
bolichen97 merged 1 commit into
mainfrom
fix/aws-control-version-restore-12391
Sep 22, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/aws-control-version-restore-12391

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

What is the problem?

A backup drive can be shared by several installs pointed at the same account.
When another writer overwrites a key this install recorded, the archive this
install uploaded stays on the drive as a noncurrent version.

Restore only ever read the CURRENT version of the key. So it fetched the other
writer's bytes, failed them against the body fingerprint this install recorded,
and refused -- with this install's own archive sitting on the same drive, intact
and unreachable, because no code path could name a version. The recorded version
id was already persisted; nothing read it.

Why this issue matters to the user

The operator cannot get their own backup back. The refusal is correct about the
bytes it saw and wrong about what is available.

Their only escape makes it worse: passing the override hands them the OTHER
install's archive, labelled unverified, which is not the file they asked for.

How our fix solves it

Symptom: restoring an own key refuses. Immediately above it: the bytes handed to
the fingerprint came from the current object. Root cause: the read had no way to
name a version, so the recorded id was dead data.

  • storage.get_file takes an optional version. Every existing caller is
    unchanged, and the parameter is the only new capability.
  • backup._recover_recorded_version makes ONE further read, pinned to the
    version the record names, and only on the path that was about to refuse. It
    accepts only when the same body fingerprint is re-taken over the bytes that
    actually arrive.
  • Every other outcome returns the existing refusal unchanged -- absent version,
    delete marker, unreadable, mismatched, and a staged copy that cannot be hashed.
    Reading the bytes back is part of fetching them, so the fingerprint read sits
    inside the same guard as the transfer: an error there refuses and unlinks the
    staged file instead of escaping the helper as a 500. The recovery can only find
    bytes that pass; it can never accept bytes that failed.
  • The extra read is authorized again immediately before it is made, by
    _authorize_recovery_read: the same four questions _authorize_upload asks of
    the paid upload, in the same order. The live caller identity must still name the
    requested account, the app must still be enabled, S3 consent must still hold for
    this profile and region, and the recorded grant must name THIS account. The
    network round-trip runs first and the cheap local decisions last, so no window
    sits between a check and the read it guards. The stored grant is read ONCE and
    its profile, region and account all checked against that one snapshot: grant
    reads are unlocked while writes take the consent lock, so checking profile and
    region against one read and the account against a second would let a re-grant
    landing between them satisfy each half from a different record, turning a refusal
    into an allow. A profile repointed during the first download therefore cannot
    reach AWS under a consent the owner never gave for this account.
    A refusal means the recovery does not run, leaving exactly the refusal the caller
    already had -- the two gates differ only in that the upload raises and this one
    declines.
  • Under foreign_ok the recovery never runs. That override means "I accept this
    may not be my machine's", so there is no refusal to rescue, and reaching past
    the current object would hand back different bytes than the caller asked for,
    labelled a proven self archive instead of the unverified one they accepted.
  • The version id is validated before it reaches the CLI: a length ceiling, no
    whitespace, printable ASCII, and a leading - refused as its own rule. That
    last one is the security rule: the id lands as a bare argv element, where the
    AWS CLI reads a leading dash as another option and a planted --profile would
    silently repoint the call.
  • The pinned read reports s3:GetObjectVersion, not s3:GetObject. S3 authorizes
    a version-pinned GetObject against a different action, and engine._checked
    renders the action name as its AccessDenied remediation hint -- so reporting
    the unversioned one would tell a denied operator to add a permission they
    already hold. get_file reports whichever action matches the request it made.

What tests we did

40 new tests, 23 in test/test_aws_control_backup.py and 17 in
test/test_aws_control_storage.py.

Scoped local runs with an explicit -n0, all passing: backup 181, and 554 across
storage, retention, unchanged and routes together.

Every guard was mutation-verified -- the guard broken by hand, the reddened set
recorded, the marker reverted -- and the sets are disjoint, which is what
separates real assertions from a harness that would pass either way:

Guard broken What reddens
skip the pinned second read the recovery tests
skip the fingerprint recheck the mismatch refusal and the no-residue test
restore the narrow version-id class the real-S3-id tests
restore the anchored match only the trailing-newline test
remove the foreign_ok gate only the two override tests
re-introduce a readability refusal only the malformed-archive test
report one action for both read shapes only the versioned-action test
move the fingerprint read outside the guard only the unhashable-copy test
skip the pre-read consent check only the consent-withdrawal test
skip the live-identity comparison only the repointed-profile test
skip the grant-account comparison only the grant-mismatch test
read the grant a second time for the account only the single-read test

Gates clean on the rebased tree: black, flake8, isort, mypy, docs lint, and the
comment-history gate scoped with a base ref (without one it exits 0 vacuously).

Any other suggestions on the work

Four things are disclosed rather than folded in.

A malformed own archive is handed back. The recovery accepts a
fingerprint-matching archive that does not open, symmetric with the
current-version read, which has always done so. A readability check existed here
and was removed on review: bytes matching the recorded fingerprint ARE the bytes
this install uploaded, so provenance is settled and whether they open is a
usability question the product answers "hand it back" everywhere else. The check
also cost two full decompressions of a possibly multi-gigabyte archive to turn
the operator's own file back into the refusal this PR exists to remove. A test
pins the accepting behaviour, so the check cannot return quietly.

The dashboard's overwritten warning disappears for the recoverable case.
Both existing sentences are driven by the refusal this PR removes -- a self
row reaches the confirm strip only after the backend refuses, and the refusal
sentence renders on the error alone. Filed as #12644 with the whole path a fix
needs. A recovered reply flag was shipped here and removed again: with no
reader it was decoration, and adding the reader means one new catalog key in
every locale, which is its own change rather than a rider on this one. The
backend still logs the event.

The ORIGIN_UNVERIFIED message wording is left alone. It says there is "no
record of uploading it", which is already inaccurate for the overwrite case on
base. The refusal had to be preserved exactly, so correcting the sentence
belongs to a change that owns it.

Retention still declines a now-recoverable key. Untouched on purpose: it
retains more and never less, and counting a recoverable-but-noncurrent copy
toward keep is a decision about what may be DELETED.

Pattern harvest

Rule candidate: semgrep
Pattern: re.match() on a $-anchored pattern used as a validator. $ also
matches immediately before a trailing newline, so "abc\n" passes a check meant
to reject whitespace. re.fullmatch() with no anchor is the correct shape, and
the defect is mechanically detectable wherever a validator pairs .match( with a
$-terminated pattern.

Three more observations from this fix, generalizable but not lintable:

  • A reply field is not a signal until something reads it. recovered travelled
    to the JSON boundary and stopped; the operator saw the same success card
    either way. Ship the reader with the field or ship neither.
  • A fingerprint match settles PROVENANCE, not USABILITY. Once bytes are proven
    to be the ones this install uploaded, a second gate asking whether they are
    any good is answering a question the rest of the product answers by handing
    the file over.
  • Exhausting a tarfile member iterator does not detect truncation. A header cut
    at a non-zero offset reads as a normal end of archive, so a valid gzip wrapping
    an incomplete tar walks clean. This was measured while implementing a reviewer
    remedy, and it is why that remedy was insufficient.

Closes #12391
Refs #12644

@chenmingwei23
chenmingwei23 requested review from a team and smeyffret September 21, 2026 17:11
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Verify #12644 stays tracked: a recoverable overwrite now restores silently, so a co-writer clobbering this install's keys is visible only in backend logs.

[DESIGN-REVIEWED] e9399cb

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

No findings.

The sole candidate — a leak of the staged recovered file if os.replace(recovered, tmp) raises (backup.py:4279) — does not survive falsification. recovered and tmp are both created by tempfile.mkstemp(dir=str(staging)) in the same directory, so the rename is a same-filesystem atomic replace of a just-created source onto an existing destination; that operation does not fail under any input that occurs in practice (a missing tmp would still succeed, EXDEV cannot arise same-dir). The candidate's own triggers ("EBUSY/EPERM", "interrupted rename", "concurrently removed") are all speculative "could" cases, so requirement (a) — a concrete input that occurs in practice — is unmet. Even granting it, the harm is one orphaned staged temp file in app storage: not a crash, security hole, or data loss. Dropped.

No additional grounded defect surfaced in the changed lines.

[OPUS-REVIEWED] e9399cb

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

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

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of e9399cb05d009a49dd0b1ad3859ed1cae22f6522 — 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

Two spellings of one authorization now coexist — _authorize_recovery_read vs _authorize_upload's two-read shape — until #12705 lands; verify that issue actually exists.

What this change ships

Inventory (9 items) — 9 justified

Intent: FIX — a restore refused the operator's own backup after a co-writer overwrote the key, though the archive sat on the drive as the recorded noncurrent version.

  1. Restoring an overwritten own key now returns this install's archive instead of refusing — justified
  2. The one extra read is re-authorized immediately before it runs (disabled app, withdrawn or mismatched grant, repointed profile all stop it) — justified
  3. storage.get_file gains an optional version pin; its one existing caller is unchanged — justified
  4. Stored version ids are validated before reaching the CLI; a leading - is refused as argv option injection — justified
  5. Denied pinned reads name s3:GetObjectVersion, the action S3 actually checks, in the remediation hint — justified
  6. Under foreign_ok recovery never runs; the override's meaning is unchanged — justified
  7. The restore reply's byte count describes the recovered object, not the overwrite — justified
  8. Recovery attempts and outcomes are logged — justified
  9. Spec, docstrings and retention comments updated in the same commit — justified

[FIRST-PRINCIPLES-REVIEWED] e9399cb

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e9399cb

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

@chenmingwei23
chenmingwei23 force-pushed the fix/aws-control-version-restore-12391 branch from e5e7186 to 2f466cc Compare September 21, 2026 18:58
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 21, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/aws-control-version-restore-12391 branch from 2f466cc to d6e7de6 Compare September 21, 2026 19:25
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for d6e7de670f809f168b58dddf090e778e6d7c7974; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

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

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for d6e7de670f809f168b58dddf090e778e6d7c7974; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

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

@chenmingwei23
chenmingwei23 force-pushed the fix/aws-control-version-restore-12391 branch from d6e7de6 to 4d0dc07 Compare September 21, 2026 20:29
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for 4d0dc079c6c6fadcad25955d81a7366c14abf386; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

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

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for 4d0dc079c6c6fadcad25955d81a7366c14abf386; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

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

@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 21, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/aws-control-version-restore-12391 branch from 4d0dc07 to 712468f Compare September 21, 2026 21:05
@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 21, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/aws-control-version-restore-12391 branch from 712468f to ac4e6c1 Compare September 21, 2026 22:31
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 21, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 22, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/aws-control-version-restore-12391 branch from 7a8fda6 to b57be8a Compare September 22, 2026 03:24
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for b57be8a6360d929d134d3f81228f6e4596dfd016; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

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

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 22, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/aws-control-version-restore-12391 branch from b57be8a to c6f08e4 Compare September 22, 2026 04:23
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Sep 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging c6f08e456bd045230f4a9df8947e9a57ca8c952b. Adjudication produced no [GPT-ADJUDICATED] marker for c6f08e4: the adjudication stage FAILED TO RUN (its raw output is in the Adjudication details block -- typically an API or setup error), so no proportionality review took place and GPT's blocking verdict stands unreviewed.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/apps/builtins/aws_control/backend/backup.py:3981 -- Corrupt consent state escapes recovery as a 500
grant = aws_consent.read_grant(aws_consent.SERVICE_S3)
Consent file becomes invalid UTF-8 during the initial download -> recovery recheck raises UnicodeDecodeError -> restore returns 500 instead of its existing 409 refusal.
Anchor: residual/crash-data-loss-corruption
Fix: Catch UnicodeDecodeError from the grant read and return the no-consent refusal.
[BLOCK-MERGE] c6f08e4
[GPT-REVIEWED] c6f08e4
False positive or not applicable? A repository writer can comment:
/ai-review override gpt c6f08e456bd045230f4a9df8947e9a57ca8c952b: <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 22, 2026
…y is overwritten

One backup drive is reachable by every install pointed at the account, and
versioning is on for that reason. When a co-writer overwrites a key this install
recorded, our archive stays on the drive as a noncurrent version. The restore read
named no version, so it fetched the overwriting object, failed the recorded body
fingerprint and refused -- with our archive present and unnameable.

storage.get_file now takes an optional version, and when an ORIGIN_SELF key fails
the fingerprint backup._recover_recorded_version makes exactly one further read, of
the VersionId uploaded_versions records for that key. It is accepted only on the
same evidence the current-version path uses -- that fingerprint, re-taken over the
bytes that arrive -- plus _archive_is_readable. Absent, deleted, malformed or
mismatched returns the existing ORIGIN_UNVERIFIED refusal, so the recovery can only
find bytes that already pass; it can never widen what a restore accepts.

The recovery runs only where the mismatch would REFUSE. Under foreign_ok the caller
has already said it will take whatever is current without proof, so there is no
refusal to rescue, and reaching past the current object would hand that caller
different bytes than it accepted, relabelled as a proven self archive. The reply
carries recovered, because the alternative outcome for this case is a refusal, which
is loud: an operator who silently receives a recovered archive would never learn a
co-writer is overwriting their backup chain.

Version ids are validated as data. They are opaque and drawn from the full base64
alphabet, so the shape is printable ASCII with no whitespace and a bounded length,
applied with fullmatch: '$' also matches BEFORE a trailing newline, so an anchored
pattern accepts "abc\n" and sends a whitespace-bearing id to the CLI. The security
rule is that a leading '-' is refused, because get_file passes the id as a bare argv
element and the AWS CLI's own option grammar would read one as another option. There
is no shell in the path. apps/aws-control/data is neither agent-readable nor
agent-writable -- it sits behind the agent file-tool floor and is bind-masked from
every agent sandbox -- so this check stands between a stored value and an argv
element, not between an agent and the CLI.

A fingerprint match is the whole test, and nothing else is asked of the recovered
bytes. Whether they still open as a tar.gz is not checked, because the
current-version read does not check it either and the upload side pushes payloads it
cannot read (_tree_fingerprint returns "" for an unreadable tar.gz), so an own archive
can legitimately be malformed. Refusing one only on the recovery path would hand the
operator their own file when nobody overwrote the key and a refusal when somebody did,
for identical bytes, at the cost of decompressing a multi-gigabyte archive to get
there.

Retention is deliberately untouched. _current_version_is_ours stays a question about
the current version, so a recoverable-but-noncurrent key still holds no keep slot --
which errs toward retaining more.

Closes #12391
Refs #12381
@chenmingwei23
chenmingwei23 force-pushed the fix/aws-control-version-restore-12391 branch from c6f08e4 to e9399cb Compare September 22, 2026 06:43
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 22, 2026

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

Verified the load-bearing claims against main myself rather than reading the body's summary.

  • restore_download reaches the recovery only inside if origin == ORIGIN_SELF: (backup.py:83 of that function), and the pre-transfer origin != ORIGIN_SELF and not foreign_ok refusal still stands ahead of it, so the new path cannot widen what an unproven archive reaches. recovered is None leaves origin = ORIGIN_UNVERIFIED untouched.
  • _authorize_recovery_read's single-snapshot grant read is not a weakening. aws_consent.is_granted is exactly read_grant plus the profile/region comparison and nothing else, so the new gate asks the same local questions off one snapshot and then adds grant.account != account, which the upload gate does not ask at all. Strictly tighter, and the STS-first ordering matches _authorize_upload.
  • _VERSION_ID_RE with fullmatch and no anchor is the right fix for the $-before-trailing-newline hole, and the leading-- check is what actually closes the argv-option case. _is_provable_version_id already existed and is what keeps "null" out, so the syntax/identity split is real rather than a restatement.
  • apps/aws-control/data is in sandbox.py:267's hidden leaves, so "not agent-writable" holds; validating on the way out is still correct for a truncated read-back.

Approving. The four disclosed non-goals are all the conservative direction, and #12644 already carries the dashboard warning gap with the path a fix needs, so nothing here is left implicit.

@bolichen97
bolichen97 merged commit fa9804a into main Sep 22, 2026
93 checks passed
@bolichen97
bolichen97 deleted the fix/aws-control-version-restore-12391 branch September 22, 2026 07:46
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 22, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…y is overwritten (kirodotdev#12565)

One backup drive is reachable by every install pointed at the account, and
versioning is on for that reason. When a co-writer overwrites a key this install
recorded, our archive stays on the drive as a noncurrent version. The restore read
named no version, so it fetched the overwriting object, failed the recorded body
fingerprint and refused -- with our archive present and unnameable.

storage.get_file now takes an optional version, and when an ORIGIN_SELF key fails
the fingerprint backup._recover_recorded_version makes exactly one further read, of
the VersionId uploaded_versions records for that key. It is accepted only on the
same evidence the current-version path uses -- that fingerprint, re-taken over the
bytes that arrive -- plus _archive_is_readable. Absent, deleted, malformed or
mismatched returns the existing ORIGIN_UNVERIFIED refusal, so the recovery can only
find bytes that already pass; it can never widen what a restore accepts.

The recovery runs only where the mismatch would REFUSE. Under foreign_ok the caller
has already said it will take whatever is current without proof, so there is no
refusal to rescue, and reaching past the current object would hand that caller
different bytes than it accepted, relabelled as a proven self archive. The reply
carries recovered, because the alternative outcome for this case is a refusal, which
is loud: an operator who silently receives a recovered archive would never learn a
co-writer is overwriting their backup chain.

Version ids are validated as data. They are opaque and drawn from the full base64
alphabet, so the shape is printable ASCII with no whitespace and a bounded length,
applied with fullmatch: '$' also matches BEFORE a trailing newline, so an anchored
pattern accepts "abc\n" and sends a whitespace-bearing id to the CLI. The security
rule is that a leading '-' is refused, because get_file passes the id as a bare argv
element and the AWS CLI's own option grammar would read one as another option. There
is no shell in the path. apps/aws-control/data is neither agent-readable nor
agent-writable -- it sits behind the agent file-tool floor and is bind-masked from
every agent sandbox -- so this check stands between a stored value and an argv
element, not between an agent and the CLI.

A fingerprint match is the whole test, and nothing else is asked of the recovered
bytes. Whether they still open as a tar.gz is not checked, because the
current-version read does not check it either and the upload side pushes payloads it
cannot read (_tree_fingerprint returns "" for an unreadable tar.gz), so an own archive
can legitimately be malformed. Refusing one only on the recovery path would hand the
operator their own file when nobody overwrote the key and a refusal when somebody did,
for identical bytes, at the cost of decompressing a multi-gigabyte archive to get
there.

Retention is deliberately untouched. _current_version_is_ours stays a question about
the current version, so a recoverable-but-noncurrent key still holds no keep slot --
which errs toward retaining more.

Closes kirodotdev#12391
Refs kirodotdev#12381
wknight1 pushed a commit to wknight1/KiroCrew that referenced this pull request Oct 5, 2026
…y is overwritten (kirodotdev#12565)

One backup drive is reachable by every install pointed at the account, and
versioning is on for that reason. When a co-writer overwrites a key this install
recorded, our archive stays on the drive as a noncurrent version. The restore read
named no version, so it fetched the overwriting object, failed the recorded body
fingerprint and refused -- with our archive present and unnameable.

storage.get_file now takes an optional version, and when an ORIGIN_SELF key fails
the fingerprint backup._recover_recorded_version makes exactly one further read, of
the VersionId uploaded_versions records for that key. It is accepted only on the
same evidence the current-version path uses -- that fingerprint, re-taken over the
bytes that arrive -- plus _archive_is_readable. Absent, deleted, malformed or
mismatched returns the existing ORIGIN_UNVERIFIED refusal, so the recovery can only
find bytes that already pass; it can never widen what a restore accepts.

The recovery runs only where the mismatch would REFUSE. Under foreign_ok the caller
has already said it will take whatever is current without proof, so there is no
refusal to rescue, and reaching past the current object would hand that caller
different bytes than it accepted, relabelled as a proven self archive. The reply
carries recovered, because the alternative outcome for this case is a refusal, which
is loud: an operator who silently receives a recovered archive would never learn a
co-writer is overwriting their backup chain.

Version ids are validated as data. They are opaque and drawn from the full base64
alphabet, so the shape is printable ASCII with no whitespace and a bounded length,
applied with fullmatch: '$' also matches BEFORE a trailing newline, so an anchored
pattern accepts "abc\n" and sends a whitespace-bearing id to the CLI. The security
rule is that a leading '-' is refused, because get_file passes the id as a bare argv
element and the AWS CLI's own option grammar would read one as another option. There
is no shell in the path. apps/aws-control/data is neither agent-readable nor
agent-writable -- it sits behind the agent file-tool floor and is bind-masked from
every agent sandbox -- so this check stands between a stored value and an argv
element, not between an agent and the CLI.

A fingerprint match is the whole test, and nothing else is asked of the recovered
bytes. Whether they still open as a tar.gz is not checked, because the
current-version read does not check it either and the upload side pushes payloads it
cannot read (_tree_fingerprint returns "" for an unreadable tar.gz), so an own archive
can legitimately be malformed. Refusing one only on the recovery path would hand the
operator their own file when nobody overwrote the key and a refusal when somebody did,
for identical bytes, at the cost of decompressing a multi-gigabyte archive to get
there.

Retention is deliberately untouched. _current_version_is_ours stays a question about
the current version, so a recoverable-but-noncurrent key still holds no keep slot --
which errs toward retaining more.

Closes kirodotdev#12391
Refs kirodotdev#12381
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.

aws-control: a restore cannot fetch the version it recorded, so an overwritten key has no automated recovery

2 participants