Skip to content
This repository was archived by the owner on Sep 5, 2026. It is now read-only.

fix(image): sync-image reconstitution must not flatten rootfs ownership - #11

Merged
the-bokya merged 2 commits into
mainfrom
fix/sync-image-preserve-ownership
Aug 27, 2026
Merged

fix(image): sync-image reconstitution must not flatten rootfs ownership#11
the-bokya merged 2 commits into
mainfrom
fix/sync-image-preserve-ownership

Conversation

@the-bokya

Copy link
Copy Markdown
Member

Problem (downstream symptom hit live)

When a promoted base image is fanned out host-to-host via sync-image (re-served as a squashfs and reconstituted on the target), non-root paths — notably /home/frappe — ended up owned root:root. A server booting that distributed image then failed with:

cd /home/frappe/pilot: Permission denied

on any host that was not the golden's promote-home. The promoted image on the home host was fine (uid 1000), and snapshot-clones were fine.

Root cause

internal/image/rootfs.go: buildExt4 ran a blanket

sudo chown -R root:root <extracted-rootfs>

over the unsquashed tree just before mkfs.ext4 -d. sudo unsquashfs already restores the source squashfs's uid/gid faithfully and mkfs.ext4 -d copies them through, so the blanket chown is pure destruction — it flattens every legitimately non-root path (/home/frappe at uid 1000 most damagingly). The author already knew it was destructive: the very next lines hand-repaired /var/cache/man (chown 6:12) because the blanket chown had clobbered it — but nothing restored /home/frappe.

buildExt4 is reached only from SyncImage (the URL / reconstitution path). Promote, snapshot-clone and migration base-ship are all block-level (dd / dm-clone / NBD), which preserve ownership — exactly why the home host and clones stayed correct while sync-image distribution broke.

Fix

Remove the blanket chown -R root:root so uid/gid are preserved end-to-end on reconstitution. Keep the guarded, numeric man-cache normalization as a standalone belt-and-suspenders (correct regardless of the source, independent of the removed chown).

Verification

  • make build — green.
  • go test ./... — all packages pass.
  • New TestSyncImagePreservesTreeOwnership: asserts the blanket flatten is gone, the ext4 is still built straight from the ownership-preserving extracted tree, and the man-cache normalization still runs. Confirmed it fails when the blanket chown is reintroduced and passes with the fix.

🤖 Generated with Claude Code

the-bokya and others added 2 commits August 27, 2026 10:11
buildExt4 ran a blanket `sudo chown -R root:root` over the unsquashed
rootfs before `mkfs.ext4 -d`, flattening every legitimately non-root path.
`sudo unsquashfs` already restores the source squashfs's uid/gid and
`mkfs.ext4 -d` copies them through, so the flatten is pure destruction —
the author even had to hand-repair /var/cache/man afterward because the
blanket chown clobbered it.

Its worst victim is /home/frappe (uid 1000): when a promoted base image is
re-served as a squashfs and fanned out host-to-host via sync-image, the
reconstituted image on every non-home host booted into
`cd /home/frappe/pilot: Permission denied`. This is the only path that
hits buildExt4 (promote / snapshot-clone / migration are all block-level),
which is exactly why the home host and clones stayed correct.

Remove the blanket chown so ownership is preserved end-to-end. Keep the
guarded, numeric man-cache normalization as a standalone belt-and-suspenders
(it is correct regardless of the source and independent of the removed chown).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Assert the blanket `chown -R root:root` is gone, the ext4 is still built
straight from the ownership-preserving extracted tree, and the guarded
man-cache normalization still runs. Fails if the flatten is reintroduced.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@the-bokya
the-bokya merged commit 59b40c6 into main Aug 27, 2026
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant