Skip to content

fix: refuse an image built while its context changed - #733

Merged
tgockel merged 1 commit into
trunkfrom
392-image-key-recheck
Oct 27, 2026
Merged

tgockel merged 1 commit into
trunkfrom
392-image-key-recheck

Conversation

@tgockel

@tgockel tgockel commented Oct 27, 2026

Copy link
Copy Markdown
Owner

The cache key is hashed before buildah build starts, but buildah reads the context as each COPY runs. A file saved during an earlier RUN therefore landed in an image tagged with the key of the content from before the edit, and restoring that content later cache-hit and served the edited image.

The key is now hashed again once buildah finishes and before anything is named, and compared with the caller's tag. On a mismatch the temporary image is discarded, nothing is tagged, and the build fails with the new OutrigError::BuildContextChanged. It is an error rather than a rebuild because the session record, outrig build and ensure_tagged_image_for all hold a tag computed up front, and the edited content can only hash to a different one. A rerun keys it, and buildah's layer cache keeps that short.

build_image_for and ensure_tagged_image_for[_with_output] now expect the tag compute_tag_for gave for the same inputs, and refuse any other the same way once their build has run. Three fake-runtime tests and one e2e that handed a build a made-up tag now pass a computed one.

Fixes #392

Summary

What does this change, and why?

Checklist

  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-targets -- -D warnings is clean
  • cargo test --workspace passes
  • Docs in doc/ updated if behavior changed (mdbook build still clean)
  • CHANGELOG updated for user-visible changes

Notes for reviewers

Anything worth calling out -- tricky bits, follow-ups, or intentionally out-of-scope items.

The cache key is hashed before `buildah build` starts, but buildah
reads the context as each `COPY` runs. A file saved during an earlier
`RUN` therefore landed in an image tagged with the key of the content
from before the edit, and restoring that content later cache-hit and
served the edited image.

The key is now hashed again once buildah finishes and before anything
is named, and compared with the caller's tag. On a mismatch the
temporary image is discarded, nothing is tagged, and the build fails
with the new OutrigError::BuildContextChanged. It is an error rather
than a rebuild because the session record, `outrig build` and
ensure_tagged_image_for all hold a tag computed up front, and the
edited content can only hash to a different one. A rerun keys it, and
buildah's layer cache keeps that short.

build_image_for and ensure_tagged_image_for[_with_output] now expect
the tag compute_tag_for gave for the same inputs, and refuse any other
the same way once their build has run. Three fake-runtime tests and one
e2e that handed a build a made-up tag now pass a computed one.

Fixes #392
@tgockel
tgockel merged commit 057fdd4 into trunk Oct 27, 2026
11 checks passed
@tgockel
tgockel deleted the 392-image-key-recheck branch October 27, 2026 14:41

This branch was successfully deployed

1 active deployment
github-pages — 057fdd48 Deployed Oct 27, 2026 by tgockel via deploy #178
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.

The image cache key is computed before buildah reads the context, so an edit during a long build is tagged under the old content's key

1 participant