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

Remove experimental mode from sign-blob and verify-blob #2457

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ policyControllerImagerefs
sgetImagerefs
policyImagerefs

bundle
signature
certificate

**verify-experimental*
4 changes: 4 additions & 0 deletions cmd/cosign/cli/options/signblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type SignBlobOptions struct {
Registry RegistryOptions
BundlePath string
SkipConfirmation bool
TlogUpload bool
}

var _ Interface = (*SignBlobOptions)(nil)
Expand Down Expand Up @@ -70,4 +71,7 @@ func (o *SignBlobOptions) AddFlags(cmd *cobra.Command) {

cmd.Flags().BoolVarP(&o.SkipConfirmation, "yes", "y", false,
"skip confirmation prompts for non-destructive operations")

cmd.Flags().BoolVar(&o.TlogUpload, "tlog-upload", false,
"whether or not to upload to the tlog")
}
5 changes: 5 additions & 0 deletions cmd/cosign/cli/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func ShouldUploadToTlog(ctx context.Context, ko options.KeyOpts, ref name.Refere
return true
}

// We don't need to validate the ref, just return true
if ref == nil {
return true
}

// Check if the image is public (no auth in Get)
if _, err := remote.Get(ref, remote.WithContext(ctx)); err != nil {
fmt.Fprintf(os.Stderr, "%q appears to be a private repository, please confirm uploading to the transparency log at %q [Y/N]: ", ref.Context().String(), ko.RekorURL)
Expand Down
4 changes: 2 additions & 2 deletions cmd/cosign/cli/sign/sign_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

// nolint
func SignBlobCmd(ro *options.RootOptions, ko options.KeyOpts, regOpts options.RegistryOptions, payloadPath string, b64 bool, outputSignature string, outputCertificate string) ([]byte, error) {
func SignBlobCmd(ro *options.RootOptions, ko options.KeyOpts, regOpts options.RegistryOptions, payloadPath string, b64 bool, outputSignature string, outputCertificate string, tlogUpload bool) ([]byte, error) {
var payload []byte
var err error
var rekorBytes []byte
Expand Down Expand Up @@ -65,7 +65,7 @@ func SignBlobCmd(ro *options.RootOptions, ko options.KeyOpts, regOpts options.Re

signedPayload := cosign.LocalSignedPayload{}

if options.EnableExperimental() {
if ShouldUploadToTlog(ctx, ko, nil, ko.SkipConfirmation, tlogUpload) {
rekorBytes, err = sv.Bytes(ctx)
if err != nil {
return nil, err
Expand Down
11 changes: 4 additions & 7 deletions cmd/cosign/cli/signblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func SignBlob() *cobra.Command {
Example: ` cosign sign-blob --key <key path>|<kms uri> <blob>

# sign a blob with Google sign-in (experimental)
COSIGN_EXPERIMENTAL=1 cosign --timeout 90s sign-blob <FILE>
cosign sign-blob <FILE> --output-signature <FILE> --output-certificate <FILE>

# sign a blob with a local key pair file
cosign sign-blob --key cosign.key <FILE>
Expand All @@ -55,11 +55,8 @@ func SignBlob() *cobra.Command {
Args: cobra.MinimumNArgs(1),
PersistentPreRun: options.BindViper,
PreRunE: func(cmd *cobra.Command, args []string) error {
// A key file is required unless we're in experimental mode!
if !options.EnableExperimental() {
if !options.OneOf(o.Key, o.SecurityKey.Use) {
return &options.KeyParseError{}
}
if options.NOf(o.Key, o.SecurityKey.Use) > 1 {
return &options.KeyParseError{}
}
return nil
},
Expand Down Expand Up @@ -91,7 +88,7 @@ func SignBlob() *cobra.Command {
fmt.Fprintln(os.Stderr, "WARNING: the '--output' flag is deprecated and will be removed in the future. Use '--output-signature'")
o.OutputSignature = o.Output
}
if _, err := sign.SignBlobCmd(ro, ko, o.Registry, blob, o.Base64Output, o.OutputSignature, o.OutputCertificate); err != nil {
if _, err := sign.SignBlobCmd(ro, ko, o.Registry, blob, o.Base64Output, o.OutputSignature, o.OutputCertificate, o.TlogUpload); err != nil {
return fmt.Errorf("signing %s: %w", blob, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cosign/cli/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ The blob may be specified as a path to a file or - for stdin.`,
cosign verify-blob --key gitlab://[PROJECT_ID] --signature $sig <blob>

# Verify a signature against a certificate
COSIGN_EXPERIMENTAL=1 cosign verify-blob --certificate <cert> --signature $sig <blob>
cosign verify-blob --certificate <cert> --signature $sig <blob>
`,

Args: cobra.ExactArgs(1),
Expand Down
8 changes: 4 additions & 4 deletions cmd/cosign/cli/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *VerifyCommand) Exec(ctx context.Context, images []string) (err error) {
co.ClaimVerifier = cosign.SimpleClaimVerifier
}

if c.keylessVerification() {
if keylessVerification(c.KeyRef, c.Sk) {
if c.RekorURL != "" {
rekorClient, err := rekor.NewClient(c.RekorURL)
if err != nil {
Expand Down Expand Up @@ -408,11 +408,11 @@ func loadCertChainFromFileOrURL(path string) ([]*x509.Certificate, error) {
return certs, nil
}

func (c *VerifyCommand) keylessVerification() bool {
if c.KeyRef != "" {
func keylessVerification(keyRef string, sk bool) bool {
if keyRef != "" {
return false
}
if c.Sk {
if sk {
return false
}
return true
Expand Down
10 changes: 5 additions & 5 deletions cmd/cosign/cli/verify/verify_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func (c *VerifyBlobCmd) Exec(ctx context.Context, blobRef string) error {
var bundle *bundle.RekorBundle

// Require a certificate/key OR a local bundle file that has the cert.
if !options.OneOf(c.KeyRef, c.Sk, c.CertRef) && c.BundlePath == "" {
return &options.PubKeyParseError{}
if options.NOf(c.KeyRef, c.Sk) > 1 {
return &options.KeyParseError{}
}

sig, err := signatures(c.SigRef, c.BundlePath)
Expand All @@ -117,16 +117,14 @@ func (c *VerifyBlobCmd) Exec(ctx context.Context, blobRef string) error {
IgnoreSCT: c.IgnoreSCT,
Offline: c.Offline,
}
if options.EnableExperimental() {
if keylessVerification(c.KeyRef, c.Sk) {
if c.RekorURL != "" {
rekorClient, err := rekor.NewClient(c.RekorURL)
if err != nil {
return fmt.Errorf("creating Rekor client: %w", err)
}
co.RekorClient = rekorClient
}
}
if options.EnableExperimental() {
co.RootCerts, err = fulcio.GetRoots()
if err != nil {
return fmt.Errorf("getting Fulcio roots: %w", err)
Expand Down Expand Up @@ -242,6 +240,8 @@ func (c *VerifyBlobCmd) Exec(ctx context.Context, blobRef string) error {
return fmt.Errorf("loading verifier from bundle: %w", err)
}
bundle = b.Bundle
default:
return fmt.Errorf("please provide a cert to verify against via --certificate or a bundle via --bundle")
}

// Performs all blob verification.
Expand Down
3 changes: 2 additions & 1 deletion doc/cosign_sign-blob.md

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

2 changes: 1 addition & 1 deletion doc/cosign_verify-blob.md

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

6 changes: 3 additions & 3 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func TestSignBlob(t *testing.T) {
KeyRef: privKeyPath1,
PassFunc: passFunc,
}
sig, err := sign.SignBlobCmd(ro, ko, options.RegistryOptions{}, bp, true, "", "")
sig, err := sign.SignBlobCmd(ro, ko, options.RegistryOptions{}, bp, true, "", "", false)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -738,15 +738,15 @@ func TestSignBlobBundle(t *testing.T) {
BundlePath: bundlePath,
RekorURL: rekorURL,
}
if _, err := sign.SignBlobCmd(ro, ko, options.RegistryOptions{}, bp, true, "", ""); err != nil {
if _, err := sign.SignBlobCmd(ro, ko, options.RegistryOptions{}, bp, true, "", "", false); err != nil {
t.Fatal(err)
}
// Now verify should work
must(verifyBlobCmd.Exec(ctx, bp), t)

// Now we turn on the tlog and sign again
defer setenv(t, env.VariableExperimental.String(), "1")()
if _, err := sign.SignBlobCmd(ro, ko, options.RegistryOptions{}, bp, true, "", ""); err != nil {
if _, err := sign.SignBlobCmd(ro, ko, options.RegistryOptions{}, bp, true, "", "", false); err != nil {
t.Fatal(err)
}

Expand Down