Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle modified hardlinks to /sysroot #405

Closed
cgwalters opened this issue Nov 10, 2022 · 0 comments · Fixed by #408
Closed

handle modified hardlinks to /sysroot #405

cgwalters opened this issue Nov 10, 2022 · 0 comments · Fixed by #408

Comments

@cgwalters
Copy link
Member

Today this:

FROM quay.io/fedora/fedora-coreos:stable
RUN touch /usr/bin/bash

When built using e.g. the redhat-actions/buildah-build@v2 Github action, seems to result in a tar stream that looks like this:

drwxr-xr-x root/root         0 1969-12-31 19:00 sysroot/
drwxr-xr-x root/root         0 1969-12-31 19:00 sysroot/ostree/
drwxr-xr-x root/root         0 1969-12-31 19:00 sysroot/ostree/repo/
drwxr-xr-x root/root         0 1969-12-31 19:00 sysroot/ostree/repo/objects/
drwxr-xr-x root/root         0 1969-12-31 19:00 sysroot/ostree/repo/objects/60/
-rwxr-xr-x root/root   1390000 2022-11-08 18:26 sysroot/ostree/repo/objects/60/feb13e826d2f9b62490ab24cea0f4a2d09615fb57027e55f713c18c59f4796.file
drwxr-xr-x root/root         0 2022-11-08 18:26 usr/
drwxr-xr-x root/root         0 2022-11-08 18:26 usr/bin/
hrwxr-xr-x root/root         0 2022-11-08 18:26 usr/bin/bash link to sysroot/ostree/repo/objects/60/feb13e826d2f9b62490ab24cea0f4a2d09615fb57027e55f713c18c59f4796.file

But that causes problems because when importing layered builds, we discard content in /sysroot entirely.

I think this has something to do with the use of the overlayfs driver versus vfs. I believe with the kernel overlayfs, modifying a hardlinked file will result in a copyup of just that single file; it explicitly will not mutate all targets of that link. From the docs:

  1. "inode index"
    Enabled with the mount option or module option "index=on" or with the
    kernel config option CONFIG_OVERLAY_FS_INDEX=y.
    If this feature is disabled and a file with multiple hard links is copied
    up, then this will "break" the link. Changes will not be propagated to
    other names referring to the same inode.

I can think of two fixes:

  • During ostree container commit, we can actually nuke everything in /sysroot - or at least just files whose timestamp is newer than the epoch. This would result in whiteout files in the serialized stream, which the import path will just ignore.
  • Probably better: Actually handle this case at import time by rewriting the tar stream to have the link point to the first file name (hence decrementing the link count) or perhaps moving the file into e.g. /usr/lib/ostree/modified-objects/$digest and rewriting the links?

It may make sense to do both.

cgwalters added a commit to cgwalters/ostree-rs-ext that referenced this issue Nov 11, 2022
xref ostreedev#405

This test case reproduces the failure when we're trying
to import a tar archive with hardlinks into `/sysroot`.
cgwalters added a commit to cgwalters/ostree-rs-ext that referenced this issue Nov 11, 2022
xref ostreedev#405

This test case reproduces the failure when we're trying
to import a tar archive with hardlinks into `/sysroot`.
cgwalters added a commit to cgwalters/ostree-rs-ext that referenced this issue Nov 11, 2022
xref ostreedev#405

This test case reproduces the failure when we're trying
to import a tar archive with hardlinks into `/sysroot`.
cgwalters added a commit to cgwalters/ostree-rs-ext that referenced this issue Nov 11, 2022
Some container build processes run without overlayfs inode indexing
on - in this common scenario, overlayfs is not quite POSIX compliant
because it will break the hardlink instead of modifying all versions.

We need to handle this case of having *all* names for a hardlinked
file being modified though too.  If the serialized tar stream
has the file in `/sysroot` be the canonical version, then because
we drop out that file here, we'll fail to import.

Fix this by significantly beefing up the tar filtering/reprocessing
logic:

 - When we see a *modified* file in `/sysroot` with a nonzero timestamp,
   cache its data into a lookaside temporary directory
 - If we then see a hardlink to that file path, make *that* file
   be the canonical version in e.g. `/usr`.
 - Any further hardlinks to `/sysroot` instead become hardlinks
   to the new canonical one.

(Arguably perhaps...we should actually not have used hardlinks
 in ostree containers at all, but injected this metadata in
 some other way.  But, the ship has sailed on that)

Closes: ostreedev#405
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 a pull request may close this issue.

1 participant