Skip to content

Commit

Permalink
Merge pull request #868 from saschagrunert/sign-recursive
Browse files Browse the repository at this point in the history
Use recursive signing for multi-arch images
  • Loading branch information
k8s-ci-robot authored May 17, 2023
2 parents 38c86b3 + 40076eb commit ec74d14
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions internal/promoter/image/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (di *DefaultPromoterImplementation) SignImages(
}
signOpts.IdentityToken = token

// We want to sign all entities for multi-arch images
signOpts.Recursive = true

// Creating a new Signer after setting the identity token is MANDATORY
// because that's the only way to propagate the identity token to the
// internal Signer structs. Without that, the identity token wouldn't be
Expand Down
4 changes: 4 additions & 0 deletions internal/promoter/image/signcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ func (di *DefaultPromoterImplementation) signReference(opts *options.Options, re
return fmt.Errorf("generating identity token: %w", err)
}
signOpts.IdentityToken = token

// We want to sign all entities for multi-arch images
signOpts.Recursive = true

di.signer = sign.New(signOpts)

// Add an annotation recording the kpromo version to ensure we
Expand Down
12 changes: 5 additions & 7 deletions test-e2e/cip/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,11 @@ func removeSignatureLayers(snapshot *[]registry.Image) {
var remove []image.Digest
for i := range *snapshot {
remove = []image.Digest{}
for dgst := range (*snapshot)[i].Dmap {
// Signature layers only have one tag
if len((*snapshot)[i].Dmap[dgst]) != 1 || !strings.HasSuffix(
string((*snapshot)[i].Dmap[dgst][0]), ".sig",
) {
continue
for dgst, tags := range (*snapshot)[i].Dmap {
if len(tags) == 0 || // Recursive signing may add additional layers without tags
(len(tags) == 1 && strings.HasSuffix(string(tags[0]), ".sig")) { // Signature layers only have one tag
remove = append(remove, dgst)
}
remove = append(remove, dgst)
}
for _, dgst := range remove {
delete((*snapshot)[i].Dmap, dgst)
Expand All @@ -152,6 +149,7 @@ func checkSnapshot(
// to compare them, we remove the signature layers from the current
// snapshot to ensure the original images were promoted.
removeSignatureLayers(&got)
removeSignatureLayers(&expected)

diff := cmp.Diff(got, expected)
if diff != "" {
Expand Down

0 comments on commit ec74d14

Please sign in to comment.