Skip to content

Commit 692e442

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 692e442

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/diff/diff.go

Lines changed: 16 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,21 @@ 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+
//nolint:staticcheck // SA1019: hdr.Xattrs has been deprecated since Go 1.10: Use PAXRecords instead.
706+
for k := range hdr.Xattrs {
707+
if strings.HasPrefix(k, "security.") {
708+
log.G(ctx).Debugf("Ignoring xattr %q", k)
709+
delete(hdr.Xattrs, k)
710+
}
711+
}
712+
for k := range hdr.PAXRecords {
713+
if strings.HasPrefix(k, "SCHILY.xattr.security.") {
714+
log.G(ctx).Debugf("Ignoring PAX record %q", k)
715+
delete(hdr.PAXRecords, k)
716+
}
717+
}
718+
}
703719
res.entries++
704720
ent := &TarEntry{
705721
Index: i,

0 commit comments

Comments
 (0)