diff --git a/pkg/oci/mutate/signatures.go b/pkg/oci/mutate/signatures.go index 53f750d9e03..f5c24e92a10 100644 --- a/pkg/oci/mutate/signatures.go +++ b/pkg/oci/mutate/signatures.go @@ -16,6 +16,8 @@ package mutate import ( + "time" + v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/empty" "github.com/google/go-containerregistry/pkg/v1/mutate" @@ -36,10 +38,18 @@ func AppendSignatures(base oci.Signatures, sigs ...oci.Signature) (oci.Signature Annotations: ann, }) } + img, err := mutate.Append(base, adds...) if err != nil { return nil, err } + + // Set the Created date to time of execution + img, err = mutate.CreatedAt(img, v1.Time{Time: time.Now()}) + if err != nil { + return nil, err + } + return &sigAppender{ Image: img, base: base, diff --git a/pkg/oci/mutate/signatures_test.go b/pkg/oci/mutate/signatures_test.go index 14978ce7834..c1f0de9aa3a 100644 --- a/pkg/oci/mutate/signatures_test.go +++ b/pkg/oci/mutate/signatures_test.go @@ -70,4 +70,10 @@ func TestAppendSignatures(t *testing.T) { } else if got, want := len(sl), 3; got != want { t.Errorf("len(Get()) = %d, wanted %d", got, want) } + + if testCfg, err := threeSig.ConfigFile(); err != nil { + t.Fatalf("ConfigFile() = %v", err) + } else if testCfg.Created.Time.IsZero() { + t.Errorf("Date of Signature was Zero") + } } diff --git a/pkg/oci/static/file.go b/pkg/oci/static/file.go index 270b5a6b763..d1d895bdb66 100644 --- a/pkg/oci/static/file.go +++ b/pkg/oci/static/file.go @@ -17,6 +17,7 @@ package static import ( "io" + "time" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/empty" @@ -44,6 +45,12 @@ func NewFile(payload []byte, opts ...Option) (oci.File, error) { if err != nil { return nil, err } + + // Set the Created date to time of execution + img, err = mutate.CreatedAt(img, v1.Time{Time: time.Now()}) + if err != nil { + return nil, err + } return &file{ SignedImage: signed.Image(img), layer: layer, diff --git a/pkg/oci/static/file_test.go b/pkg/oci/static/file_test.go index 8c074fbc7f8..c652a7a318d 100644 --- a/pkg/oci/static/file_test.go +++ b/pkg/oci/static/file_test.go @@ -120,4 +120,14 @@ func TestNewFile(t *testing.T) { t.Errorf("Payload() = %s, wanted %s", got, want) } }) + + t.Run("check date", func(t *testing.T) { + fileCfg, err := file.ConfigFile() + if err != nil { + t.Fatalf("ConfigFile() = %v", err) + } + if fileCfg.Created.Time.IsZero() { + t.Errorf("Date of Signature was Zero") + } + }) }