-
Notifications
You must be signed in to change notification settings - Fork 0
1. How to self sign a container ?
Self-signing a container involves creating a cryptographic signature using your own keys, ensuring authenticity and integrity. Here’s a straightforward way to do this using common tools like cosign, which is widely adopted for container signing:
First, download and install the latest version of cosign from the official repository:
# Linux/macOS
curl -LO "https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64"
chmod +x cosign-linux-amd64
sudo mv cosign-linux-amd64 /usr/local/bin/cosignVerify the installation:
cosign versionUse cosign generate-key-pair to create public/private keys:
cosign generate-key-pairThis generates two files in your current directory:
-
cosign.key(private key, protect this securely) -
cosign.pub(public key, used for verification)
Important: Keep your
cosign.keysecure and private. It should not be exposed publicly or shared.
First, ensure your image is pushed to your registry. For example:
docker tag my-image:latest myregistry.example.com/my-image:latest
docker push myregistry.example.com/my-image:latestNow, sign the pushed container image:
cosign sign --key cosign.key myregistry.example.com/my-image:latestThis command attaches your cryptographic signature to the image.
To verify the signature, you (or anyone else) can run:
cosign verify --key cosign.pub myregistry.example.com/my-image:latestIf verification is successful, you’ll see details about the signature.
- Provide your public key (
cosign.pub) to anyone who needs to verify your images. - The public key can be freely shared, and it's common to publish it publicly or distribute it via a secure key management solution.
- Docker Content Trust (Notary v1) — Integrated into Docker, but considered less straightforward than cosign.
- Notary v2 (experimental, still evolving standard).
- Sigstore tooling (cosign, Fulcio, Rekor) — Currently the easiest and most widely recommended approach.
- Use secure storage for your private key (
cosign.key). - Automate signing processes through CI/CD.
- Consider key rotation regularly.
That's the simplest and most effective way to self-sign your container images.