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

Deprecate --certificate-email flag. Make --certificate-identity and -… #2411

Merged
merged 51 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
25e49e4
Deprecate --certificate-email flag. Make --certificate-identity and -…
kpk47 Nov 2, 2022
b7e1548
Make --cert-email and --cert-identity mutually exclusive
kpk47 Nov 3, 2022
8566156
Remove --certificate-email flag
kpk47 Nov 4, 2022
9602e9d
docgen
kpk47 Nov 4, 2022
21482bd
lint
kpk47 Nov 4, 2022
4f5d609
lint
kpk47 Nov 4, 2022
f223f6e
Enforce requiring --certificate-identity and --certificate-oidc-issue…
kpk47 Nov 4, 2022
e5e9636
Move argument checks to Exec() functions.
kpk47 Nov 7, 2022
8cc212f
Don't require cert-identity or cert-oidc-issuer in keyed mode
kpk47 Nov 7, 2022
12cae1c
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Nov 7, 2022
803a341
fix mismerge
kpk47 Nov 7, 2022
3babacb
Change e2e blob and attestation tests to use keys.
kpk47 Nov 9, 2022
4835f5f
Add workflow_dispatch trigger to attestation e2e tests
kpk47 Nov 9, 2022
3fc8332
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Nov 9, 2022
c21c197
fix e2e test
kpk47 Nov 9, 2022
902b53e
typo
kpk47 Nov 9, 2022
6c11e62
typo
kpk47 Nov 9, 2022
68ce699
debugging workflow
kpk47 Nov 10, 2022
032cc39
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Nov 10, 2022
5dd8f2b
fix attest e2e test
kpk47 Nov 10, 2022
357452f
fix attest e2e test
kpk47 Nov 10, 2022
35a21e5
removing debug print statements
kpk47 Nov 10, 2022
c4c04f2
test e2e keyless
kpk47 Nov 11, 2022
a545b14
remove flags to trigger error
kpk47 Nov 11, 2022
61de5bc
change sign_blob e2e test to use local bundles
kpk47 Nov 11, 2022
f30b015
Add tests for missing flags
kpk47 Nov 11, 2022
2f87646
typos
kpk47 Nov 11, 2022
d2a12a3
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Nov 11, 2022
1c84341
typos
kpk47 Nov 11, 2022
655fb48
Move error checking into CheckVerifyOptions
kpk47 Nov 12, 2022
fb1764a
unit test
kpk47 Nov 12, 2022
3a7b802
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Nov 15, 2022
b0a121d
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Nov 29, 2022
8bc1a06
Re-disable e2e sign-blob-test. It can't run on GHA
kpk47 Nov 29, 2022
cc2fc0e
debug verify attestation test
kpk47 Dec 1, 2022
7733f76
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Dec 16, 2022
a0857c1
Fix verify-attestation args
kpk47 Dec 16, 2022
2c59469
debug attestation
kpk47 Dec 16, 2022
15cfa8d
debug verify-blob args
kpk47 Dec 19, 2022
1f35b49
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Dec 19, 2022
858ee99
fix sign-blob integration test; remove debug print statements
kpk47 Dec 19, 2022
98e66d9
add regexp flags
kpk47 Dec 19, 2022
6868f71
docgen
kpk47 Dec 19, 2022
fc654cd
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Dec 20, 2022
f8431d9
update test cert and enable sign-blob e2e test
kpk47 Dec 21, 2022
034855f
Remove sign-blob e2e test from workflow. It requires human interaction
kpk47 Dec 21, 2022
a756b95
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Dec 21, 2022
45fd981
re-enable sign-blob e2e test using GH credentials
kpk47 Dec 21, 2022
04c940d
fix workflow permissions
kpk47 Dec 21, 2022
e84a33d
re-disable sign-blob tests. Changing workflow permissions didn't help
kpk47 Dec 21, 2022
820bf93
Merge branch 'main' of github.com:sigstore/cosign into flags
kpk47 Dec 21, 2022
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
13 changes: 7 additions & 6 deletions .github/workflows/kind-verify-attestation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ name: Test attest / verify-attestation
on:
pull_request:
branches: [ 'main', 'release-*' ]
workflow_dispatch:

defaults:
run:
Expand Down Expand Up @@ -118,12 +119,12 @@ jobs:

- name: Verify with cosign
run: |
./cosign verify --rekor-url ${{ env.REKOR_URL }} --allow-insecure-registry ${{ env.demoimage }}
./cosign verify --rekor-url ${{ env.REKOR_URL }} --allow-insecure-registry ${{ env.demoimage }} --certificate-identity https://kubernetes.io/namespaces/default/serviceaccounts/default --certificate-oidc-issuer "https://kubernetes.default.svc.cluster.local"

