fix(cli): include size + extras in rootfs cache key - #280
Conversation
3d345c1 to
5f7fb0d
Compare
5f7fb0d to
f56e569
Compare
|
Per the contributing guidelines, I ran the local gate on this branch:
The failing test is pre-existing and unrelated to this PR: it panics with Commits are signed off per the DCO requirement. |
|
Note on the force-push: the branch history was rewritten after the PR was opened, to align with the contributing guidelines:
|
WaylandYang
left a comment
There was a problem hiding this comment.
Thanks for the fix and the added tests. One cache-correctness blocker remains: rootfs_cache_key feeds only size_mib and extra into SHA-256; the image reference is represented only by the lossy slug. Distinct valid image references such as foo/bar:1 and foo-bar-1 both normalize to foo-bar-1, so identical size/extras will still reuse the same rootfs and can boot content from the wrong source image.
Please include the raw image reference in the hashed payload (with unambiguous framing, e.g. length prefixes or separators) and add a regression test covering two image names that collide after slug sanitization.
The digest previously covered only size_mib + extra packages; the image reference appeared solely in the lossy slug filename, so two distinct refs that slug identically (e.g. "foo/bar:1" vs "foo-bar-1") with the same size/extras produced the SAME cache key and could boot the wrong rootfs. Hash the raw reference (length-framed) into the digest; the slug remains for filename readability only. Regression test: cache_key_differentiates_refs_with_same_slug
The digest previously covered only size_mib + extra packages; the image reference appeared solely in the lossy slug filename, so two distinct refs that slug identically (e.g. "foo/bar:1" vs "foo-bar-1") with the same size/extras produced the SAME cache key and could boot the wrong rootfs. Hash the raw reference (length-framed) into the digest; the slug remains for filename readability only. Regression test: cache_key_differentiates_refs_with_same_slug
8836afe to
733ffa9
Compare
|
Thanks for the review — confirmed, and fixed in commit The digest previously covered only Fix: hash the raw image reference into the digest, length-framed ( Regression test: Tradeoffs: the length prefix means two refs that are byte-different but share a prefix can't alias (e.g. fmt/clippy/tests green. |
The digest previously covered only size_mib + extra packages; the image reference appeared solely in the lossy slug filename, so two distinct refs that slug identically (e.g. "foo/bar:1" vs "foo-bar-1") with the same size/extras produced the SAME cache key and could boot the wrong rootfs. - Hash size_mib, extra packages, and the raw image reference (length-framed) into the digest; the slug remains for readability - Regression test: cache_key_differentiates_refs_with_same_slug
733ffa9 to
588cf68
Compare
|
History rebuilt: the branch is now a single clean commit on top of current main (5e457c4) — no merged-upstream history in the diff. Same content as before: raw image ref hashed (length-framed) into the rootfs cache key + slug-collision regression test. Force-pushed; the old commits are gone from the branch. |
WaylandYang
left a comment
There was a problem hiding this comment.
Re-reviewed the cleaned-up head. The cache key now covers the raw image reference, size, and NUL-delimited extras; the slug-collision regression is correct, the diff is scoped again, and CI is green. Approved.
Related issue: #284
The rootfs cache key was derived only from the image name (slug), so
forkd from-image elixir:1.17(default 1536 MiB) andforkd from-image elixir:1.17 --size-mib 3072both mapped to the sameelixir-1-17.ext4. A rebuild with a different--size-mib(or--extra) silently reused the stale rootfs, producing a truncated/corrupt ext4 that kernel-panics on mount (VFS: Unable to mount root fs).rootfs_cache_key()hashessize_mib+extrapackages into the cache filename →elixir-1-17-3072-<sha8>.ext4. Applied in bothfrom_image_cmdandrun_cmd. Adds 4 unit tests (size, extras, determinism, slug sanitization).Verified:
cargo test -p forkd-cli→ 36 passed; re-bakedelixir:1.17 --size-mib 3072after the fix → snapshot builds and boots,elixir --version→ 1.17.3 in a live sandbox.