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

feat: add debug information to cert validation error #2579

Merged
merged 1 commit into from
Dec 28, 2022
Merged
Changes from all 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
11 changes: 7 additions & 4 deletions pkg/cosign/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ func CheckCertificatePolicy(cert *x509.Certificate, co *CheckOpts) error {
return err
}
oidcIssuer := ce.GetIssuer()
sans := getSubjectAlternateNames(cert)
// If there are identities given, go through them and if one of them
// matches, call that good, otherwise, return an error.
if len(co.Identities) > 0 {
Expand Down Expand Up @@ -303,14 +304,14 @@ func CheckCertificatePolicy(cert *x509.Certificate, co *CheckOpts) error {
if err != nil {
return fmt.Errorf("malformed subject in identity: %s : %w", identity.SubjectRegExp, err)
}
for _, san := range getSubjectAlternateNames(cert) {
for _, san := range sans {
if regex.MatchString(san) {
subjectMatches = true
break
}
}
case identity.Subject != "":
for _, san := range getSubjectAlternateNames(cert) {
for _, san := range sans {
if san == identity.Subject {
subjectMatches = true
break
Expand All @@ -321,11 +322,13 @@ func CheckCertificatePolicy(cert *x509.Certificate, co *CheckOpts) error {
subjectMatches = true
}
if subjectMatches && issuerMatches {
// If both issuer / subject match, return verifier
// If both issuer / subject match, return verified
return nil
}
}
return &VerificationError{"none of the expected identities matched what was in the certificate"}
return &VerificationError{
fmt.Sprintf("none of the expected identities matched what was in the certificate, got subjects [%s] with issuer %s",
strings.Join(sans, ", "), oidcIssuer)}
}
return nil
}
Expand Down