- name: Verify custom attestation with cosign, works
run: |
echo '::group:: test custom verify-attestation success'
if ! ./cosign verify-attestation --policy ./test/testdata/policies/cue-works.cue --rekor-url ${{ env.REKOR_URL }} --allow-insecure-registry ${{ env.demoimage }} ; then
if ! ./cosign verify-attestation --certificate-identity https://kubernetes.io/namespaces/default/serviceaccounts/default --certificate-oidc-issuer "https://kubernetes.default.svc.cluster.local" --policy ./test/testdata/policies/cue-works.cue --rekor-url ${{ env.REKOR_URL }} --allow-insecure-registry ${{ env.demoimage }} ; then
echo Failed to verify attestation with a valid policy
exit 1
else
Expand All @@ -134,7 +135,7 @@ jobs:
- name: Verify custom attestation with cosign, fails
run: |
echo '::group:: test custom verify-attestation success'
if ./cosign verify-attestation --policy ./test/testdata/policies/cue-fails.cue --rekor-url ${{ env.REKOR_URL }} --allow-insecure-registry ${{ env.demoimage }} ; then
if ./cosign verify-attestation --policy ./test/testdata/policies/cue-fails.cue --rekor-url ${{ env.REKOR_URL }} --allow-insecure-registry ${{ env.demoimage }} --certificate-identity https://kubernetes.io/namespaces/default/serviceaccounts/default --certificate-oidc-issuer "https://kubernetes.default.svc.cluster.local" ; then
echo custom verify-attestation succeeded with cue policy that should not work
exit 1
else
Expand All @@ -144,7 +145,7 @@ jobs:

- name: Verify a blob
run: |
./cosign verify-blob README.md --rekor-url ${{ env.REKOR_URL }} --certificate ./cert.pem --signature sig
./cosign verify-blob README.md --rekor-url ${{ env.REKOR_URL }} --certificate ./cert.pem --signature sig --certificate-identity https://kubernetes.io/namespaces/default/serviceaccounts/default --certificate-oidc-issuer "https://kubernetes.default.svc.cluster.local"

