Cosign
A container image signing tool
A container image signing tool
Cosign is a core tool of the Sigstore project that provides the ability to add digital signatures to container images and verify them. As software supply chain security has become more important, it has become essential to prove that deployed container images come from a trusted source and have not been tampered with.
Cosign's most notable feature is "keyless signing." Traditional signing methods require a private key to be stored securely, but Cosign generates a temporary key and signs through OIDC (OpenID Connect)-based authentication. By using workflow identity in GitHub Actions and GitLab CI, you can sign without the burden of key management.
Signed images are recorded in Rekor (a transparency log), so who signed them and when can be publicly verified. This makes it possible to meet SLSA (Supply-chain Levels for Software Artifacts) requirements and enables audit trails.
In a Kubernetes environment, it can be integrated with Kyverno or Gatekeeper to block the deployment of unsigned images. This allows you to enforce a policy of "deploy only trusted images to the cluster."
# Cosign μ€μΉ (macOS)
brew install cosign
# Keyless μλͺ
(GitHub Actionsμμ μλμΌλ‘ OIDC ν ν° μ¬μ©)
cosign sign --yes ghcr.io/myorg/myapp:v1.0.0
# μλͺ
κ²μ¦
cosign verify ghcr.io/myorg/myapp:v1.0.0 \
--certificate-identity=https://github.com/myorg/myapp/.github/workflows/build.yml@refs/tags/v1.0.0 \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com
# SBOM μ²¨λΆ (μννΈμ¨μ΄ ꡬμ±μμ λͺ©λ‘)
cosign attach sbom --sbom sbom.spdx ghcr.io/myorg/myapp:v1.0.0
# Attestation μΆκ° (λΉλ μΆμ² μ¦λͺ
)
cosign attest --predicate provenance.json --type slsaprovenance ghcr.io/myorg/myapp:v1.0.0
# GitHub Actions μν¬νλ‘ μμ
# .github/workflows/build.yml
jobs:
build:
permissions:
id-token: write # OIDC ν ν° λ°κΈμ νμ
packages: write
steps:
- uses: sigstore/cosign-installer@v3
- run: |
cosign sign --yes ${{ env.IMAGE_TAG }}
Senior: "To prepare for the supply chain security audit, we need to sign all production images. Let's add Cosign keyless to the CI pipeline."
Junior: "How do we handle key management? Should we put it in a secrets store?"
Senior: "If you use keyless mode, it signs automatically with GitHub OIDC. No key management is needed. And since it's recorded in Rekor, an audit log is left automatically too."
Interviewer: "How would you implement container image supply chain security?"
Candidate: "I'd sign images in CI with Cosign and allow only signature-verified images to be deployed through Kyverno policies. With keyless signing, I'd sign based on OIDC without the burden of key management, and track audits with the Rekor transparency log."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Reviewer: "The --certificate-identity option is missing from cosign verify. If you don't verify the signer's identity, any signature will pass."
Author: "You're right. I'll fix it by also specifying the workflow file path and the OIDC issuer, so that only signatures made by our CI are allowed."