cosign icon indicating copy to clipboard operation
cosign copied to clipboard

Cosign 2 signs not existing containers

Open tafli opened this issue 11 months ago • 0 comments

Description

cosign v2 seems to sign a not existing image when using a random sha256 digest:

$ cosign-darwin-amd64 sign --output-signature=/dev/stderr --output-certificate=/dev/stdout --key my_cosign.key --tlog-upload=false --upload=false alpine:1.99.99@sha256:$(head /dev/urandom | sha256sum | cut -d " " -f1)
Enter password for private key:
MEUCIBxHLySRmljNghdEfNK39QVCKJgVWjIH1NT9GCbSnEbOAiEAgKDAVFun8338JSivcof0o5o64ifNipqdg4kpIKuuCoM=-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEICBzllUzhpZ07UKnhhaZ73gCSuZw
2fHDW+Mg69RtW3FQ8zBF4HZgPcXvJg8Gn4xa+qAtoJ3asunEZLmFupzZoQ==
-----END PUBLIC KEY-----
Certificate wrote in the file /dev/stdout

$ echo $?
0

However, when not using a digest, the behavior is as expected as cosign tries to retrieve the tags digest but can't find the image:

$ cosign-darwin-amd64 sign --output-signature=/dev/stderr --output-certificate=/dev/stdout --key my_cosign.key --tlog-upload=false --upload=false alpine:1.99.99
Enter password for private key:
WARNING: Image reference alpine:1.99.99 uses a tag, not a digest, to identify the image to sign.
    This can lead you to sign a different image than the intended one. Please use a
    digest (example.com/ubuntu@sha256:abc123...) rather than tag
    (example.com/ubuntu:latest) for the input to cosign. The ability to refer to
    images by tag will be removed in a future release.

Error: signing [alpine:1.99.99]: accessing entity: entity not found in registry
main.go:74: error during command execution: signing [alpine:1.99.99]: accessing entity: entity not found in registry

$ echo $?
1

Tested out with cosign v1 and the outcome using a digest is the same as without.

Version cosign version: 2.1.1 (tested on macOS and Windows)

Expected behavior

Signing an image with digest that does not exist in the registry shouldn't be possible and the same output shout be given as with signing without a digest:

$ cosign-darwin-amd64 sign --output-signature=/dev/stderr --output-certificate=/dev/stdout --key my_cosign.key --tlog-upload=false --upload=false alpine:1.99.99@sha256:$(head /dev/urandom | sha256sum | cut -d " " -f1)
Enter password for private key:

Error: signing [alpine:1.99.99@sha256:<sha256-digest>]: accessing entity: entity not found in registry
main.go:74: error during command execution: signing [alpine:1.99.99]: accessing entity: entity not found in registry

$ echo $?
1

tafli avatar Aug 17 '23 09:08 tafli