Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
With a key pair:
cosign generate-key-pair
cosign sign --key cosign.key registry.example.com/shop/api@sha256:4a1f…
cosign verify --key cosign.pub registry.example.com/shop/api@sha256:4a1f…Keyless in GitHub Actions (no key to store): cosign sign --yes IMAGE@DIGEST with permissions: id-token: write.
Step by step
- Always sign the digest, never only the tag — get it from the push or:
docker buildx imagetools inspect registry.example.com/shop/api:1.4.2 --format '{{.Manifest.Digest}}'- Key pair (quick answer):
cosign.keyis encrypted with a password — keep it in a secret store (or use a cloud KMS:--key awskms://…,azurekms://…). Share onlycosign.pub. - Keyless in CI — the signature is tied to the workflow identity, recorded in the public transparency log (Rekor):
permissions:
contents: read
packages: write
id-token: write
steps:
- run: cosign sign --yes ghcr.io/org/shop@${{ steps.build.outputs.digest }}- Verify keyless — check who signed (the workflow) and the issuer:
cosign verify ghcr.io/org/shop@sha256:4a1f… --certificate-identity "https://github.com/org/shop/.github/workflows/release.yml@refs/heads/main" --certificate-oidc-issuer "https://token.actions.githubusercontent.com" -o text- See what is attached (signatures, SBOM attestations):
cosign tree registry.example.com/shop/api@sha256:4a1f…- Enforce it in Kubernetes — Kyverno
verifyImages(or Sigstore policy-controller) refuses Pods with unsigned images:
verifyImages:
- imageReferences: ["registry.example.com/shop/*"]
attestors:
- entries:
- keys:
publicKeys: |-
-----BEGIN PUBLIC KEY-----
<cosign.pub content>
-----END PUBLIC KEY-----Check that it worked
cosign verify prints the verified signature (exit code 0); verifying a different digest fails; and in the cluster a Pod with an unsigned image is refused (or reported, in Audit mode).
Common problems
| Problem | Cause | Fix |
|---|---|---|
no matching signatures | Signed another digest (or only the tag moved). | Sign and verify the same @sha256: digest. |
| Keyless verify fails on identity | --certificate-identity does not match the workflow path/branch exactly. | Copy it from the signature (cosign verify … -o text); or use --certificate-identity-regexp. |
UNAUTHORIZED when signing | No push rights to the registry (signatures are stored there). | Log in with a robot/token that can push. |
| Private/air-gapped setup | No access to the public transparency log. | Key pair with --tlog-upload=false (and verify with --insecure-ignore-tlog), or a private Sigstore. |
Lost cosign.key password | Key can not be used. | Make a new key pair; re-sign; distribute the new public key. |
| Pods blocked after enabling the policy | Old, unsigned images still in use. | Start in Audit mode; sign images; then Enforce. |
Go further
- Command pages: cosign, docker, kubectl.
- Next how-tos: Create an SBOM for an image, Enforce a Kubernetes policy with Kyverno, Push an image to a private registry, Sign Git commits.
- Full guide: Cosign. Learn it: CKS — Sign images, Docker — Sign, GitHub Actions — Provenance.
1Why sign the digest and not the tag?
A tag can point to another image later; a digest always means exactly one image.
2What does keyless signing in CI use instead of a stored private key?
The workflow's OIDC identity — a short-lived certificate recorded in the transparency log.