From 2fdfd564c180e01abe40463b6b6107f9ee2e1cf9 Mon Sep 17 00:00:00 2001 From: Ye Sijun Date: Thu, 23 Jun 2022 00:43:52 +0800 Subject: [PATCH] make xattr EPERM non-fatal in createTarFile Signed-off-by: Ye Sijun (cherry picked from commit 68a55fe8bdba268d0ccb301cee8a085958bf9275) Signed-off-by: Phil Estes --- archive/tar.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/archive/tar.go b/archive/tar.go index a57074e7714b..44b794953133 100644 --- a/archive/tar.go +++ b/archive/tar.go @@ -120,6 +120,8 @@ const ( whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq" paxSchilyXattr = "SCHILY.xattr." + + userXattrPrefix = "user." ) // Apply applies a tar stream of an OCI style diff tar. @@ -393,11 +395,19 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header if strings.HasPrefix(key, paxSchilyXattr) { key = key[len(paxSchilyXattr):] if err := setxattr(path, key, value); err != nil { + if errors.Is(err, syscall.EPERM) && strings.HasPrefix(key, userXattrPrefix) { + // In the user.* namespace, only regular files and directories can have extended attributes. + // See https://man7.org/linux/man-pages/man7/xattr.7.html for details. + if fi, err := os.Lstat(path); err == nil && (!fi.Mode().IsRegular() && !fi.Mode().IsDir()) { + log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key) + continue + } + } if errors.Is(err, syscall.ENOTSUP) { log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key) continue } - return err + return fmt.Errorf("failed to setxattr %q for key %q: %w", path, key, err) } } }