Sub topic 2
Signing and Verifying with a Key Pair
Assume you can build and push OCI images, use a container registry, and understand public-key cryptography. This chapter compares key-based signing with keyless signing and shows how to verify the signer.
Sign a fixed image digest with a key pair
An image tag, such as 1.0.0, can be moved to different content. A digest identifies exact content. Resolve the digest before signing:
docker buildx imagetools inspect registry.example.com/team/app:1.0.0 \
--format '{{json .Manifest.Digest}}'
IMAGE=registry.example.com/team/app@sha256:<digest>
cosign generate-key-pair
cosign sign --key cosign.key "$IMAGE"
cosign verify --key cosign.pub "$IMAGE"cosign generate-key-pair creates an encrypted private key and a public key. Protect cosign.key; anyone with it can create signatures that verify with cosign.pub. Cosign stores the signature as an OCI artifact associated with the image in the registry.
Keyless signing with OIDC
Keyless signing avoids a long-lived private key. Cosign obtains an OpenID Connect (OIDC) identity token from a supported login, then Fulcio issues a short-lived signing certificate. The certificate connects the temporary key to an identity, such as an email address or GitHub Actions workflow.
cosign sign "$IMAGE"
cosign verify \
--certificate-identity [email protected] \
--certificate-oidc-issuer https://accounts.google.com \
"$IMAGE"Keyless signing reduces private-key storage, but verification must check the expected identity and issuer. An issuer is the authority that created the OIDC identity token.
Rekor records signing events
Rekor is Sigstore’s transparency log. Keyless signing records signing metadata, including the certificate and signature, in a tamper-evident public log. The log helps auditors detect unexpected signing events and supports later verification.
A transparency log does not decide whether a signer is trusted. Your verification command or deployment policy must define which identities and issuers are allowed.
Exercise
Why should a verifier pin both certificate identity and OIDC issuer?
Show answer
The identity names who signed, while the issuer identifies which authority authenticated that identity.