هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
The signature is stored in the registry next to the image (same repository, a special tag). You always sign the digest (@sha256:…), not a tag, because tags can move. Keyless signing gets a short-lived certificate from Sigstore's Fulcio CA for the OIDC identity of the CI job and records it in the public Rekor transparency log.
| Item | Value |
|---|---|
| Program | cosign (one binary; also .rpm/.deb on the releases page) |
| Keys (key mode) | cosign.key (private, encrypted with a password), cosign.pub |
| KMS keys | awskms://, azurekms://, gcpkms://, hashivault:// |
| Keyless | OIDC identity of the CI job + Fulcio + Rekor (public good instance or your own) |
| Where signatures live | in the image's registry repository |
Install on RHEL and Ubuntu
Choose the version from github.com/sigstore/cosign/releases:
CVER=v2.6.1
curl -fsSLo cosign https://github.com/sigstore/cosign/releases/download/$CVER/cosign-linux-amd64
install -m 0755 cosign /usr/local/bin/cosign
cosign version(Or install the .rpm / .deb from the same page with dnf install ./cosign-*.rpm / apt install ./cosign_*.deb.) Log in to your registry first: docker login harbor.example.com — Cosign uses the same credentials.
Sign with a key pair
Good for labs and private setups without internet access to Sigstore:
cosign generate-key-pair
Enter password for private key:
Private key written to cosign.key
Public key written to cosign.pub
IMG=harbor.example.com/shop/shop
DIGEST=$(skopeo inspect --format '{{.Digest}}' docker://$IMG:1.4.0)
cosign sign --key cosign.key --tlog-upload=false $IMG@$DIGEST
cosign verify --key cosign.pub --insecure-ignore-tlog=true $IMG@$DIGESTBetter in companies: keep the key in a KMS (cosign generate-key-pair --kms awskms:///alias/cosign, then --key awskms:///alias/cosign) — the private key never leaves the KMS.
Keyless signing in CI (GitHub Actions)
No keys at all: the job's OIDC identity signs. The job needs id-token: write:
name: release
on:
push:
branches: [main]
permissions:
contents: read
packages: write
id-token: write
jobs:
build-sign:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: sigstore/cosign-installer@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: build
uses: docker/build-push-action@v6
with:
push: true
tags: ghcr.io/org/shop:${{ github.sha }}
- run: cosign sign --yes ghcr.io/org/shop@${{ steps.build.outputs.digest }}Verify — check who signed (the workflow) and which OIDC 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
Verification for ghcr.io/org/shop@sha256:4a1f… --
The following checks were performed on each of these signatures:
- The cosign claims were validated
- Existence of the claims in the transparency log was verified offline
- The code-signing certificate was verified using trusted certificate authority certificates(GitLab CI works the same with id_tokens and the GitLab issuer.)
Attestations: attach an SBOM
Sign a statement about the image — for example its SBOM made by Syft:
syft ghcr.io/org/shop@sha256:4a1f… -o cyclonedx-json > sbom.cdx.json
cosign attest --yes --type cyclonedx --predicate sbom.cdx.json ghcr.io/org/shop@sha256:4a1f…
cosign verify-attestation --type cyclonedx --certificate-identity-regexp 'https://github.com/org/shop/.*' --certificate-oidc-issuer https://token.actions.githubusercontent.com ghcr.io/org/shop@sha256:4a1f… | jq -r '.payload' | base64 -d | jq '.predicateType'
cosign tree ghcr.io/org/shop@sha256:4a1f…Daily use: the commands and the real uses
cosign tree IMAGE@DIGEST
cosign verify --key cosign.pub IMAGE@DIGEST
cosign sign-blob --yes --bundle app.tar.gz.bundle app.tar.gz
cosign verify-blob --bundle app.tar.gz.bundle --certificate-identity ID --certificate-oidc-issuer ISSUER app.tar.gz
cosign copy SRC_IMAGE DST_IMAGE
cosign triangulate IMAGE@DIGESTReal uses at work:
- Sign every release image in CI; verify in the cluster with a policy engine (Kyverno
verifyImages, Sigstore policy-controller) so unsigned images can not run. - Attach SBOMs and vulnerability scan results as attestations.
- Sign release files (
sign-blob) for customers.
Make it safe
Security checklist:
- Always sign and verify digests, never tags.
- Prefer keyless (CI identity) or KMS keys; never commit
cosign.key; protect its password. - Verify the exact identity (
--certificate-identity+--certificate-oidc-issuer), not "any signature". - Enforce verification at deploy time (admission policy), not only in CI.
- Pin the Cosign version and the installer action.
- Private projects: know that the public Rekor log shows signing metadata — use a private Sigstore stack or
--tlog-upload=falsewith keys if that matters.
Update and remove
Download the new binary (or package) and replace it. Remove: rm /usr/local/bin/cosign (signatures stay in the registry).
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
no matching signatures | Wrong key/identity/issuer, or the image was rebuilt (new digest). | Check the digest; compare identity and issuer with the signing job. |
WARNING: Image reference … uses a tag, not a digest | You signed a tag. | Sign IMAGE@sha256:…. |
CI: getting signer: … no ID token / failed to get OIDC token | The job has no OIDC permission. | permissions: id-token: write (GitHub) or id_tokens (GitLab). |
UNAUTHORIZED when signing | No push rights to the repository. | docker login; the signature is written to the same repository. |
| Verification fails in an air-gapped cluster | No access to Rekor/Fulcio roots. | Use key/KMS signing with --insecure-ignore-tlog, or a private Sigstore and its trusted root. |
cosign.key asks for a password in CI | The key is encrypted. | Set COSIGN_PASSWORD from a CI secret, or use KMS/keyless. |
Next steps
- Quick how-to: Sign and verify an image with Cosign.
- Command page: cosign.
- Learn it for the CKS: Sign and verify images. At work: Sign and verify images.
- The SBOM: Syft. Enforce in the cluster: Kyverno. The registry: Harbor.
1Why sign the image digest and not the tag?
A tag can be moved to another image; the digest always means exactly one image.
2What does a keyless verify check besides the signature itself?
The signer's identity (--certificate-identity) and the OIDC issuer.