Skip to content

Commit 838047a

Browse files
committed
archive: fix ConvertRead/ConvertWrite functions for rootless docker & native diff overlay
Signed-off-by: Jonas Geiler <[email protected]>
1 parent aef6905 commit 838047a

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

pkg/archive/archive_linux.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"path/filepath"
77
"strings"
88

9+
"github.com/containerd/containerd/pkg/userns"
910
"github.com/docker/docker/pkg/system"
1011
"github.com/pkg/errors"
1112
"golang.org/x/sys/unix"
@@ -35,13 +36,18 @@ func (overlayWhiteoutConverter) ConvertWrite(hdr *tar.Header, path string, fi os
3536
}
3637

3738
if fi.Mode()&os.ModeDir != 0 {
39+
opaqueXattrName := "trusted.overlay.opaque"
40+
if userns.RunningInUserNS() {
41+
opaqueXattrName = "user.overlay.opaque"
42+
}
43+
3844
// convert opaque dirs to AUFS format by writing an empty file with the prefix
39-
opaque, err := system.Lgetxattr(path, "trusted.overlay.opaque")
45+
opaque, err := system.Lgetxattr(path, opaqueXattrName)
4046
if err != nil {
4147
return nil, err
4248
}
4349
if len(opaque) == 1 && opaque[0] == 'y' {
44-
delete(hdr.PAXRecords, paxSchilyXattr+"trusted.overlay.opaque")
50+
delete(hdr.PAXRecords, paxSchilyXattr+opaqueXattrName)
4551

4652
// create a header for the whiteout file
4753
// it should inherit some properties from the parent, but be a regular file
@@ -69,9 +75,14 @@ func (c overlayWhiteoutConverter) ConvertRead(hdr *tar.Header, path string) (boo
6975

7076
// if a directory is marked as opaque by the AUFS special file, we need to translate that to overlay
7177
if base == WhiteoutOpaqueDir {
72-
err := unix.Setxattr(dir, "trusted.overlay.opaque", []byte{'y'}, 0)
78+
opaqueXattrName := "trusted.overlay.opaque"
79+
if userns.RunningInUserNS() {
80+
opaqueXattrName = "user.overlay.opaque"
81+
}
82+
83+
err := unix.Setxattr(dir, opaqueXattrName, []byte{'y'}, 0)
7384
if err != nil {
74-
return false, errors.Wrapf(err, "setxattr(%q, trusted.overlay.opaque=y)", dir)
85+
return false, errors.Wrapf(err, "setxattr(%q, %s=y)", dir, opaqueXattrName)
7586
}
7687
// don't write the file itself
7788
return false, err

0 commit comments

Comments
 (0)