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

Invert upload flag to allow for not uploading attestation #979

Merged
merged 1 commit into from
Oct 31, 2021
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
2 changes: 1 addition & 1 deletion cmd/cosign/cli/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Attest() *cobra.Command {
OIDCClientSecret: o.OIDC.ClientSecret,
}
for _, img := range args {
if err := attest.AttestCmd(cmd.Context(), ko, o.Registry, img, o.Cert, o.Upload, o.Predicate.Path, o.Force, o.Predicate.Type); err != nil {
if err := attest.AttestCmd(cmd.Context(), ko, o.Registry, img, o.Cert, o.NoUpload, o.Predicate.Path, o.Force, o.Predicate.Type); err != nil {
return errors.Wrapf(err, "signing %s", img)
}
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/cosign/cli/attest/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"bytes"
"context"
_ "crypto/sha256" // for `crypto.SHA256`
"encoding/base64"
"encoding/json"
"fmt"
"os"
Expand All @@ -45,7 +44,7 @@ import (

//nolint
func AttestCmd(ctx context.Context, ko sign.KeyOpts, regOpts options.RegistryOptions, imageRef string, certPath string,
upload bool, predicatePath string, force bool, predicateType string) error {
noUpload bool, predicatePath string, force bool, predicateType string) error {
// A key file or token is required unless we're in experimental mode!
if options.EnableExperimental() {
if options.NOf(ko.KeyRef, ko.Sk) > 1 {
Expand Down Expand Up @@ -115,8 +114,8 @@ func AttestCmd(ctx context.Context, ko sign.KeyOpts, regOpts options.RegistryOpt
return errors.Wrap(err, "signing")
}

if !upload {
fmt.Println(base64.StdEncoding.EncodeToString(signedPayload))
if noUpload {
fmt.Println(string(signedPayload))
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/cosign/cli/options/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
type AttestOptions struct {
Key string
Cert string
Upload bool
NoUpload bool
Force bool
Recursive bool

Expand Down Expand Up @@ -52,8 +52,8 @@ func (o *AttestOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.Cert, "cert", "",
"path to the x509 certificate to include in the Signature")

cmd.Flags().BoolVar(&o.Upload, "upload", true,
"whether to upload the signature")
cmd.Flags().BoolVar(&o.NoUpload, "no-upload", false,
"do not upload the generated attestation")

cmd.Flags().BoolVarP(&o.Force, "force", "f", false,
"skip warnings and confirmations")
Expand Down
2 changes: 1 addition & 1 deletion doc/cosign_attest.md

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

3 changes: 2 additions & 1 deletion test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ func TestAttestVerify(t *testing.T) {

// Now attest the image
ko := sign.KeyOpts{KeyRef: privKeyPath, PassFunc: passFunc}
must(attest.AttestCmd(ctx, ko, options.RegistryOptions{}, imgName, "", true, slsaAttestationPath, false, "custom"), t)
must(attest.AttestCmd(ctx, ko, options.RegistryOptions{}, imgName, "", false, slsaAttestationPath, false,
"custom"), t)

// Use cue to verify attestation
policyPath := filepath.Join(td, "policy.cue")
Expand Down