متقدم
البحث فيأدلة التثبيت
طريقة البحث
  • الصق رسالة الخطأ بين علامتي تنصيص، مثل "permission denied"، لتجد جدول الحل.
  • اختر مجالًا وجزءًا من الدليل (التثبيت، أول الإعدادات، الاستخدام اليومي، الأمان، الحلول) لتصل مباشرة إلى الخطوة الصحيحة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدليل 62Cosign · Security

Install and set up Cosign (sign and verify images)

Cosign (from the Sigstore project) signs container images and other artifacts and verifies them before use, so a cluster runs only images your pipeline really built. It can sign with a key pair, with a cloud KMS key, or keyless with the CI system's identity (no keys to store). It also attaches attestations like SBOMs and scan results. This guide installs Cosign, signs and verifies with keys and keyless in GitHub Actions, adds an SBOM attestation, and covers the common errors.

  • 10 الدروس
  • 8 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

62.1

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.

ItemValue
Programcosign (one binary; also .rpm/.deb on the releases page)
Keys (key mode)cosign.key (private, encrypted with a password), cosign.pub
KMS keysawskms://, azurekms://, gcpkms://, hashivault://
KeylessOIDC identity of the CI job + Fulcio + Rekor (public good instance or your own)
Where signatures livein the image's registry repository

الأوامر في هذا الدرس

62.2

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.

62.3

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@$DIGEST

Better 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.

62.4

Keyless signing in CI (GitHub Actions)

No keys at all: the job's OIDC identity signs. The job needs id-token: write:

.github/workflows/release.yml
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.)

الأوامر في هذا الدرس

62.5

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…

62.6

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@DIGEST

Real 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.

الأوامر في هذا الدرس

62.7

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=false with keys if that matters.

62.8

Update and remove

Download the new binary (or package) and replace it. Remove: rm /usr/local/bin/cosign (signatures stay in the registry).

الأوامر في هذا الدرس

62.9

Fix common problems

ProblemCauseFix
no matching signaturesWrong 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 digestYou signed a tag.Sign IMAGE@sha256:….
CI: getting signer: … no ID token / failed to get OIDC tokenThe job has no OIDC permission.permissions: id-token: write (GitHub) or id_tokens (GitLab).
UNAUTHORIZED when signingNo push rights to the repository.docker login; the signature is written to the same repository.
Verification fails in an air-gapped clusterNo 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 CIThe key is encrypted.Set COSIGN_PASSWORD from a CI secret, or use KMS/keyless.

الأوامر في هذا الدرس

62.10

Next steps

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.

الأوامر في هذا الدرس

كل الأوامر في هذا الفصل