Skip to content

Commit 3ac39b6

Browse files
committed
storage: strip env specific data during archive
This ensures the checksum is predictable, and not influenced by e.g. different runtime configuration settings, or FS specific data. Signed-off-by: Hidde Beydals <[email protected]>
1 parent d0560e5 commit 3ac39b6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

controllers/storage.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ func SourceIgnoreFilter(ps []gitignore.Pattern, domain []string) ArchiveFileFilt
161161
}
162162

163163
// Archive atomically archives the given directory as a tarball to the given v1beta1.Artifact path, excluding
164-
// directories and any ArchiveFileFilter matches.
164+
// directories and any ArchiveFileFilter matches. While archiving, any environment specific data (for example,
165+
// the user and group name) is stripped from file headers.
165166
// If successful, it sets the checksum and last update time on the artifact.
166167
func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter ArchiveFileFilter) (err error) {
167168
if f, err := os.Stat(dir); os.IsNotExist(err) || !f.IsDir() {
@@ -216,6 +217,16 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
216217
}
217218
header.Name = relFilePath
218219

220+
// We want to remove any environment specific data as well, this
221+
// ensures the checksum is purely content based.
222+
header.Gid = 0
223+
header.Uid = 0
224+
header.Uname = ""
225+
header.Gname = ""
226+
header.ModTime = time.Time{}
227+
header.AccessTime = time.Time{}
228+
header.ChangeTime = time.Time{}
229+
219230
if err := tw.WriteHeader(header); err != nil {
220231
return err
221232
}

0 commit comments

Comments
 (0)