-
Notifications
You must be signed in to change notification settings - Fork 18.9k
daemon/graphdriver/overlay2: set TarOptions.InUserNS for native differ (fix "failed to Lchown "/dev/console") #48083
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
Conversation
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, andTypeCharto 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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
I'll bring this one in, and move the backport out of draft. |
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
EPERMwould be discarded, andcreateTarFilewould not returnearly, therefor attempting to os.LChown the missing file, ultimately
resulting in an error:
This patch fixes the missing option in overlay.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)