- name: Collect diagnostics
if: ${{ failure() }}
Expand All @@ -157,7 +158,7 @@ jobs:
- name: Verify vuln attestation with cosign, works
run: |
echo '::group:: test vuln verify-attestation success'
if ! ./cosign verify-attestation --type vuln --policy ./test/testdata/policies/cue-vuln-works.cue --rekor-url ${{ env.REKOR_URL }} --allow-insecure-registry ${{ env.demoimage }} ; then
if ! ./cosign verify-attestation --type vuln --policy ./test/testdata/policies/cue-vuln-works.cue --rekor-url ${{ env.REKOR_URL }} --allow-insecure-registry ${{ env.demoimage }} --certificate-identity https://kubernetes.io/namespaces/default/serviceaccounts/default --certificate-oidc-issuer "https://kubernetes.default.svc.cluster.local" ; then
echo Failed to verify attestation with a valid policy
exit 1
else
Expand All @@ -168,7 +169,7 @@ jobs:
- name: Verify vuln attestation with cosign, fails
run: |
echo '::group:: test vuln verify-attestation success'
if ./cosign verify-attestation --type vuln --policy ./test/testdata/policies/cue-vuln-fails.cue --rekor-url ${{ env.REKOR_URL }} --allow-insecure-registry ${{ env.demoimage }} ; then
if ./cosign verify-attestation --type vuln --policy ./test/testdata/policies/cue-vuln-fails.cue --rekor-url ${{ env.REKOR_URL }} --allow-insecure-registry ${{ env.demoimage }} --certificate-identity https://kubernetes.io/namespaces/default/serviceaccounts/default --certificate-oidc-issuer "https://kubernetes.default.svc.cluster.local" ; then
echo verify-attestation succeeded with cue policy that should not work
exit 1
else
Expand Down
3 changes: 1 addition & 2 deletions cmd/cosign/cli/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ Shell-like variables in the Dockerfile's FROM lines will be substituted with val
v := &dockerfile.VerifyDockerfileCommand{
VerifyCommand: verify.VerifyCommand{
RegistryOptions: o.Registry,
CertVerifyOptions: o.CertVerify,
CheckClaims: o.CheckClaims,
KeyRef: o.Key,
CertRef: o.CertVerify.Cert,
CertEmail: o.CertVerify.CertEmail,
CertOidcIssuer: o.CertVerify.CertOidcIssuer,
CertGithubWorkflowTrigger: o.CertVerify.CertGithubWorkflowTrigger,
CertGithubWorkflowSha: o.CertVerify.CertGithubWorkflowSha,
CertGithubWorkflowName: o.CertVerify.CertGithubWorkflowName,
Expand Down
3 changes: 1 addition & 2 deletions cmd/cosign/cli/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ against the transparency log.`,
v := &manifest.VerifyManifestCommand{
VerifyCommand: verify.VerifyCommand{
RegistryOptions: o.Registry,
CertVerifyOptions: o.CertVerify,
CheckClaims: o.CheckClaims,
KeyRef: o.Key,
CertRef: o.CertVerify.Cert,
CertEmail: o.CertVerify.CertEmail,
CertOidcIssuer: o.CertVerify.CertOidcIssuer,
CertGithubWorkflowTrigger: o.CertVerify.CertGithubWorkflowTrigger,
CertGithubWorkflowSha: o.CertVerify.CertGithubWorkflowSha,
CertGithubWorkflowName: o.CertVerify.CertGithubWorkflowName,
Expand Down
29 changes: 23 additions & 6 deletions cmd/cosign/cli/options/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
package options

import (
"errors"

"github.com/sigstore/cosign/v2/pkg/cosign"
"github.com/spf13/cobra"
)

// CertVerifyOptions is the wrapper for certificate verification.
type CertVerifyOptions struct {
Cert string
CertEmail string
CertIdentity string
CertIdentityRegexp string
CertOidcIssuer string
CertOidcIssuerRegexp string
CertGithubWorkflowTrigger string
CertGithubWorkflowSha string
CertGithubWorkflowName string
Expand All @@ -42,14 +46,17 @@ func (o *CertVerifyOptions) AddFlags(cmd *cobra.Command) {
"path to the public certificate. The certificate will be verified against the Fulcio roots if the --certificate-chain option is not passed.")
_ = cmd.Flags().SetAnnotation("certificate", cobra.BashCompFilenameExt, []string{"cert"})

cmd.Flags().StringVar(&o.CertEmail, "certificate-email", "",
"the email expected in a valid Fulcio certificate")

cmd.Flags().StringVar(&o.CertIdentity, "certificate-identity", "",
"the identity expected in a valid Fulcio certificate. Valid values include email address, DNS names, IP addresses, and URIs.")
"The identity expected in a valid Fulcio certificate. Valid values include email address, DNS names, IP addresses, and URIs. Either --certificate-identity or --certificate-identity-regexp must be set for keyless flows.")

cmd.Flags().StringVar(&o.CertIdentityRegexp, "certificate-identity-regexp", "",
"A regular expression alternative to --certificate-identity. Accepts the Go regular expression syntax described at https://golang.org/s/re2syntax. Either --certificate-identity or --certificate-identity-regexp must be set for keyless flows.")

cmd.Flags().StringVar(&o.CertOidcIssuer, "certificate-oidc-issuer", "",
"the OIDC issuer expected in a valid Fulcio certificate, e.g. https://token.actions.githubusercontent.com or https://oauth2.sigstore.dev/auth")
"The OIDC issuer expected in a valid Fulcio certificate, e.g. https://token.actions.githubusercontent.com or https://oauth2.sigstore.dev/auth. Either --certificate-oidc-issuer or --certificate-oidc-issuer-regexp must be set for keyless flows.")

cmd.Flags().StringVar(&o.CertOidcIssuerRegexp, "certificate-oidc-issuer-regexp", "",
"A regular expression alternative to --certificate-oidc-issuer. Accepts the Go regular expression syntax described at https://golang.org/s/re2syntax. Either --certificate-oidc-issuer or --certificate-oidc-issuer-regexp must be set for keyless flows.")

// -- Cert extensions begin --
// Source: https://github.com/sigstore/fulcio/blob/main/docs/oid-info.md
Expand Down Expand Up @@ -82,3 +89,13 @@ func (o *CertVerifyOptions) AddFlags(cmd *cobra.Command) {
"when set, verification will not check that a certificate contains an embedded SCT, a proof of "+
"inclusion in a certificate transparency log")
}

func (o *CertVerifyOptions) Identities() ([]cosign.Identity, error) {
if o.CertIdentity == "" && o.CertIdentityRegexp == "" {
return nil, errors.New("--certificate-identity or --certificate-identity-regexp is required for verification in keyless mode")
}
if o.CertOidcIssuer == "" && o.CertOidcIssuerRegexp == "" {
return nil, errors.New("--certificate-oidc-issuer or --certificate-oidc-issuer-regexp is required for verification in keyless mode")
}
return []cosign.Identity{{IssuerRegExp: o.CertOidcIssuerRegexp, Issuer: o.CertOidcIssuer, SubjectRegExp: o.CertIdentityRegexp, Subject: o.CertIdentity}}, nil
}
12 changes: 3 additions & 9 deletions cmd/cosign/cli/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ against the transparency log.`,

v := &verify.VerifyCommand{
RegistryOptions: o.Registry,
CertVerifyOptions: o.CertVerify,
CheckClaims: o.CheckClaims,
KeyRef: o.Key,
CertRef: o.CertVerify.Cert,
CertEmail: o.CertVerify.CertEmail,
CertIdentity: o.CertVerify.CertIdentity,
CertOidcIssuer: o.CertVerify.CertOidcIssuer,
CertGithubWorkflowTrigger: o.CertVerify.CertGithubWorkflowTrigger,
CertGithubWorkflowSha: o.CertVerify.CertGithubWorkflowSha,
CertGithubWorkflowName: o.CertVerify.CertGithubWorkflowName,
Expand Down Expand Up @@ -191,10 +189,8 @@ against the transparency log.`,
v := &verify.VerifyAttestationCommand{
RegistryOptions: o.Registry,
CheckClaims: o.CheckClaims,
CertVerifyOptions: o.CertVerify,
CertRef: o.CertVerify.Cert,
CertEmail: o.CertVerify.CertEmail,
CertIdentity: o.CertVerify.CertIdentity,
CertOidcIssuer: o.CertVerify.CertOidcIssuer,
CertChain: o.CertVerify.CertChain,
CertGithubWorkflowTrigger: o.CertVerify.CertGithubWorkflowTrigger,
CertGithubWorkflowSha: o.CertVerify.CertGithubWorkflowSha,
Expand Down Expand Up @@ -287,10 +283,8 @@ The blob may be specified as a path to a file or - for stdin.`,
}
verifyBlobCmd := &verify.VerifyBlobCmd{
KeyOpts: ko,
CertVerifyOptions: o.CertVerify,
CertRef: o.CertVerify.Cert,
CertEmail: o.CertVerify.CertEmail,
CertIdentity: o.CertVerify.CertIdentity,
CertOIDCIssuer: o.CertVerify.CertOidcIssuer,
CertChain: o.CertVerify.CertChain,
SigRef: o.Signature,
CertGithubWorkflowTrigger: o.CertVerify.CertGithubWorkflowTrigger,
Expand Down
16 changes: 10 additions & 6 deletions cmd/cosign/cli/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,10 @@ import (
// nolint
type VerifyCommand struct {
options.RegistryOptions
options.CertVerifyOptions
CheckClaims bool
KeyRef string
CertRef string
CertEmail string
CertIdentity string
CertOidcIssuer string
CertGithubWorkflowTrigger string
CertGithubWorkflowSha string
CertGithubWorkflowName string
Expand Down Expand Up @@ -99,6 +97,14 @@ func (c *VerifyCommand) Exec(ctx context.Context, images []string) (err error) {
c.HashAlgorithm = crypto.SHA256
}

var identities []cosign.Identity
if c.KeyRef == "" {
identities, err = c.Identities()
if err != nil {
return err
}
}

ociremoteOpts, err := c.ClientOpts(ctx)
if err != nil {
return fmt.Errorf("constructing client options: %w", err)
Expand All @@ -107,16 +113,14 @@ func (c *VerifyCommand) Exec(ctx context.Context, images []string) (err error) {
co := &cosign.CheckOpts{
Annotations: c.Annotations.Annotations,
RegistryClientOpts: ociremoteOpts,
CertEmail: c.CertEmail,
CertIdentity: c.CertIdentity,
CertOidcIssuer: c.CertOidcIssuer,
CertGithubWorkflowTrigger: c.CertGithubWorkflowTrigger,
CertGithubWorkflowSha: c.CertGithubWorkflowSha,
CertGithubWorkflowName: c.CertGithubWorkflowName,
CertGithubWorkflowRepository: c.CertGithubWorkflowRepository,
CertGithubWorkflowRef: c.CertGithubWorkflowRef,
IgnoreSCT: c.IgnoreSCT,
SignatureRef: c.SignatureRef,
Identities: identities,
Offline: c.Offline,
SkipTlogVerify: c.SkipTlogVerify,
}
Expand Down
17 changes: 11 additions & 6 deletions cmd/cosign/cli/verify/verify_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ import (
// nolint
type VerifyAttestationCommand struct {
options.RegistryOptions
options.CertVerifyOptions
CheckClaims bool
KeyRef string
CertRef string
CertEmail string
CertIdentity string
CertOidcIssuer string
CertGithubWorkflowTrigger string
CertGithubWorkflowSha string
CertGithubWorkflowName string
Expand Down Expand Up @@ -81,21 +79,28 @@ func (c *VerifyAttestationCommand) Exec(ctx context.Context, images []string) (e
return &options.KeyParseError{}
}

var identities []cosign.Identity
if c.KeyRef == "" {
identities, err = c.Identities()
if err != nil {
return err
}
}

ociremoteOpts, err := c.ClientOpts(ctx)
if err != nil {
return fmt.Errorf("constructing client options: %w", err)
}

co := &cosign.CheckOpts{
RegistryClientOpts: ociremoteOpts,
CertEmail: c.CertEmail,
CertIdentity: c.CertIdentity,
CertOidcIssuer: c.CertOidcIssuer,
CertGithubWorkflowTrigger: c.CertGithubWorkflowTrigger,
CertGithubWorkflowSha: c.CertGithubWorkflowSha,
CertGithubWorkflowName: c.CertGithubWorkflowName,
CertGithubWorkflowRepository: c.CertGithubWorkflowRepository,
CertGithubWorkflowRef: c.CertGithubWorkflowRef,
IgnoreSCT: c.IgnoreSCT,
Identities: identities,
Offline: c.Offline,
SkipTlogVerify: c.SkipTlogVerify,
}
Expand Down
54 changes: 54 additions & 0 deletions cmd/cosign/cli/verify/verify_attestation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2022 the Sigstore Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package verify

import (
"context"
"testing"

"github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
)

func TestVerifyAttestationMissingSubject(t *testing.T) {
ctx := context.Background()

verifyAttestation := VerifyAttestationCommand{
CertRef: "cert.pem",
CertVerifyOptions: options.CertVerifyOptions{
CertOidcIssuer: "issuer",
},
}

err := verifyAttestation.Exec(ctx, []string{"foo", "bar", "baz"})
if err == nil {
t.Fatal("verifyAttestation expected 'need --certificate-identity'")
}
}

func TestVerifyAttestationMissingIssuer(t *testing.T) {
ctx := context.Background()

verifyAttestation := VerifyAttestationCommand{
CertRef: "cert.pem",
CertVerifyOptions: options.CertVerifyOptions{
CertIdentity: "subject",
},
}

err := verifyAttestation.Exec(ctx, []string{"foo", "bar", "baz"})
if err == nil {
t.Fatal("verifyAttestation expected 'need --certificate-oidc-issuer'")
}
}
17 changes: 11 additions & 6 deletions cmd/cosign/cli/verify/verify_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ func isb64(data []byte) bool {
// nolint
type VerifyBlobCmd struct {
options.KeyOpts
options.CertVerifyOptions
CertRef string
CertEmail string
CertIdentity string
CertOIDCIssuer string
CertChain string
SigRef string
CertGithubWorkflowTrigger string
Expand Down Expand Up @@ -85,6 +83,15 @@ func (c *VerifyBlobCmd) Exec(ctx context.Context, blobRef string) error {
return &options.KeyParseError{}
}

var identities []cosign.Identity
var err error
if c.KeyRef == "" {
identities, err = c.Identities()
if err != nil {
return err
}
}

sig, err := base64signature(c.SigRef, c.BundlePath)
if err != nil {
return err
Expand All @@ -96,15 +103,13 @@ func (c *VerifyBlobCmd) Exec(ctx context.Context, blobRef string) error {
}

co := &cosign.CheckOpts{
CertEmail: c.CertEmail,
CertIdentity: c.CertIdentity,
CertOidcIssuer: c.CertOIDCIssuer,
CertGithubWorkflowTrigger: c.CertGithubWorkflowTrigger,
CertGithubWorkflowSha: c.CertGithubWorkflowSHA,
CertGithubWorkflowName: c.CertGithubWorkflowName,
CertGithubWorkflowRepository: c.CertGithubWorkflowRepository,
CertGithubWorkflowRef: c.CertGithubWorkflowRef,
IgnoreSCT: c.IgnoreSCT,
Identities: identities,
Offline: c.Offline,
SkipTlogVerify: c.SkipTlogVerify,
}
Expand Down
Loading