Skip to content

Commit

Permalink
util/image: unset PAXRecords and Xattrs when applying files
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Lanford <[email protected]>
  • Loading branch information
joelanford committed Feb 28, 2025
1 parent a6de9f9 commit 83cf868
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/shared/util/image/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func forceOwnershipRWX() archive.Filter {
h.Uid = uid
h.Gid = gid
h.Mode |= 0700
h.PAXRecords = nil
h.Xattrs = nil //nolint:staticcheck
return true, nil
}
}
Expand Down
28 changes: 28 additions & 0 deletions internal/shared/util/image/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,39 @@ package image

import (
"archive/tar"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/util/rand"
)

func TestForceOwnershipRWX(t *testing.T) {
h := tar.Header{
Name: "foo/bar",
Mode: 0000,
Uid: rand.Int(),
Gid: rand.Int(),
Xattrs: map[string]string{ //nolint:staticcheck
"foo": "bar",
},
PAXRecords: map[string]string{
"fizz": "buzz",
},
}
ok, err := forceOwnershipRWX()(&h)
require.NoError(t, err)
assert.True(t, ok)

assert.Equal(t, "foo/bar", h.Name)
assert.Equal(t, int64(0700), h.Mode)
assert.Equal(t, os.Getuid(), h.Uid)
assert.Equal(t, os.Getgid(), h.Gid)
assert.Nil(t, h.PAXRecords)
assert.Nil(t, h.Xattrs) //nolint:staticcheck
}

func TestOnlyPath(t *testing.T) {
type testCase struct {
name string
Expand Down

0 comments on commit 83cf868

Please sign in to comment.