Skip to content

Commit 3de199d

Browse files
committed
UPSTREAM: <drop>: internal/source: unset PAXRecords and Xattrs when applying files
1 parent 07003f5 commit 3de199d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

internal/source/containers_image.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ func applyLayerFilter(srcPath string) archive.Filter {
337337
h.Uid = os.Getuid()
338338
h.Gid = os.Getgid()
339339
h.Mode |= 0700
340+
h.PAXRecords = nil
341+
h.Xattrs = nil //nolint:staticcheck
340342

341343
cleanName := path.Clean(strings.TrimPrefix(h.Name, "/"))
342344
relPath, err := filepath.Rel(cleanSrcPath, cleanName)

internal/source/containers_image_internal_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package source
22

33
import (
44
"archive/tar"
5+
"os"
56
"testing"
67

78
"github.com/stretchr/testify/assert"
9+
"k8s.io/apimachinery/pkg/util/rand"
810
)
911

1012
func TestContainersImage_applyLayerFilter(t *testing.T) {
@@ -116,6 +118,34 @@ func TestContainersImage_applyLayerFilter(t *testing.T) {
116118
assert.NoError(t, err)
117119
},
118120
},
121+
{
122+
name: "correctly sets permissions, uid/gid, and file attributes",
123+
srcPaths: []string{"foo"},
124+
tarHeaders: []tar.Header{
125+
{
126+
Name: "foo/bar",
127+
Mode: 0000,
128+
Uid: rand.Int(),
129+
Gid: rand.Int(),
130+
Xattrs: map[string]string{ //nolint:staticcheck
131+
"foo": "bar",
132+
},
133+
PAXRecords: map[string]string{
134+
"fizz": "buzz",
135+
},
136+
},
137+
},
138+
assertion: func(tarHeader *tar.Header, keep bool, err error) {
139+
assert.True(t, keep)
140+
assert.NoError(t, err)
141+
assert.Equal(t, "foo/bar", tarHeader.Name)
142+
assert.Equal(t, int64(0700), tarHeader.Mode)
143+
assert.Equal(t, os.Getuid(), tarHeader.Uid)
144+
assert.Equal(t, os.Getgid(), tarHeader.Gid)
145+
assert.Nil(t, tarHeader.PAXRecords)
146+
assert.Nil(t, tarHeader.Xattrs) //nolint:staticcheck
147+
},
148+
},
119149
} {
120150
t.Run(tc.name, func(t *testing.T) {
121151
for _, srcPath := range tc.srcPaths {

0 commit comments

Comments
 (0)