-
Notifications
You must be signed in to change notification settings - Fork 566
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: cert-extensions verify #1626
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -48,22 +48,27 @@ import ( | |||
// nolint | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also need to update:
And also update where cosign/cmd/cosign/cli/verify.go Line 260 in 03e66aa
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you, I missed those parts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for updating these! |
||||
type VerifyCommand struct { | ||||
options.RegistryOptions | ||||
CheckClaims bool | ||||
KeyRef string | ||||
CertRef string | ||||
CertEmail string | ||||
CertOidcIssuer string | ||||
CertChain string | ||||
EnforceSCT bool | ||||
Sk bool | ||||
Slot string | ||||
Output string | ||||
RekorURL string | ||||
Attachment string | ||||
Annotations sigs.AnnotationsMap | ||||
SignatureRef string | ||||
HashAlgorithm crypto.Hash | ||||
LocalImage bool | ||||
CheckClaims bool | ||||
KeyRef string | ||||
CertRef string | ||||
CertEmail string | ||||
CertOidcIssuer string | ||||
CertGithubWorkflowTrigger string | ||||
CertGithubWorkflowSha string | ||||
CertGithubWorkflowName string | ||||
CertGithubWorkflowRepository string | ||||
CertGithubWorkflowRef string | ||||
CertChain string | ||||
EnforceSCT bool | ||||
Sk bool | ||||
Slot string | ||||
Output string | ||||
RekorURL string | ||||
Attachment string | ||||
Annotations sigs.AnnotationsMap | ||||
SignatureRef string | ||||
HashAlgorithm crypto.Hash | ||||
LocalImage bool | ||||
} | ||||
|
||||
// Exec runs the verification command | ||||
|
@@ -92,12 +97,17 @@ func (c *VerifyCommand) Exec(ctx context.Context, images []string) (err error) { | |||
return fmt.Errorf("constructing client options: %w", err) | ||||
} | ||||
co := &cosign.CheckOpts{ | ||||
Annotations: c.Annotations.Annotations, | ||||
RegistryClientOpts: ociremoteOpts, | ||||
CertEmail: c.CertEmail, | ||||
CertOidcIssuer: c.CertOidcIssuer, | ||||
EnforceSCT: c.EnforceSCT, | ||||
SignatureRef: c.SignatureRef, | ||||
Annotations: c.Annotations.Annotations, | ||||
RegistryClientOpts: ociremoteOpts, | ||||
CertEmail: c.CertEmail, | ||||
CertOidcIssuer: c.CertOidcIssuer, | ||||
CertGithubWorkflowTrigger: c.CertGithubWorkflowTrigger, | ||||
CertGithubWorkflowSha: c.CertGithubWorkflowSha, | ||||
CertGithubWorkflowName: c.CertGithubWorkflowName, | ||||
CertGithubWorkflowRepository: c.CertGithubWorkflowRepository, | ||||
CertGithubWorkflowRef: c.CertGithubWorkflowRef, | ||||
EnforceSCT: c.EnforceSCT, | ||||
SignatureRef: c.SignatureRef, | ||||
} | ||||
if c.CheckClaims { | ||||
co.ClaimVerifier = cosign.SimpleClaimVerifier | ||||
|
@@ -239,10 +249,30 @@ func PrintVerification(imgRef string, verified []oci.Signature, output string) { | |||
case "text": | ||||
for _, sig := range verified { | ||||
if cert, err := sig.Cert(); err == nil && cert != nil { | ||||
ce := cosign.CertExtensions{Cert: cert} | ||||
fmt.Fprintln(os.Stderr, "Certificate subject: ", sigs.CertSubject(cert)) | ||||
if issuerURL := sigs.CertIssuerExtension(cert); issuerURL != "" { | ||||
if issuerURL := ce.GetIssuer(); issuerURL != "" { | ||||
fmt.Fprintln(os.Stderr, "Certificate issuer URL: ", issuerURL) | ||||
} | ||||
|
||||
if githubWorkflowTrigger := ce.GetCertExtensionGithubWorkflowTrigger(); githubWorkflowTrigger != "" { | ||||
fmt.Fprintln(os.Stderr, "Certificate extension GitHub Workflow Trigger:", githubWorkflowTrigger) | ||||
} | ||||
|
||||
if githubWorkflowSha := ce.GetExtensionGithubWorkflowSha(); githubWorkflowSha != "" { | ||||
fmt.Fprintln(os.Stderr, "Certificate extension GitHub Workflow SHA:", githubWorkflowSha) | ||||
} | ||||
if githubWorkflowName := ce.GetCertExtensionGithubWorkflowName(); githubWorkflowName != "" { | ||||
fmt.Fprintln(os.Stderr, "Certificate extension GitHub Workflow Name:", githubWorkflowName) | ||||
} | ||||
|
||||
if githubWorkflowRepository := ce.GetCertExtensionGithubWorkflowRepository(); githubWorkflowRepository != "" { | ||||
fmt.Fprintln(os.Stderr, "Certificate extension GitHub Workflow Trigger", githubWorkflowRepository) | ||||
} | ||||
|
||||
if githubWorkflowRef := ce.GetCertExtensionGithubWorkflowRef(); githubWorkflowRef != "" { | ||||
fmt.Fprintln(os.Stderr, "Certificate extension GitHub Workflow Ref:", githubWorkflowRef) | ||||
} | ||||
} | ||||
|
||||
p, err := sig.Payload() | ||||
|
@@ -269,13 +299,32 @@ func PrintVerification(imgRef string, verified []oci.Signature, output string) { | |||
} | ||||
|
||||
if cert, err := sig.Cert(); err == nil && cert != nil { | ||||
ce := cosign.CertExtensions{Cert: cert} | ||||
if ss.Optional == nil { | ||||
ss.Optional = make(map[string]interface{}) | ||||
} | ||||
ss.Optional["Subject"] = sigs.CertSubject(cert) | ||||
if issuerURL := sigs.CertIssuerExtension(cert); issuerURL != "" { | ||||
if issuerURL := ce.GetIssuer(); issuerURL != "" { | ||||
ss.Optional["Issuer"] = issuerURL | ||||
} | ||||
if githubWorkflowTrigger := ce.GetCertExtensionGithubWorkflowTrigger(); githubWorkflowTrigger != "" { | ||||
ss.Optional[cosign.CertExtensionGithubWorkflowTrigger] = githubWorkflowTrigger | ||||
} | ||||
|
||||
if githubWorkflowSha := ce.GetExtensionGithubWorkflowSha(); githubWorkflowSha != "" { | ||||
ss.Optional[cosign.CertExtensionGithubWorkflowSha] = githubWorkflowSha | ||||
} | ||||
if githubWorkflowName := ce.GetCertExtensionGithubWorkflowName(); githubWorkflowName != "" { | ||||
ss.Optional[cosign.CertExtensionGithubWorkflowName] = githubWorkflowName | ||||
} | ||||
|
||||
if githubWorkflowRepository := ce.GetCertExtensionGithubWorkflowRepository(); githubWorkflowRepository != "" { | ||||
ss.Optional[cosign.CertExtensionGithubWorkflowRepository] = githubWorkflowRepository | ||||
} | ||||
|
||||
if githubWorkflowRef := ce.GetCertExtensionGithubWorkflowRef(); githubWorkflowRef != "" { | ||||
ss.Optional[cosign.CertExtensionGithubWorkflowRef] = githubWorkflowRef | ||||
} | ||||
} | ||||
if bundle, err := sig.Bundle(); err == nil && bundle != nil { | ||||
if ss.Optional == nil { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to update
VerifyAttestation
with the new verify options, on line 185There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch @haydentherapper as always