Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow cosign download sbom when image is absent #3245

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 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,17 @@ 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 {
se = ociremote.SignedUnknown(digest)
} else {
return err
}
} else {
return err
}
}

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

se, err := ociremote.SignedEntity(ref, ociremoteOpts...)
var entityNotFoundError *ociremote.EntityNotFoundError
if err != nil {
return nil, err
if errors.As(err, &entityNotFoundError) {
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
Loading