From fc29e2e295e62833085fc2bff7a578cc15bf6a88 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Fri, 22 Mar 2024 21:47:54 +0000 Subject: [PATCH] fix: handle overlay xattr opaque bit Current behavior determines if a path is a whiteout if a overlay char dev is present. Additionally, also check the extended attrs. Signed-off-by: Ramkumar Chinchani --- go.mod | 1 + go.sum | 3 +++ oci/layer/generate.go | 4 ++-- oci/layer/utils.go | 19 ++++++++++++++++--- vendor/modules.txt | 3 +++ 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index e6f756cac..9800c37d5 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/opencontainers/runc v1.1.8 github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 github.com/pkg/errors v0.9.1 + github.com/pkg/xattr v0.4.9 github.com/rootless-containers/proto/go-proto v0.0.0-20230421021042-4cd87ebadd67 github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.12 diff --git a/go.sum b/go.sum index 5f4278b7a..7beb3929e 100644 --- a/go.sum +++ b/go.sum @@ -72,6 +72,8 @@ github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417/go.m github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/xattr v0.4.9 h1:5883YPCtkSd8LFbs13nXplj9g9tlrwoJRjgpgMu1/fE= +github.com/pkg/xattr v0.4.9/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6ktU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= @@ -123,6 +125,7 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/oci/layer/generate.go b/oci/layer/generate.go index a231d2ea4..32ba48354 100644 --- a/oci/layer/generate.go +++ b/oci/layer/generate.go @@ -88,7 +88,7 @@ func GenerateLayer(path string, deltas []mtree.InodeDelta, opt *RepackOptions) ( return errors.Wrapf(err, "couldn't determine overlay whiteout for %s", fullPath) } - whiteout, err := isOverlayWhiteout(fi) + whiteout, err := isOverlayWhiteout(fi, fullPath) if err != nil { return err } @@ -166,7 +166,7 @@ func GenerateInsertLayer(root string, target string, opaque bool, opt *RepackOpt } pathInTar := path.Join(target, curPath[len(root):]) - whiteout, err := isOverlayWhiteout(info) + whiteout, err := isOverlayWhiteout(info, filepath.Join(curPath, info.Name())) if err != nil { return err } diff --git a/oci/layer/utils.go b/oci/layer/utils.go index f22122f78..15daf8629 100644 --- a/oci/layer/utils.go +++ b/oci/layer/utils.go @@ -19,6 +19,7 @@ package layer import ( "archive/tar" + "fmt" "os" "path/filepath" "syscall" @@ -27,6 +28,7 @@ import ( rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/umoci/pkg/idtools" "github.com/pkg/errors" + "github.com/pkg/xattr" rootlesscontainers "github.com/rootless-containers/proto/go-proto" "golang.org/x/sys/unix" "google.golang.org/protobuf/proto" @@ -230,7 +232,7 @@ func InnerErrno(err error) error { // isOverlayWhiteout returns true if the FileInfo represents an overlayfs style // whiteout (i.e. mknod c 0 0) and false otherwise. -func isOverlayWhiteout(info os.FileInfo) (bool, error) { +func isOverlayWhiteout(info os.FileInfo, path string) (bool, error) { var major, minor uint32 switch stat := info.Sys().(type) { case *unix.Stat_t: @@ -243,6 +245,17 @@ func isOverlayWhiteout(info os.FileInfo) (bool, error) { return false, errors.Errorf("[internal error] unknown stat info type %T", info.Sys()) } - return major == 0 && minor == 0 && - info.Mode()&os.ModeCharDevice != 0, nil + if major == 0 && minor == 0 && + info.Mode()&os.ModeCharDevice != 0 { + return true, nil + } + + attr, err := xattr.LGet("user.overlay.opaque", path) + if err != nil && !errors.Is(err, os.ErrNotExist) { + return false, errors.Errorf("[internal error] failed to get extended attrs for %s, err:%v", path, err) + } + + fmt.Printf("ATTR=%+v\n", attr) + + return false, nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index 7afd4c289..aa5c7d0cb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -63,6 +63,9 @@ github.com/opencontainers/runtime-spec/specs-go # github.com/pkg/errors v0.9.1 ## explicit github.com/pkg/errors +# github.com/pkg/xattr v0.4.9 +## explicit; go 1.14 +github.com/pkg/xattr # github.com/pmezard/go-difflib v1.0.0 ## explicit github.com/pmezard/go-difflib/difflib