Skip to content

Conversation

@thaJeztah
Copy link
Member

pkg/archive: getWhiteoutConverter: don't error with userns enabled

Since 838047a, the overlayWhiteoutConverter
is supported with userns enabled, so we no longer need this check.

pkg/archive: handleTarTypeBlockCharFifo: don't discard EPERM errors

This function was discarding EPERM errors if it detected that userns was
enabled; move such checks to the caller-site, so that they can decide
how to handle the error (which, in case of userns may be to log and ignore).

pkg/archive: createTarFile: consistently use the same value for userns

createTarFile accepts a opts (TarOptions) argument to specify whether
userns is enabled; whe should consider always detecting locally, but
at least make sure we're consistently working with the same value within
this function.

daemon/graphdriver/overlay2: set TarOptions.InUserNS for native differ

Commits b2fd67d (and the follow-up commit
f6b8025) updated doesSupportNativeDiff to
detect whether the host can support native overlay diffing with userns
enabled.

As a result, useNaiveDiff would now return "false" in cases where it
previously would return "true" (and thus skip). However, overlay2,
unlike fuse-overlay did not take user namespaces into account, when
using the native differ, and it therefore did not set the InUserNS option
in TarOptions.

As a result pkg/archive.createTarFile would attempt tocreate device-nodes
through handleTarTypeBlockCharFifo which would fail, but the resulting
error EPERM would be discarded, and createTarFile would not return
early, therefor attempting to os.LChown the missing file, ultimately
resulting in an error:

failed to Lchown "/dev/console" for UID 0, GID 0: lchown /dev/console: no such file or directory

This patch fixes the missing option in overlay.

- Description for the changelog

Fix "fail to register layer: failed to Lchown" errors when trying to pull an image with rootless enabled on a system that supports native overlay with user-namespaces.

- A picture of a cute animal (not mandatory but encouraged)

Since 838047a, the overlayWhiteoutConverter
is supported with userns enabled, so we no longer need this check.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This function was discarding EPERM errors if it detected that userns was
enabled; move such checks to the caller-site, so that they can decide
how to handle the error (which, in case of userns may be to log and ignore).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
createTarFile accepts a opts (TarOptions) argument to specify whether
userns is enabled; whe should consider always detecting locally, but
at least make sure we're consistently working with the same value within
this function.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Commits b2fd67d (and the follow-up commit
f6b8025) updated doesSupportNativeDiff to
detect whether the host can support native overlay diffing with userns
enabled.

As a result, [useNaiveDiff] would now return "false" in cases where it
previously would return "true" (and thus skip). However, [overlay2],
unlike [fuse-overlay] did not take user namespaces into account, when
using the native differ, and it therefore did not set the InUserNS option
in TarOptions.

As a result pkg/archive.createTarFile would attempt tocreate [device-nodes]
through [handleTarTypeBlockCharFifo] which would fail, but the resulting
error `EPERM` would be discarded, and `createTarFile` would not return
early, therefor attempting to [os.LChown] the missing file, ultimately
resulting in an error:

    failed to Lchown "/dev/console" for UID 0, GID 0: lchown /dev/console: no such file or directory

This patch fixes the missing option in overlay.

[useNaiveDiff]: https://github.com/moby/moby/blob/47eebd718f332f29a38455b61ee879ced5bc219b/daemon/graphdriver/overlay2/overlay.go#L248-L256
[overlay2]: https://github.com/moby/moby/blob/47eebd718f332f29a38455b61ee879ced5bc219b/daemon/graphdriver/overlay2/overlay.go#L684-L689
[fuse-overlay]: https://github.com/moby/moby/blob/47eebd718f332f29a38455b61ee879ced5bc219b/daemon/graphdriver/fuse-overlayfs/fuseoverlayfs.go#L456-L462
[device-nodes]: https://github.com/moby/moby/blob/ff1e2c0de72a1bbbe4cdbe1558da57d327899df5/pkg/archive/archive.go#L713-L720
[handleTarTypeBlockCharFifo]: https://github.com/moby/moby/blob/47eebd718f332f29a38455b61ee879ced5bc219b/pkg/archive/archive_unix.go#L110-L114
[os.LChown]: https://github.com/moby/moby/blob/ff1e2c0de72a1bbbe4cdbe1558da57d327899df5/pkg/archive/archive.go#L762-L773

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
// Handle this is an OS-specific way
if err := handleTarTypeBlockCharFifo(hdr, path); err != nil {
if inUserns && errors.Is(err, syscall.EPERM) {
// In most cases, cannot create a fifo if running in user namespace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside the previous code stumbled into this, is Fifo really something we don't expect to be working. In containerd we don't skip Fifo for user namespaces.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went a bit back-and-forth on both of these;

  • changed all of TypeFifo, TypeBlock, and TypeChar to try optimistically (but log the error on failure); this in the line of thought "who knows? one day it may work?"
  • or the reverse; anticipating it won't work, so skip for useNs

In the end, I decided to keep the current behavior for now, but perhaps that's something we should revisit, WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keep current behavior is right for the scope of this. Just the behavior difference was sticking out more so wanted to mention it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, same! It also was a bit my motivation for moving the error-handling out of handleTarTypeBlockCharFifo - I wanted to make it more visible / explicit where we're ignoring errors.

@thaJeztah
Copy link
Member Author

I'll bring this one in, and move the backport out of draft.

@thaJeztah thaJeztah merged commit 0d16821 into moby:master Jun 28, 2024
@thaJeztah thaJeztah deleted the fix_rootless_pull branch June 28, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment