Skip to content

Commit

Permalink
fix(mutate): also set timestamps only present in some formats (#1550)
Browse files Browse the repository at this point in the history
Currently, layerTime only mutates the modification timestamp which is
present in all tar formats. When working with layers GNU or PAX header
formats, access and change timestamps are also generated/recorded. This
breaks functionality like reproducible builds which rely on having
control over all variable fields (esp. timestamps)  in the layers

This commit adds a special case to the layerTime(Layer, Time) function
which will also set the additional timestamps if the header is of GNU or
PAX format

Signed-off-by: Joel Pepper <pepper@bronze-deer.de>
  • Loading branch information
BronzeDeer committed Feb 1, 2023
1 parent 061ee6b commit 824efc7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/v1/mutate/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,13 @@ func layerTime(layer v1.Layer, t time.Time) (v1.Layer, error) {
}

header.ModTime = t

//PAX and GNU Format support additional timestamps in the header
if header.Format == tar.FormatPAX || header.Format == tar.FormatGNU {
header.AccessTime = t
header.ChangeTime = t
}

if err := tarWriter.WriteHeader(header); err != nil {
return nil, fmt.Errorf("writing tar header: %w", err)
}
Expand Down

0 comments on commit 824efc7

Please sign in to comment.