Skip to content

Commit 1b1cafc

Browse files
author
Jake Sanders
authored
move verify-dockerfile to dockerfile verify (#662)
* move `verify-dockerfile` to `dockerfile verify` Signed-off-by: Jake Sanders <[email protected]> * fix docstring Signed-off-by: Jake Sanders <[email protected]>
1 parent 275e015 commit 1b1cafc

File tree

7 files changed

+72
-30
lines changed

7 files changed

+72
-30
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2021 The Sigstore Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package dockerfile
16+
17+
import (
18+
"context"
19+
"flag"
20+
21+
"github.com/peterbourgon/ff/v3/ffcli"
22+
)
23+
24+
func Dockerfile() *ffcli.Command {
25+
var (
26+
flagset = flag.NewFlagSet("cosign dockerfile", flag.ExitOnError)
27+
)
28+
29+
return &ffcli.Command{
30+
Name: "dockerfile",
31+
ShortUsage: "cosign dockerfile",
32+
ShortHelp: "Provides utilities for discovering images in and performing operations on Dockerfiles",
33+
FlagSet: flagset,
34+
Subcommands: []*ffcli.Command{VerifyDockerfile()},
35+
Exec: func(ctx context.Context, args []string) error {
36+
return flag.ErrHelp
37+
},
38+
}
39+
}

cmd/cosign/cli/verify_dockerfile.go renamed to cmd/cosign/cli/dockerfile/verify.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package cli
15+
package dockerfile
1616

1717
import (
1818
"bufio"
@@ -25,24 +25,25 @@ import (
2525

2626
"github.com/peterbourgon/ff/v3/ffcli"
2727
"github.com/pkg/errors"
28+
"github.com/sigstore/cosign/cmd/cosign/cli"
2829
)
2930

3031
// VerifyCommand verifies a signature on a supplied container image
3132
type VerifyDockerfileCommand struct {
32-
VerifyCommand
33+
cli.VerifyCommand
3334
BaseOnly bool
3435
}
3536

3637
// Verify builds and returns an ffcli command
3738
func VerifyDockerfile() *ffcli.Command {
38-
cmd := VerifyDockerfileCommand{VerifyCommand: VerifyCommand{}}
39-
flagset := flag.NewFlagSet("cosign verify-dockerfile", flag.ExitOnError)
39+
cmd := VerifyDockerfileCommand{VerifyCommand: cli.VerifyCommand{}}
40+
flagset := flag.NewFlagSet("cosign dockerfile verify", flag.ExitOnError)
4041
flagset.BoolVar(&cmd.BaseOnly, "base-image-only", false, "only verify the base image (the last FROM image in the Dockerfile)")
41-
applyVerifyFlags(&cmd.VerifyCommand, flagset)
42+
cli.ApplyVerifyFlags(&cmd.VerifyCommand, flagset)
4243

4344
return &ffcli.Command{
44-
Name: "verify-dockerfile",
45-
ShortUsage: "cosign verify-dockerfile -key <key path>|<key url>|<kms uri> <path/to/Dockerfile>",
45+
Name: "verify",
46+
ShortUsage: "cosign dockerfile verify -key <key path>|<key url>|<kms uri> <path/to/Dockerfile>",
4647
ShortHelp: "Verify a signature on the base image specified in the Dockerfile",
4748
LongHelp: `Verify signature and annotations on images in a Dockerfile by checking claims
4849
against the transparency log.
@@ -51,34 +52,34 @@ Shell-like variables in the Dockerfile's FROM lines will be substituted with val
5152
5253
EXAMPLES
5354
# verify cosign claims and signing certificates on the FROM images in the Dockerfile
54-
cosign verify-dockerfile <path/to/Dockerfile>
55+
cosign dockerfile verify <path/to/Dockerfile>
5556
5657
# only verify the base image (the last FROM image)
57-
cosign verify-dockerfile -base-image-only <path/to/Dockerfile>
58+
cosign dockerfile verify -base-image-only <path/to/Dockerfile>
5859
5960
# additionally verify specified annotations
60-
cosign verify-dockerfile -a key1=val1 -a key2=val2 <path/to/Dockerfile>
61+
cosign dockerfile verify -a key1=val1 -a key2=val2 <path/to/Dockerfile>
6162
6263
# (experimental) additionally, verify with the transparency log
63-
COSIGN_EXPERIMENTAL=1 cosign verify-dockerfile <path/to/Dockerfile>
64+
COSIGN_EXPERIMENTAL=1 cosign dockerfile verify <path/to/Dockerfile>
6465
6566
# verify images with public key
66-
cosign verify-dockerfile -key cosign.pub <path/to/Dockerfile>
67+
cosign dockerfile verify -key cosign.pub <path/to/Dockerfile>
6768
6869
# verify images with public key provided by URL
69-
cosign verify-dockerfile -key https://host.for/<FILE> <path/to/Dockerfile>
70+
cosign dockerfile verify -key https://host.for/<FILE> <path/to/Dockerfile>
7071
7172
# verify images with public key stored in Azure Key Vault
72-
cosign verify-dockerfile -key azurekms://[VAULT_NAME][VAULT_URI]/[KEY] <path/to/Dockerfile>
73+
cosign dockerfile verify -key azurekms://[VAULT_NAME][VAULT_URI]/[KEY] <path/to/Dockerfile>
7374
7475
# verify images with public key stored in AWS KMS
75-
cosign verify-dockerfile -key awskms://[ENDPOINT]/[ID/ALIAS/ARN] <path/to/Dockerfile>
76+
cosign dockerfile verify -key awskms://[ENDPOINT]/[ID/ALIAS/ARN] <path/to/Dockerfile>
7677
7778
# verify images with public key stored in Google Cloud KMS
78-
cosign verify-dockerfile -key gcpkms://projects/[PROJECT]/locations/global/keyRings/[KEYRING]/cryptoKeys/[KEY] <path/to/Dockerfile>
79+
cosign dockerfile verify -key gcpkms://projects/[PROJECT]/locations/global/keyRings/[KEYRING]/cryptoKeys/[KEY] <path/to/Dockerfile>
7980
8081
# verify images with public key stored in Hashicorp Vault
81-
cosign verify-dockerfile -key hashivault://[KEY] <path/to/Dockerfile>`,
82+
cosign dockerfile verify -key hashivault://[KEY] <path/to/Dockerfile>`,
8283

8384
FlagSet: flagset,
8485
Exec: cmd.Exec,

cmd/cosign/cli/verify_dockerfile_test.go renamed to cmd/cosign/cli/dockerfile/verify_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
package cli
14+
package dockerfile
1515

1616
import (
1717
"os"

cmd/cosign/cli/verify.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type VerifyCommand struct {
4646
Annotations *map[string]interface{}
4747
}
4848

49-
func applyVerifyFlags(cmd *VerifyCommand, flagset *flag.FlagSet) {
49+
func ApplyVerifyFlags(cmd *VerifyCommand, flagset *flag.FlagSet) {
5050
annotations := annotationsMap{}
5151
flagset.StringVar(&cmd.KeyRef, "key", "", "path to the public key file, URL, KMS URI or Kubernetes Secret")
5252
flagset.StringVar(&cmd.CertEmail, "cert-email", "", "the email expected in a valid fulcio cert")
@@ -66,7 +66,7 @@ func applyVerifyFlags(cmd *VerifyCommand, flagset *flag.FlagSet) {
6666
func Verify() *ffcli.Command {
6767
cmd := VerifyCommand{}
6868
flagset := flag.NewFlagSet("cosign verify", flag.ExitOnError)
69-
applyVerifyFlags(&cmd, flagset)
69+
ApplyVerifyFlags(&cmd, flagset)
7070

7171
return &ffcli.Command{
7272
Name: "verify",

cmd/cosign/cli/verify_manifest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type VerifyManifestCommand struct {
4646
func VerifyManifest() *ffcli.Command {
4747
cmd := VerifyManifestCommand{VerifyCommand: VerifyCommand{}}
4848
flagset := flag.NewFlagSet("cosign verify-manifest", flag.ExitOnError)
49-
applyVerifyFlags(&cmd.VerifyCommand, flagset)
49+
ApplyVerifyFlags(&cmd.VerifyCommand, flagset)
5050

5151
return &ffcli.Command{
5252
Name: "verify-manifest",

cmd/cosign/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/sigstore/cosign/cmd/cosign/cli"
3030
"github.com/sigstore/cosign/cmd/cosign/cli/attach"
31+
"github.com/sigstore/cosign/cmd/cosign/cli/dockerfile"
3132
"github.com/sigstore/cosign/cmd/cosign/cli/download"
3233
"github.com/sigstore/cosign/cmd/cosign/cli/pivcli"
3334
"github.com/sigstore/cosign/cmd/cosign/cli/upload"
@@ -55,14 +56,15 @@ func main() {
5556
cli.SignBlob(),
5657
cli.VerifyAttestation(),
5758
cli.VerifyBlob(),
58-
cli.VerifyDockerfile(),
5959
cli.VerifyManifest(),
6060
// Upload sub-tree
6161
upload.Upload(),
6262
// Download sub-tree
6363
download.Download(),
6464
// Attach sub-tree
6565
attach.Attach(),
66+
// Dockerfile sub-tree
67+
dockerfile.Dockerfile(),
6668
// PIV sub-tree
6769
pivcli.PivKey(),
6870
// PIV sub-tree

test/e2e_test.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ popd
4646
go build -o cosign ./cmd/cosign
4747
go test -tags=e2e -race ./...
4848

49-
# Test `cosign verify-dockerfile`
49+
# Test `cosign dockerfile verify`
5050
export DISTROLESS_PUB_KEY=distroless.pub
5151
wget -O ${DISTROLESS_PUB_KEY} https://raw.githubusercontent.com/GoogleContainerTools/distroless/main/cosign.pub
52-
./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./test/testdata/single_stage.Dockerfile
53-
if (./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./test/testdata/unsigned_build_stage.Dockerfile); then false; fi
54-
./cosign verify-dockerfile -base-image-only -key ${DISTROLESS_PUB_KEY} ./test/testdata/unsigned_build_stage.Dockerfile
55-
./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./test/testdata/fancy_from.Dockerfile
56-
test_image="gcr.io/distroless/base" ./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./test/testdata/with_arg.Dockerfile
52+
./cosign dockerfile verify -key ${DISTROLESS_PUB_KEY} ./test/testdata/single_stage.Dockerfile
53+
if (./cosign dockerfile verify -key ${DISTROLESS_PUB_KEY} ./test/testdata/unsigned_build_stage.Dockerfile); then false; fi
54+
./cosign dockerfile verify -base-image-only -key ${DISTROLESS_PUB_KEY} ./test/testdata/unsigned_build_stage.Dockerfile
55+
./cosign dockerfile verify -key ${DISTROLESS_PUB_KEY} ./test/testdata/fancy_from.Dockerfile
56+
test_image="gcr.io/distroless/base" ./cosign dockerfile verify -key ${DISTROLESS_PUB_KEY} ./test/testdata/with_arg.Dockerfile
5757
# Image exists, but is unsigned
58-
if (test_image="ubuntu" ./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./test/testdata/with_arg.Dockerfile); then false; fi
59-
./cosign verify-dockerfile -key ${DISTROLESS_PUB_KEY} ./test/testdata/with_lowercase.Dockerfile
58+
if (test_image="ubuntu" ./cosign dockerfile verify -key ${DISTROLESS_PUB_KEY} ./test/testdata/with_arg.Dockerfile); then false; fi
59+
./cosign dockerfile verify -key ${DISTROLESS_PUB_KEY} ./test/testdata/with_lowercase.Dockerfile
6060

6161
# Test `cosign verify-manifest`
6262
./cosign verify-manifest -key ${DISTROLESS_PUB_KEY} ./test/testdata/signed_manifest.yaml

0 commit comments

Comments
 (0)