-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't expose local account details in oci-archive tar files
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
- Loading branch information
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,45 @@ | ||
package archive | ||
|
||
import "github.com/containers/image/v5/internal/private" | ||
import ( | ||
"archive/tar" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/containers/image/v5/internal/private" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var _ private.ImageDestination = (*ociArchiveImageDestination)(nil) | ||
|
||
func TestTarDirectory(t *testing.T) { | ||
srcDir := t.TempDir() | ||
err := os.WriteFile(filepath.Join(srcDir, "regular"), []byte("contents"), 0o600) | ||
require.NoError(t, err) | ||
|
||
dest := filepath.Join(t.TempDir(), "file.tar") | ||
err = tarDirectory(srcDir, dest) | ||
require.NoError(t, err) | ||
|
||
f, err := os.Open(dest) | ||
require.NoError(t, err) | ||
defer f.Close() | ||
reader := tar.NewReader(f) | ||
numItems := 0 | ||
for { | ||
hdr, err := reader.Next() | ||
if err == io.EOF { | ||
break | ||
} | ||
require.NoError(t, err) | ||
// Test that the header does not expose data about the local account | ||
assert.Equal(t, 0, hdr.Uid) | ||
assert.Equal(t, 0, hdr.Gid) | ||
assert.Equal(t, "", hdr.Uname) | ||
assert.Equal(t, "", hdr.Gname) | ||
numItems++ | ||
} | ||
assert.Equal(t, 1, numItems) | ||
} |