Skip to content

Commit

Permalink
feat: adds no cert found on sig exit code (#3038)
Browse files Browse the repository at this point in the history
Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com>
  • Loading branch information
ChrisJBurns committed Jun 9, 2023
1 parent f4f319b commit d0cc985
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions cmd/cosign/errors/exit_code_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func LookupExitCodeForError(err interface{ error }) int {
return ImageWithoutSignature
}

if noCertificateFoundOnSignature(err) {
return NoCertificateFoundOnSignature
}

// we want to return exit code = `1` at this point because there is
// no valid exit code found for the error type passed, so we default to 1.
return 1
Expand All @@ -53,3 +57,8 @@ func noSignaturesFoundError(err interface{ error }) bool {
var errNoSignaturesFound *cosignError.ErrNoSignaturesFound
return errors.As(err, &errNoSignaturesFound)
}

func noCertificateFoundOnSignature(err interface{ error }) bool {
var errNoCertificateFoundOnSignature *cosignError.ErrNoCertificateFoundOnSignature
return errors.As(err, &errNoCertificateFoundOnSignature)
}
3 changes: 3 additions & 0 deletions cmd/cosign/errors/exit_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ const NonExistentTag = 11

// Error verifying image due to no matching signature
const NoMatchingSignature = 12

// Error verifying image due to no certificate found on signature
const NoCertificateFoundOnSignature = 13
1 change: 1 addition & 0 deletions doc/cosign_exit_codes.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/cosign/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ type ErrNoMatchingAttestations struct {
func (e *ErrNoMatchingAttestations) Error() string {
return e.err.Error()
}

type ErrNoCertificateFoundOnSignature struct {
err error
}

func (e *ErrNoCertificateFoundOnSignature) Error() string {
return e.err.Error()
}
3 changes: 1 addition & 2 deletions pkg/cosign/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,7 @@ func verifyInternal(ctx context.Context, sig oci.Signature, h v1.Hash,
return false, err
}
if cert == nil {
// TODO: add error type instead of blank string
return false, ThrowError(&VerificationFailure{
return false, ThrowError(&ErrNoCertificateFoundOnSignature{
fmt.Errorf("no certificate found on signature"),
})
}
Expand Down

0 comments on commit d0cc985

Please sign in to comment.