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

feat: cosign sign #556

Merged
merged 1 commit into from
Dec 13, 2021
Merged

feat: cosign sign #556

merged 1 commit into from
Dec 13, 2021

Conversation

developer-guy
Copy link
Contributor

@developer-guy developer-guy commented Nov 23, 2021

Signed-off-by: Batuhan Apaydın batuhan.apaydin@trendyol.com
Co-authored-by: Furkan Türkal furkan.turkal@trendyol.com

Fixes #423

I forgot that we can't have a digest before pushing the image, so, we have to do it right after pushing the image. 🙋🏻‍♂️

## Keyless Mode
$ COSIGN_EXPERIMENTAL=1 _output/nerdctl push --sign devopps/bar:latest

## Without Keyless Mode
$ cosign generate-key-pair
$ _output/nerdctl push --sign --cosign-key cosign.key devopps/bar:latest

cmd/nerdctl/push.go Outdated Show resolved Hide resolved
cmd/nerdctl/push.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
@AkihiroSuda AkihiroSuda added this to the v0.15.0 milestone Nov 23, 2021
@AkihiroSuda AkihiroSuda added enhancement New feature or request impact/major labels Nov 23, 2021
@developer-guy
Copy link
Contributor Author

@AkihiroSuda would you mind testing this in your environment, we have a macOS laptop, so, didn't test it well, we tried on CentOS by leveraging your Vagrantfile, but I just want to be sure about the development, it'd be perfect if you can test this on your own. 🙋🏻‍♂️

@developer-guy
Copy link
Contributor Author

seems there is a problem with the Go modules 👇

https://github.com/containerd/nerdctl/runs/4299324111?check_suite_focus=true#step:4:555

but couldn't make it work, I really don't understand why I'm getting this error, can you please help @AkihiroSuda, thanks in advance, but it is not a blocker thing to build binary itself which means that I can still run the following commands to build binary:

GOOS=linux make binaries && \
        GOOS=linux go test -c ./cmd/nerdctl

@AkihiroSuda
Copy link
Member

  go: downloading go.opentelemetry.io v0.1.0
  github.com/containerd/nerdctl/cmd/nerdctl imports
  	github.com/sigstore/cosign/cmd/cosign/cli/sign imports
  	github.com/sigstore/cosign/cmd/cosign/cli/fulcio/fulcioverifier imports
  	github.com/google/certificate-transparency-go imports
  	go.etcd.io/etcd/v3 imports
  	go.etcd.io/etcd/tests/v3/integration imports
  	go.etcd.io/etcd/server/v3/embed imports
  	go.opentelemetry.io/otel/semconv: module go.opentelemetry.io/otel@latest found (v1.2.0), but does not contain package go.opentelemetry.io/otel/semconv
  github.com/containerd/nerdctl/cmd/nerdctl imports
  	github.com/sigstore/cosign/cmd/cosign/cli/sign imports
  	github.com/sigstore/cosign/cmd/cosign/cli/fulcio/fulcioverifier imports
  	github.com/google/certificate-transparency-go imports
  	go.etcd.io/etcd/v3 imports
  	go.etcd.io/etcd/tests/v3/integration imports
  	go.etcd.io/etcd/server/v3/embed imports
  	go.opentelemetry.io/otel/exporters/otlp imports
  	go.opentelemetry.io/otel/sdk/metric/controller/basic imports
  	go.opentelemetry.io/otel/metric/registry: module go.opentelemetry.io/otel/metric@latest found (v0.25.0), but does not contain package go.opentelemetry.io/otel/metric/registry

Probably you need some replace() lines in go.mod

@AkihiroSuda
Copy link
Member

Depending on etcd and opentelemetry seems too much heavy.

Can we somehow reduce these deps?
e.g., by executing an external binary

@developer-guy
Copy link
Contributor Author

Screen-Recording-2021-11-29-at-1

@developer-guy
Copy link
Contributor Author

Screen-Recording-2021-11-29-at-2

cc: @Dentrax

