Skip to content

Conversation

@cyphar
Copy link
Member

@cyphar cyphar commented May 20, 2025

Since Linux 5.11, overlayfs supports using "user.overlay." as the xattr
namespace for special overlayfs xattrs (rather than the default
"trusted.overlay.") when mounted using the "userxattr" mount option.
This is a key part of unprivileged overlayfs mounting.

For the most part, supporting this is fairly straightforward now that
the on-disk format is represented with OverlayfsRootfs -- all hardcoded
references to "trusted.overlay." just need to take into account the
value of OverlayfsRootfs.UserXattr. Downstreams like stacker have had
out-of-tree patches to support operating on these xattrs for a long time
(since they use unprivileged overlayfs mounts whenever possible), so
supporting it in a more structured way should be very welcome.

One key thing to note is that (just like overlayfs) we only ever treat
one of "trusted.overlay." or "user.overlay." as special. The existing
tests also only needed miminal adjustments, and include tests to make
sure that we only ever touch the appropriate namespace.

This also finally allows us to run the overlayfs tests as an
unprivileged user.

Implements #576
Implements #584
Signed-off-by: Aleksa Sarai [email protected]

Our xattr tests in particular incorrectly re-used the same rootfs for
both on-disk formats, which happened to work because the subtest
ordering resulted in correct behaviour, but changing the test names
caused those tests to fail.

Fixes: 9a1cefa ("oci: layer: correctly handle trusted.overlay xattr namespace escaping")
Signed-off-by: Aleksa Sarai <[email protected]>
@cyphar cyphar added this to the 0.5.0 milestone May 20, 2025
@codecov-commenter
Copy link

codecov-commenter commented May 20, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 91.84783% with 15 lines in your changes missing coverage. Please review.

Project coverage is 73.74%. Comparing base (36a1d10) to head (7d2d5e5).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
oci/layer/tar_extract.go 68.96% 6 Missing and 3 partials ⚠️
oci/layer/types.go 94.87% 2 Missing ⚠️
utils.go 0.00% 1 Missing and 1 partial ⚠️
oci/layer/tar_generate.go 91.66% 0 Missing and 1 partial ⚠️
oci/layer/xattr.go 98.21% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #587      +/-   ##
==========================================
+ Coverage   72.58%   73.74%   +1.16%     
==========================================
  Files          68       69       +1     
  Lines        5424     5493      +69     
==========================================
+ Hits         3937     4051     +114     
+ Misses       1104     1060      -44     
+ Partials      383      382       -1     
Files with missing lines Coverage Δ
cmd/umoci/insert.go 80.70% <100.00%> (+0.70%) ⬆️
cmd/umoci/raw-unpack.go 67.50% <100.00%> (+1.26%) ⬆️
cmd/umoci/unpack.go 78.37% <100.00%> (+3.03%) ⬆️
oci/layer/generate.go 68.83% <100.00%> (-0.99%) ⬇️
oci/layer/unpack.go 60.41% <100.00%> (+0.50%) ⬆️
oci/layer/utils.go 71.42% <ø> (ø)
oci/layer/utils_unix.go 64.44% <100.00%> (ø)
oci/layer/tar_generate.go 67.72% <91.66%> (+1.88%) ⬆️
oci/layer/xattr.go 98.87% <98.21%> (+50.54%) ⬆️
oci/layer/types.go 94.87% <94.87%> (ø)
... and 2 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cyphar
Copy link
Member Author

cyphar commented May 20, 2025

/cc @hallyn @tych0 @rchincha

This should remove the main need you have for a downstream fork of umoci. I suspect you will want to just do OverlayfsRootfs{UserXattr: true} for everything.

cyphar added 4 commits May 20, 2025 17:25
…onfig

Previously we had separate ways of specifying the on-disk format with
UnpackOptions and RepackOptions (UnpackOptions had an enum for the
on-disk format while RepackOptions just had a boolean specifying whether
overlayfs-style whiteouts should be translated).

Conceptually it makes far more sense to think of the configuration as
being an "on-disk format", so we should represent it that way in the
configuration. In addition to the on-disk format type, the userns
mapping applied to the rootfs is more a property of the on-disk format
than being a standalone option.

