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

Move "verify-manifest" into "verify". #527

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 17 additions & 1 deletion cmd/cosign/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

package cli

import "reflect"
import (
"reflect"
"strings"
)

// oneOf ensures that only one of the supplied interfaces is set to a non-zero value.
func oneOf(args ...interface{}) bool {
Expand All @@ -32,3 +35,16 @@ func nOf(args ...interface{}) int {
}
return n
}

type StringSlice struct {
slice []string
}

func (ss *StringSlice) Set(s string) error {
ss.slice = append(ss.slice, s)
return nil
}

func (ss *StringSlice) String() string {
return strings.Join(ss.slice, ",")
}
27 changes: 25 additions & 2 deletions cmd/cosign/cli/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"

"github.com/google/go-containerregistry/pkg/name"
Expand All @@ -42,6 +43,7 @@ type VerifyCommand struct {
Output string
RekorURL string
Annotations *map[string]interface{}
Files StringSlice
}

func applyVerifyFlags(cmd *VerifyCommand, flagset *flag.FlagSet) {
Expand All @@ -53,6 +55,8 @@ func applyVerifyFlags(cmd *VerifyCommand, flagset *flag.FlagSet) {
flagset.BoolVar(&cmd.CheckClaims, "check-claims", true, "whether to check the claims found")
flagset.StringVar(&cmd.Output, "output", "json", "output the signing image information. Default JSON.")

flagset.Var(&cmd.Files, "f", "files to validate (kubernetes manifests or Dockerfiles)")

// parse annotations
flagset.Var(&annotations, "a", "extra key=value pairs to sign")
cmd.Annotations = &annotations.annotations
Expand Down Expand Up @@ -103,7 +107,7 @@ EXAMPLES

// Exec runs the verification command
func (c *VerifyCommand) Exec(ctx context.Context, args []string) (err error) {
if len(args) == 0 {
if len(args) == 0 && len(c.Files.slice) == 0 {
return flag.ErrHelp
}

Expand Down Expand Up @@ -145,7 +149,26 @@ func (c *VerifyCommand) Exec(ctx context.Context, args []string) (err error) {
}
co.SigVerifier = pubKey

for _, imageRef := range args {
allImgs := []string{}
allImgs = append(allImgs, args...)

for _, f := range c.Files.slice {
err := isExtensionAllowed(f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we distinguish the given file whether Dockerfile in this function? Currently, isExtensionAllowed only returns true in case given file is .yml or .yaml. In the flag description, since we pointed out that -f flag accepts Dockerfile, we actually do not check here.

flagset.Var(&cmd.Files, "f", "files to validate (kubernetes manifests or Dockerfiles)")

Will we move the verify-dockerfile into verify command in the long term?

if err != nil {
return errors.Wrap(err, "check if extension is valid")
}
manifest, err := ioutil.ReadFile(f)
if err != nil {
return fmt.Errorf("could not read manifest: %v", err)
}
imgs, err := getImagesFromYamlManifest(string(manifest))
if err != nil {
return err
}
allImgs = append(allImgs, imgs...)
}

for _, imageRef := range allImgs {
ref, err := name.ParseReference(imageRef)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/cosign/cli/verify_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ EXAMPLES

// Exec runs the verification command
func (c *VerifyManifestCommand) Exec(ctx context.Context, args []string) error {
fmt.Fprintln(os.Stderr, "This command is deprecated and will be removed in the next release. Please use `cosign verify -f <manifest>` instead.")
if len(args) != 1 {
return flag.ErrHelp
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ if (test_image="ubuntu" ./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./
# Test `cosign verify-manifest`
./cosign verify-manifest -key ${DISTROLESS_PUB_KEY} ./test/testdata/signed_manifest.yaml
if (./cosign verify-manifest -key ${DISTROLESS_PUB_KEY} ./test/testdata/unsigned_manifest.yaml); then false; fi
./cosign verify -key ${DISTROLESS_PUB_KEY} -f ./test/testdata/signed_manifest.yaml

# Run the built container to make sure it doesn't crash
make ko-local
Expand Down