Skip to content

Commit

Permalink
fix: allow cosign download sbom when image is absent (#3245)
Browse files Browse the repository at this point in the history
* fix: allow cosign download sbom when image is absent

Signed-off-by: Vishal Choudhary <[email protected]>

* fix: remove lint issue

Signed-off-by: Vishal Choudhary <[email protected]>

* fix: add errors.As

Signed-off-by: Vishal Choudhary <[email protected]>

* feat: added comments

Signed-off-by: Vishal Choudhary <[email protected]>

---------

Signed-off-by: Vishal Choudhary <[email protected]>
  • Loading branch information
vishal-chdhry authored Oct 17, 2023
1 parent da66fdd commit bb4715c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 12 additions & 1 deletion cmd/cosign/cli/download/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package download
import (
"context"
"encoding/json"
"errors"
"fmt"

"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -46,8 +47,18 @@ func AttestationCmd(ctx context.Context, regOpts options.RegistryOptions, attOpt
}

se, err := ociremote.SignedEntity(ref, ociremoteOpts...)
var entityNotFoundError *ociremote.EntityNotFoundError
if err != nil {
return err
if errors.As(err, &entityNotFoundError) {
if digest, ok := ref.(name.Digest); ok {
// We don't need to access the original image to download the attached attestation
se = ociremote.SignedUnknown(digest)
} else {
return err
}
} else {
return err
}
}

se, err = platform.SignedEntityForPlatform(se, attOptions.Platform)
Expand Down
12 changes: 11 additions & 1 deletion cmd/cosign/cli/download/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,18 @@ func SBOMCmd(
}

se, err := ociremote.SignedEntity(ref, ociremoteOpts...)
var entityNotFoundError *ociremote.EntityNotFoundError
if err != nil {
return nil, err
if errors.As(err, &entityNotFoundError) {
// We don't need to access the original image to download the attached sbom
if digest, ok := ref.(name.Digest); ok {
se = ociremote.SignedUnknown(digest)
} else {
return nil, err
}
} else {
return nil, err
}
}

se, err = platform.SignedEntityForPlatform(se, dnOpts.Platform)
Expand Down

0 comments on commit bb4715c

Please sign in to comment.