By creating an OnDiskFormat interface that has multiple implementations
we can also add per-on-disk-format configuration options (such as
userxattr for the overlayfs on-disk-format, which will be added later in
this series).

Signed-off-by: Aleksa Sarai <[email protected]>
…lter

This doesn't happen in practice (because filters are retrieved based on
their xattr prefix), but it's useful when writing unit tests of our
behaviour.

Signed-off-by: Aleksa Sarai <[email protected]>
Since "" is an invalid xattr, we don't need to mess around with *string
to indicate that an xattr should be removed.

Signed-off-by: Aleksa Sarai <[email protected]>
Since Linux 5.11, overlayfs supports using "user.overlay." as the xattr
namespace for special overlayfs xattrs (rather than the default
"trusted.overlay.") when mounted using the "userxattr" mount option.
This is a key part of unprivileged overlayfs mounting.

For the most part, supporting this is fairly straightforward now that
the on-disk format is represented with OverlayfsRootfs -- all hardcoded
references to "trusted.overlay." just need to take into account the
value of OverlayfsRootfs.UserXattr. Downstreams like stacker have had
out-of-tree patches to support operating on these xattrs for a long time
(since they use unprivileged overlayfs mounts whenever possible), so
supporting it in a more structured way should be very welcome.

One key thing to note is that (just like overlayfs) we only ever treat
one of "trusted.overlay." or "user.overlay." as special. The existing
tests also only needed miminal adjustments, and include tests to make
sure that we only ever touch the appropriate namespace.

This also finally allows us to run the overlayfs tests as an
unprivileged user.

Signed-off-by: Aleksa Sarai <[email protected]>
@cyphar cyphar force-pushed the overlayfs-userxattr branch from 6bd7436 to 7d2d5e5 Compare May 20, 2025 07:26
@cyphar cyphar modified the milestones: 0.5.0, 0.6.0 May 20, 2025
@cyphar cyphar merged commit 9892049 into opencontainers:main May 21, 2025
18 checks passed
@cyphar cyphar deleted the overlayfs-userxattr branch May 21, 2025 02:29
cyphar added a commit to cyphar/stacker that referenced this pull request May 31, 2025
This allows us to switch away from our umoci fork now that upstream
supports OverlayfsRootfs and the various features we need. The key
changes that allow us to switch away from our fork are:

 * opencontainers/umoci#572 which implemented a large number of fixes
   to overlayfs handling, such as opaque whiteouts and several features
   not implemented in our fork (xattr escaping, handling of missing
   parent directories, improved rootless support, handling of nested
   whiteouts inside an opaque whiteout).

 * opencontainers/umoci#581 which switched to a Docker-friendly gzip
   block size by default, removing the need to configure it (as
   suggested in opencontainers/umoci#509).

 * opencontainers/umoci#587 which implemented full configurable
   userxattr (user.overlay.*) support.

Signed-off-by: Aleksa Sarai <[email protected]>
rchincha pushed a commit to project-stacker/stacker that referenced this pull request May 31, 2025
* feat: update to skopeo v1.13.0

We need to update skopeo to match the pgzip version between skopeo and
umoci.

Signed-off-by: Aleksa Sarai <[email protected]>

* feat: update to github.com/opencontainers/[email protected]

This allows us to switch away from our umoci fork now that upstream
supports OverlayfsRootfs and the various features we need. The key
changes that allow us to switch away from our fork are:

 * opencontainers/umoci#572 which implemented a large number of fixes
   to overlayfs handling, such as opaque whiteouts and several features
   not implemented in our fork (xattr escaping, handling of missing
   parent directories, improved rootless support, handling of nested
   whiteouts inside an opaque whiteout).

 * opencontainers/umoci#581 which switched to a Docker-friendly gzip
   block size by default, removing the need to configure it (as
   suggested in opencontainers/umoci#509).

 * opencontainers/umoci#587 which implemented full configurable
   userxattr (user.overlay.*) support.

Signed-off-by: Aleksa Sarai <[email protected]>

---------

Signed-off-by: Aleksa Sarai <[email protected]>
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 this pull request may close these issues.

layer pack/unpack: unify on-disk format configuration layer: overlay userxattr support

2 participants