Skip to content

Commit

Permalink
archive, rootless: use user.* instead of trusted.*
Browse files Browse the repository at this point in the history
unprivileged users cannot use the trusted.* xattrs.  Since for
rootless we always mount overlay with userxattr, we can just check if
running in rootless mode and use user.* instead of trusted.*.

Closes: containers/podman#9936

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Apr 6, 2021
1 parent 4821b98 commit 42af54d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
12 changes: 12 additions & 0 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/containers/storage/pkg/pools"
"github.com/containers/storage/pkg/promise"
"github.com/containers/storage/pkg/system"
"github.com/containers/storage/pkg/unshare"
gzip "github.com/klauspost/pgzip"
rsystem "github.com/opencontainers/runc/libcontainer/system"
"github.com/pkg/errors"
Expand Down Expand Up @@ -1489,3 +1490,14 @@ func TarPath(uidmap []idtools.IDMap, gidmap []idtools.IDMap) func(path string) (
})
}
}

// GetOverlayXattrName returns the xattr used by the overlay driver with the
// given name.
// It uses the trusted.overlay prefix when running as root, and user.overlay
// in rootless mode.
func GetOverlayXattrName(name string) string {
if unshare.IsRootless() {
return fmt.Sprintf("user.overlay.%s", name)
}
return fmt.Sprintf("trusted.overlay.%s", name)
}
10 changes: 7 additions & 3 deletions pkg/archive/archive_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"golang.org/x/sys/unix"
)

func getOverlayOpaqueXattrName() string {
return GetOverlayXattrName("opaque")
}

func GetWhiteoutConverter(format WhiteoutFormat, data interface{}) TarWhiteoutConverter {
if format == OverlayWhiteoutFormat {
if rolayers, ok := data.([]string); ok && len(rolayers) > 0 {
Expand Down Expand Up @@ -39,13 +43,13 @@ func (o overlayWhiteoutConverter) ConvertWrite(hdr *tar.Header, path string, fi

if fi.Mode()&os.ModeDir != 0 {
// convert opaque dirs to AUFS format by writing an empty file with the whiteout prefix
opaque, err := system.Lgetxattr(path, "trusted.overlay.opaque")
opaque, err := system.Lgetxattr(path, getOverlayOpaqueXattrName())
if err != nil {
return nil, err
}
if len(opaque) == 1 && opaque[0] == 'y' {
if hdr.Xattrs != nil {
delete(hdr.Xattrs, "trusted.overlay.opaque")
delete(hdr.Xattrs, getOverlayOpaqueXattrName())
}
// If there are no lower layers, then it can't have been deleted in this layer.
if len(o.rolayers) == 0 {
Expand Down Expand Up @@ -114,7 +118,7 @@ func (overlayWhiteoutConverter) ConvertReadWithHandler(hdr *tar.Header, path str

// if a directory is marked as opaque by the AUFS special file, we need to translate that to overlay
if base == WhiteoutOpaqueDir {
err := handler.Setxattr(dir, "trusted.overlay.opaque", []byte{'y'})
err := handler.Setxattr(dir, getOverlayOpaqueXattrName(), []byte{'y'})
// don't write the file itself
return false, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/archive/archive_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func setupOverlayTestDir(t *testing.T, src string) {
err := os.Mkdir(filepath.Join(src, "d1"), 0700)
require.NoError(t, err)

err = system.Lsetxattr(filepath.Join(src, "d1"), "trusted.overlay.opaque", []byte("y"), 0)
err = system.Lsetxattr(filepath.Join(src, "d1"), getWhiteoutXattrName(), []byte("y"), 0)
require.NoError(t, err)

err = ioutil.WriteFile(filepath.Join(src, "d1", "f1"), []byte{}, 0600)
Expand All @@ -36,7 +36,7 @@ func setupOverlayTestDir(t *testing.T, src string) {
err = os.Mkdir(filepath.Join(src, "d2"), 0750)
require.NoError(t, err)

err = system.Lsetxattr(filepath.Join(src, "d2"), "trusted.overlay.opaque", []byte("y"), 0)
err = system.Lsetxattr(filepath.Join(src, "d2"), getWhiteoutXattrName(), []byte("y"), 0)
require.NoError(t, err)

err = ioutil.WriteFile(filepath.Join(src, "d2", "f1"), []byte{}, 0660)
Expand All @@ -60,7 +60,7 @@ func setupOverlayLowerDir(t *testing.T, lower string) {
}

func checkOpaqueness(t *testing.T, path string, opaque string) {
xattrOpaque, err := system.Lgetxattr(path, "trusted.overlay.opaque")
xattrOpaque, err := system.Lgetxattr(path, getWhiteoutXattrName())
require.NoError(t, err)

if string(xattrOpaque) != opaque {
Expand Down
2 changes: 1 addition & 1 deletion pkg/archive/changes_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func overlayDeletedFile(layers []string, root, path string, fi os.FileInfo) (str
return "", nil
}
// If the directory isn't marked as opaque, then it's just a normal directory.
opaque, err := system.Lgetxattr(filepath.Join(root, path), "trusted.overlay.opaque")
opaque, err := system.Lgetxattr(filepath.Join(root, path), getWhiteoutXattrName())
if err != nil {
return "", err
}
Expand Down

0 comments on commit 42af54d

Please sign in to comment.