From f5d022cda9eae625fb2b2a0ade0cbb433a9c48f9 Mon Sep 17 00:00:00 2001 From: Angel Misevski Date: Wed, 1 May 2024 11:16:45 -0400 Subject: [PATCH] Remove more fields from tar file headers Remove unnecessary fields from tar file headers to try to make tars reproducible. --- pkg/lib/storage/layer.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/lib/storage/layer.go b/pkg/lib/storage/layer.go index cd1ad02b..0cfc1ee7 100644 --- a/pkg/lib/storage/layer.go +++ b/pkg/lib/storage/layer.go @@ -165,9 +165,7 @@ func writeHeaderToTar(name string, fi os.FileInfo, tw *tar.Writer) error { return fmt.Errorf("failed to generate header for %s: %w", name, err) } header.Name = name - header.AccessTime = time.Time{} - header.ModTime = time.Time{} - header.ChangeTime = time.Time{} + sanitizeTarHeader(header) if err := tw.WriteHeader(header); err != nil { return fmt.Errorf("failed to write header: %w", err) } @@ -204,3 +202,13 @@ func removeTempFile(filepath string) { output.Errorf("Failed to clean up temporary file %s: %s", filepath, err) } } + +func sanitizeTarHeader(header *tar.Header) { + header.AccessTime = time.Time{} + header.ModTime = time.Time{} + header.ChangeTime = time.Time{} + header.Uid = 0 + header.Gid = 0 + header.Uname = "" + header.Gname = "" +}