Skip to content

Commit 6e86a83

Browse files
committed
Skip setting xattrs when running as non-root
To fix: ``` ERRO[0022] field "Layers[10]": failed to load layer (input-0): failed to setxattr "/tmp/r/93992c935cd0c3a219bf8a33e3c4fdd8bff42d4fd51a0067edcc68dc8596935b/diff/input-0/layers-10/usr/bin/newgidmap" for key "security.capability": operation not permitted ``` Signed-off-by: Akihiro Suda <[email protected]>
1 parent 8163257 commit 6e86a83

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/diff/diff.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"path"
1212
"path/filepath"
13+
"runtime"
1314
"slices"
1415
"sort"
1516
"strconv"
@@ -700,6 +701,20 @@ func (d *differ) loadLayer(ctx context.Context, node *EventTreeNode, inputIdx in
700701
hdr.Name = strings.TrimPrefix(hdr.Name, "/")
701702
hdr.Name = strings.TrimPrefix(hdr.Name, "./")
702703
}
704+
if os.Geteuid() != 0 && runtime.GOOS == "linux" {
705+
for k := range hdr.Xattrs {
706+
if strings.HasPrefix(k, "security.") {
707+
log.G(ctx).Debugf("Ignoring xattr %q", k)
708+
delete(hdr.Xattrs, k)
709+
}
710+
}
711+
for k := range hdr.PAXRecords {
712+
if strings.HasPrefix(k, "SCHILY.xattr.security.") {
713+
log.G(ctx).Debugf("Ignoring PAX record %q", k)
714+
delete(hdr.PAXRecords, k)
715+
}
716+
}
717+
}
703718
res.entries++
704719
ent := &TarEntry{
705720
Index: i,

0 commit comments

Comments
 (0)