Skip to main content
RunBook Academy

← All labs in Docker & Containers

Lab · intermediate · ~25 min

Lab 24: Cosign image signing and verification

B · Nested virtualisationC · Simulation

Objectives

  • Generate a cosign key pair
  • Sign an image
  • Verify the signature

Prerequisites

  • Lab 5: install Docker; access to a registry

Objective

Sign a Docker image with cosign (key-based) and verify the signature.

Tasks

Task 1: Install cosign

# Pre-built binary
curl -O -L https://github.com/sigstore/cosign/releases/download/v2.4.0/cosign-linux-amd64
sudo install -m 0755 cosign-linux-amd64 /usr/local/bin/cosign
cosign version

Task 2: Generate a key pair

cosign generate-key-pair
# Creates cosign.key (private) and cosign.pub (public)
ls -la cosign.key cosign.pub
chmod 0400 cosign.key

Task 3: Build and tag an image

docker build -t myorg/cosign-test:1.0.0 - <<'EOF'
FROM alpine
RUN echo "ok" > /tmp/hello
EOF

Task 4: Sign the image

COSIGN_PASSWORD=test123 cosign sign --key cosign.key myorg/cosign-test:1.0.0

Task 5: Verify

cosign verify --key cosign.pub myorg/cosign-test:1.0.0
# Verification for myorg/cosign-test:1.0.0 --
# The following checks were performed on each of these signatures:
#   - The cosign signature was validated against the specified public key
# ...

Task 6: Tamper detection

# Modify the image without resigning
docker tag myorg/cosign-test:1.0.0 myorg/cosign-test:1.0.1
docker push myorg/cosign-test:1.0.1 2>/dev/null || true

# Verification should fail
cosign verify --key cosign.pub myorg/cosign-test:1.0.1
# Error: no matching signatures

Task 7: Cleanup

docker rmi myorg/cosign-test:1.0.0 myorg/cosign-test:1.0.1 2>/dev/null

Verification status

Last reviewed
2026-08-09
Executed end to end
not yet run on hardware

The commands and configuration here have been reviewed against the verified software versions, but nobody has run this lab start to finish on a system meeting its prerequisites. Treat the Expected Outcome as the intended result rather than an observed one, and keep the Cleanup section to hand.