Skip to content

Commit 9e2f28c

Browse files
authored
util/image: unset PAXRecords and Xattrs when applying files (#1823)
Signed-off-by: Joe Lanford <[email protected]>
1 parent a6de9f9 commit 9e2f28c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

internal/shared/util/image/filters.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func forceOwnershipRWX() archive.Filter {
2323
h.Uid = uid
2424
h.Gid = gid
2525
h.Mode |= 0700
26+
h.PAXRecords = nil
27+
h.Xattrs = nil //nolint:staticcheck
2628
return true, nil
2729
}
2830
}

internal/shared/util/image/filters_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,39 @@ package image
22

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

78
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
"k8s.io/apimachinery/pkg/util/rand"
811
)
912

13+
func TestForceOwnershipRWX(t *testing.T) {
14+
h := tar.Header{
15+
Name: "foo/bar",
16+
Mode: 0000,
17+
Uid: rand.Int(),
18+
Gid: rand.Int(),
19+
Xattrs: map[string]string{ //nolint:staticcheck
20+
"foo": "bar",
21+
},
22+
PAXRecords: map[string]string{
23+
"fizz": "buzz",
24+
},
25+
}
26+
ok, err := forceOwnershipRWX()(&h)
27+
require.NoError(t, err)
28+
assert.True(t, ok)
29+
30+
assert.Equal(t, "foo/bar", h.Name)
31+
assert.Equal(t, int64(0700), h.Mode)
32+
assert.Equal(t, os.Getuid(), h.Uid)
33+
assert.Equal(t, os.Getgid(), h.Gid)
34+
assert.Nil(t, h.PAXRecords)
35+
assert.Nil(t, h.Xattrs) //nolint:staticcheck
36+
}
37+
1038
func TestOnlyPath(t *testing.T) {
1139
type testCase struct {
1240
name string

0 commit comments

Comments
 (0)