|
| 1 | +# Cosign Signature Verification Guide |
| 2 | + |
| 3 | +This document explains how to verify Docker image signatures created by the CI/CD pipeline using Sigstore Cosign. |
| 4 | + |
| 5 | +## Understanding Keyless Signing |
| 6 | + |
| 7 | +Our pipeline uses **keyless signing** with Sigstore Cosign, which means: |
| 8 | +- No private keys to manage or secure |
| 9 | +- Signatures are linked to GitHub Actions OIDC tokens |
| 10 | +- Certificate identity reflects the exact workflow that signed the image |
| 11 | + |
| 12 | +## Certificate Identity Format |
| 13 | + |
| 14 | +When GitHub Actions signs an image, the certificate identity follows this format: |
| 15 | +``` |
| 16 | +https://github.com/{OWNER}/{REPO}/.github/workflows/{WORKFLOW}.yml@refs/heads/{BRANCH} |
| 17 | +``` |
| 18 | + |
| 19 | +For our main branch pipeline: |
| 20 | +``` |
| 21 | +https://github.com/devakesu/GhostClass/.github/workflows/pipeline.yml@refs/heads/main |
| 22 | +``` |
| 23 | + |
| 24 | +For releases: |
| 25 | +``` |
| 26 | +https://github.com/devakesu/GhostClass/.github/workflows/release.yml@refs/tags/{VERSION} |
| 27 | +``` |
| 28 | + |
| 29 | +## Verification Methods |
| 30 | + |
| 31 | +### Method 1: Regex Pattern (Recommended for Automation) |
| 32 | + |
| 33 | +This method is flexible and works across different workflows and tags: |
| 34 | + |
| 35 | +```bash |
| 36 | +cosign verify \ |
| 37 | + --certificate-identity-regexp="^https://github.com/devakesu/GhostClass/.github/workflows/" \ |
| 38 | + --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \ |
| 39 | + ghcr.io/devakesu/ghostclass:main |
| 40 | +``` |
| 41 | + |
| 42 | +**Advantages:** |
| 43 | +- Works for both `pipeline.yml` and `release.yml` |
| 44 | +- Works for all branches and tags |
| 45 | +- Simpler to maintain |
| 46 | + |
| 47 | +### Method 2: Exact Identity Match (Strict Verification) |
| 48 | + |
| 49 | +For maximum security when you know the exact workflow: |
| 50 | + |
| 51 | +```bash |
| 52 | +# For main branch (pipeline.yml) |
| 53 | +cosign verify \ |
| 54 | + --certificate-identity="https://github.com/devakesu/GhostClass/.github/workflows/pipeline.yml@refs/heads/main" \ |
| 55 | + --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \ |
| 56 | + ghcr.io/devakesu/ghostclass:main |
| 57 | + |
| 58 | +# For releases (release.yml) |
| 59 | +cosign verify \ |
| 60 | + --certificate-identity="https://github.com/devakesu/GhostClass/.github/workflows/release.yml@refs/tags/v1.3.0" \ |
| 61 | + --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \ |
| 62 | + ghcr.io/devakesu/ghostclass:v1.3.0 |
| 63 | +``` |
| 64 | + |
| 65 | +**Advantages:** |
| 66 | +- Most restrictive |
| 67 | +- Ensures signature came from specific workflow and branch |
| 68 | + |
| 69 | +**Disadvantages:** |
| 70 | +- Must update for different workflows or branches |
| 71 | +- Harder to automate |
| 72 | + |
| 73 | +## Deployment System Integration |
| 74 | + |
| 75 | +### Coolify |
| 76 | + |
| 77 | +If you're using Coolify or similar deployment systems that run health checks, update your verification script: |
| 78 | + |
| 79 | +```bash |
| 80 | +#!/bin/bash |
| 81 | +set -e |
| 82 | + |
| 83 | +# Download cosign |
| 84 | +wget -qO /tmp/cosign https://github.com/sigstore/cosign/releases/download/v2.2.4/cosign-linux-amd64 |
| 85 | +chmod +x /tmp/cosign |
| 86 | + |
| 87 | +# Verify signature using regex pattern (more flexible) |
| 88 | +/tmp/cosign verify \ |
| 89 | + --certificate-identity-regexp="^https://github.com/devakesu/GhostClass/.github/workflows/" \ |
| 90 | + --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \ |
| 91 | + ghcr.io/devakesu/ghostclass:main |
| 92 | + |
| 93 | +# Verify attestation |
| 94 | +/tmp/cosign verify-attestation \ |
| 95 | + --type cyclonedx \ |
| 96 | + --certificate-identity-regexp="^https://github.com/devakesu/GhostClass/.github/workflows/" \ |
| 97 | + --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \ |
| 98 | + ghcr.io/devakesu/ghostclass:main |
| 99 | + |
| 100 | +echo "✓ Image signature and attestation verified successfully" |
| 101 | +``` |
| 102 | + |
| 103 | +### Docker Compose / Kubernetes |
| 104 | + |
| 105 | +Add an init container or pre-deployment job: |
| 106 | + |
| 107 | +```yaml |
| 108 | +# Example init container for Kubernetes |
| 109 | +initContainers: |
| 110 | + - name: verify-signature |
| 111 | + image: gcr.io/projectsigstore/cosign:v2.2.4 |
| 112 | + command: |
| 113 | + - sh |
| 114 | + - -c |
| 115 | + - | |
| 116 | + cosign verify \ |
| 117 | + --certificate-identity-regexp="^https://github.com/devakesu/GhostClass/.github/workflows/" \ |
| 118 | + --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \ |
| 119 | + ghcr.io/devakesu/ghostclass:main |
| 120 | +``` |
| 121 | +
|
| 122 | +## Troubleshooting |
| 123 | +
|
| 124 | +### Error: "no signatures found" |
| 125 | +
|
| 126 | +**Possible causes:** |
| 127 | +1. Image was built before signing was implemented |
| 128 | +2. Signing step failed in CI/CD pipeline |
| 129 | +3. Using wrong certificate identity or OIDC issuer |
| 130 | +4. Image digest doesn't match (use `@sha256:...` instead of tags when possible) |
| 131 | + |
| 132 | +**Solutions:** |
| 133 | +```bash |
| 134 | +# Check if signature exists |
| 135 | +cosign tree ghcr.io/devakesu/ghostclass:main |
| 136 | +
|
| 137 | +# Verify with more verbose output |
| 138 | +cosign verify \ |
| 139 | + --certificate-identity-regexp="^https://github.com/devakesu/GhostClass" \ |
| 140 | + --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \ |
| 141 | + ghcr.io/devakesu/ghostclass:main \ |
| 142 | + --verbose |
| 143 | +``` |
| 144 | + |
| 145 | +### Error: "certificate identity mismatch" |
| 146 | + |
| 147 | +Your certificate identity doesn't match what was used during signing. |
| 148 | + |
| 149 | +**Solution:** Use regex pattern instead of exact match: |
| 150 | +```bash |
| 151 | +# ❌ Too specific |
| 152 | +--certificate-identity="https://github.com/devakesu/GhostClass" |
| 153 | +
|
| 154 | +# ✅ Flexible regex |
| 155 | +--certificate-identity-regexp="^https://github.com/devakesu/GhostClass/.github/workflows/" |
| 156 | +``` |
| 157 | + |
| 158 | +### Verifying Specific Image Digest |
| 159 | + |
| 160 | +For maximum security, verify using the image digest instead of tags: |
| 161 | + |
| 162 | +```bash |
| 163 | +# Get the digest |
| 164 | +docker pull ghcr.io/devakesu/ghostclass:main |
| 165 | +docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/devakesu/ghostclass:main |
| 166 | +
|
| 167 | +# Verify the digest |
| 168 | +cosign verify \ |
| 169 | + --certificate-identity-regexp="^https://github.com/devakesu/GhostClass/.github/workflows/" \ |
| 170 | + --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \ |
| 171 | + ghcr.io/devakesu/ghostclass@sha256:abc123... |
| 172 | +``` |
| 173 | + |
| 174 | +## Reference |
| 175 | + |
| 176 | +- [Sigstore Cosign Documentation](https://docs.sigstore.dev/cosign/overview/) |
| 177 | +- [GitHub Actions OIDC](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect) |
| 178 | +- [Keyless Signing Explained](https://docs.sigstore.dev/cosign/keyless/) |
0 commit comments