Skip to content

Commit d3f3c36

Browse files
committed
Add --ca-intermediates flag
Add --ca-intermediates flag to enable to pass a PEM file with intermediate CA certificates. One can use either --ca-roots, optionally together with --ca-intermediates - or --certificate-chain, which contains zero, one or several intermediate CA certificate followed by the root CA certificate. Expand the helper Go program test/gencert/main.go to allow to generate root and intermediate CA certificates, and a certificate signed by the intermediate CA. Expand the functional test e2e_tsa_certbundle.sh to test the --ca-intermediates flag (together with --ca-roots). Fixed sigstore#3462. Signed-off-by: Dmitry S <dsavints@gmail.com>
1 parent e98ab7a commit d3f3c36

13 files changed

+170
-77
lines changed

cmd/cosign/cli/options/certificate.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type CertVerifyOptions struct {
3333
CertGithubWorkflowName string
3434
CertGithubWorkflowRepository string
3535
CertGithubWorkflowRef string
36+
CAIntermediates string
3637
CARoots string
3738
CertChain string
3839
SCT string
@@ -76,6 +77,10 @@ func (o *CertVerifyOptions) AddFlags(cmd *cobra.Command) {
7677
cmd.Flags().StringVar(&o.CertGithubWorkflowRef, "certificate-github-workflow-ref", "",
7778
"contains the ref claim from the GitHub OIDC Identity token that contains the git ref that the workflow run was based upon.")
7879
// -- Cert extensions end --
80+
cmd.Flags().StringVar(&o.CAIntermediates, "ca-intermediates", "",
81+
"path to a file of intermediate CA certificates in PEM format which will be needed "+
82+
"when building the certificate chains for the signing certificate. Conflicts with --certificate-chain.")
83+
_ = cmd.Flags().SetAnnotation("ca-intermediates", cobra.BashCompFilenameExt, []string{"cert"})
7984
cmd.Flags().StringVar(&o.CARoots, "ca-roots", "",
8085
"path to a bundle file of CA certificates in PEM format which will be needed "+
8186
"when building the certificate chains for the signing certificate. Conflicts with --certificate-chain.")
@@ -85,9 +90,10 @@ func (o *CertVerifyOptions) AddFlags(cmd *cobra.Command) {
8590
"path to a list of CA certificates in PEM format which will be needed "+
8691
"when building the certificate chain for the signing certificate. "+
8792
"Must start with the parent intermediate CA certificate of the "+
88-
"signing certificate and end with the root certificate. Conflicts with --ca-roots.")
93+
"signing certificate and end with the root certificate. Conflicts with --ca-roots and --ca-intermediates.")
8994
_ = cmd.Flags().SetAnnotation("certificate-chain", cobra.BashCompFilenameExt, []string{"cert"})
9095
cmd.MarkFlagsMutuallyExclusive("ca-roots", "certificate-chain")
96+
cmd.MarkFlagsMutuallyExclusive("ca-intermediates", "certificate-chain")
9197

9298
cmd.Flags().StringVar(&o.SCT, "sct", "",
9399
"path to a detached Signed Certificate Timestamp, formatted as a RFC6962 AddChainResponse struct. "+

cmd/cosign/cli/verify.go

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ against the transparency log.`,
6262
# verify image with local certificate and certificate chain
6363
cosign verify --cert cosign.crt --cert-chain chain.crt <IMAGE>
6464
65+
# verify image with local certificate and certificate bundles of CA roots
66+
# and (optionally) CA intermediates
67+
cosign verify --cert cosign.crt --ca-roots ca-roots.pem --ca-intermediates ca-intermediates.pem <IMAGE>
68+
6569
# verify image using keyless verification with the given certificate
6670
# chain and identity parameters, without Fulcio roots (for BYO PKI):
6771
cosign verify --cert-chain chain.crt --certificate-oidc-issuer https://issuer.example.com --certificate-identity foo@example.com <IMAGE>
@@ -115,6 +119,7 @@ against the transparency log.`,
115119
CertGithubWorkflowName: o.CertVerify.CertGithubWorkflowName,
116120
CertGithubWorkflowRepository: o.CertVerify.CertGithubWorkflowRepository,
117121
CertGithubWorkflowRef: o.CertVerify.CertGithubWorkflowRef,
122+
CAIntermediates: o.CertVerify.CAIntermediates,
118123
CARoots: o.CertVerify.CARoots,
119124
CertChain: o.CertVerify.CertChain,
120125
IgnoreSCT: o.CertVerify.IgnoreSCT,

cmd/cosign/cli/verify/verify.go

+13
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type VerifyCommand struct {
6060
CertGithubWorkflowName string
6161
CertGithubWorkflowRepository string
6262
CertGithubWorkflowRef string
63+
CAIntermediates string
6364
CARoots string
6465
CertChain string
6566
CertOidcProvider string
@@ -206,6 +207,18 @@ func (c *VerifyCommand) Exec(ctx context.Context, images []string) (err error) {
206207
co.RootCerts.AddCert(cert)
207208
}
208209
}
210+
if c.CAIntermediates != "" {
211+
caIntermediates, err := loadCertChainFromFileOrURL(c.CAIntermediates)
212+
if err != nil {
213+
return err
214+
}
215+
if len(caIntermediates) > 0 {
216+
co.IntermediateCerts = x509.NewCertPool()
217+
for _, cert := range caIntermediates {
218+
co.IntermediateCerts.AddCert(cert)
219+
}
220+
}
221+
}
209222
}
210223
default:
211224
{

doc/cosign_dockerfile_verify.md

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_manifest_verify.md

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_verify-attestation.md

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_verify-blob-attestation.md

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_verify-blob.md

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_verify.md

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)