@@ -48,6 +54,7 @@ func newPullCommand() *cobra.Command {
pullCommand.Flags().StringSlice("platform", nil, "Pull content for a specific platform")
pullCommand.RegisterFlagCompletionFunc("platform", shellCompletePlatforms)
pullCommand.Flags().Bool("all-platforms", false, "Pull content for all platforms")
pullCommand.Flags().Bool("verify", false, "Verify the image with cosign")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be a string flag --verify=(none|cosign) so that we can eventually add other verifier such as Notary (v2).

Copy link
Member

Choose a reason for hiding this comment

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

Also, can we have integration tests?
The tests should cover both good sign and bad sign.

Copy link
Contributor

Choose a reason for hiding this comment

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

String flag --verify=(none|cosign) would make sense to implement! However, what about adding this feature when someone wants to work with notary to implement in nerdctl? But we can do it anyway if you want, since it's a good long-term feature!

For the integration tests, we probably need to store cosign.key and cosign.pub files in the ./examples or smth folder. And we will be depended on cosign executable (must be installed) to run all integration tests, is it OK?

Copy link
Member

Choose a reason for hiding this comment

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

Notary support doesn't need to be added right now. We just have to design the CLI flag to be extensible to cover notary (or something else) in future.

For the integration tests, we probably need to store cosign.key and cosign.pub files in the ./examples or smth folder. And we will be depended on cosign executable (must be installed) to run all integration tests, is it OK?

The key should be generated during the tests by executing cosign. (as we generate ocicrypt keys in image_encrypt_linux_test.go)

Copy link
Member

Choose a reason for hiding this comment

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

(So, maybe we should change push --cosign to push --sign=(none|cosign) for consistency with pull --verify=(none|cosign). Sorry for going back and forth.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, we've enhanced the flag according to your reviews

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we wrote a simple integration test that creates a cosign-key-pair and run push&pull test cases, but not sure if it is effective. We couldn't able to run the tests in Vagrant since it could not find the testutil.go file. 🤔 What is the right way to run the all test?

docs/cosign.md Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
cosignCmd.Env = append(cosignCmd.Env, "COSIGN_EXPERIMENTAL=true")
}

cosignCmd.Args = append(cosignCmd.Args, rawRef)
Copy link
Member

@AkihiroSuda AkihiroSuda Nov 30, 2021

Choose a reason for hiding this comment

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

This is racy (sigstore/cosign#648), so at least we have to print a warning when rawRef does not contain the explicit digest value.

Ideally, we should resolve the digest before shelling out cosign (and print the validated digest).

Copy link
Contributor Author

@developer-guy developer-guy Nov 30, 2021

Choose a reason for hiding this comment

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

that's so true, thanks for the warning, done.

Copy link
Member

Choose a reason for hiding this comment

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

The latest revision seems to have this race again

cmd/nerdctl/pull.go Outdated Show resolved Hide resolved
cmd/nerdctl/push.go Outdated Show resolved Hide resolved
cmd/nerdctl/push.go Outdated Show resolved Hide resolved
cmd/nerdctl/pull.go Outdated Show resolved Hide resolved
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks, but this race has to be either resolved or warned with logrus.Warn: https://github.com/containerd/nerdctl/pull/556/files#r759121329

Also please squash commits

@developer-guy developer-guy changed the title WIP: feat: cosign sign feat: cosign sign Dec 8, 2021
cmd/nerdctl/pull.go Outdated Show resolved Hide resolved
cmd/nerdctl/pull.go Outdated Show resolved Hide resolved
@fahedouch
Copy link
Member

why docs/cosign.md is empty ?

@fahedouch
Copy link
Member

root@a608af437e02:/home/github/developer-guy/nerdctl# _output/nerdctl push --cosign-key /home/github/cosign/cosign.key --sign=cosign fahedouch/alpine-cosign:test
INFO[0000] pushing as a reduced-platform image (application/vnd.docker.distribution.manifest.list.v2+json, sha256:00b7511e88b4d70718d5e3ca5fd2377cdaa7d27dd729214202dada4c8c57b287) 
index-sha256:00b7511e88b4d70718d5e3ca5fd2377cdaa7d27dd729214202dada4c8c57b287:    waiting        |--------------------------------------| 
manifest-sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3: waiting        |--------------------------------------| 
layer-sha256:59bf1c3509f33515622619af21ed55bbe26d24913cedbca106468a5fb37a50c3:    waiting        |--------------------------------------| 
config-sha256:c059bfaa849c4d8e4aecaeb3a10c2d9b3d85f5165c66ad3a4d937758128c4d18:   waiting        |--------------------------------------| 
elapsed: 1.6 s                                                                    total:   0.0 B (0.0 B/s)                                         
INFO[0001] cosign: Enter password for private key:      
INFO[0001] cosign: Error: signing [fahedouch/alpine-cosign:test]: getting signer: reading key: inappropriate ioctl for device 

looks like it prevents passing a password by redirected stdin when unset COSIGN_PASSWORD

@developer-guy
Copy link
Contributor Author

why docs/cosign.md is empty ?

fixed, I don't why :/

Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
Co-authored-by: Furkan Türkal <furkan.turkal@trendyol.com>
Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
@developer-guy
Copy link
Contributor Author

anything else do we need to fix or update? kindly ping @AkihiroSuda @fahedouch @ktock

}
return nil
}

Copy link
Member

Choose a reason for hiding this comment

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

The race #556 (comment) seems introduced again in the latest revision.

imgutil.EnsureImage should be called with the verified digest value when verifier == "cosign"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cosign cosign enhancement New feature or request impact/major
Projects
None yet
Development

Successfully merging this pull request may close these issues.

embed signing container image logic into nerdctl by using cosign as a library
5 participants