-
-
Notifications
You must be signed in to change notification settings - Fork 0
ci(cosign): canonical signing workflow per ADR-041 #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Cramraika
wants to merge
1
commit into
main
Choose a base branch
from
cosign-ci-rollout-20260428
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Cosign image-signing workflow template — copy to <repo>/.github/workflows/cosign.yml | ||
| # Per ADR-041 (Trivy + Cosign deploy gate). Sample distribution scope: 18 app repos. | ||
| # | ||
| # Required GitHub secrets (pull from Infisical-CI MI): | ||
| # COSIGN_PRIVATE_KEY — base64-encoded private key | ||
| # COSIGN_PASSWORD — passphrase for private key | ||
| # GHCR_PAT — GitHub PAT with write:packages (or use built-in GITHUB_TOKEN if same org) | ||
| # | ||
| # Public key for verification: published at https://gist.githubusercontent.com/Cramraika/c246bdb779518a588617839bfe2a75c1/raw/cosign.pub | ||
| # Coolify pre-deploy hook (vps_host/scripts/coolify-hooks/trivy-pre-deploy.sh): | ||
| # - Pulls image | ||
| # - Runs Trivy CVE scan | ||
| # - cosign verify --key <pub-key-url> <image> | ||
| # - Refuses deploy on either Trivy CRITICAL or cosign verify fail | ||
|
|
||
| name: Cosign image signing | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| tags: ['v*'] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| id-token: write # for keyless via OIDC if desired (alternate path) | ||
|
|
||
| jobs: | ||
| build-sign-push: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Log in to GHCR | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Extract metadata | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ghcr.io/${{ github.repository }} | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=ref,event=tag | ||
| type=sha,format=short | ||
|
|
||
| - name: Build and push image | ||
| id: build | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: . | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
|
|
||
| - name: Install Cosign | ||
| uses: sigstore/cosign-installer@v3 | ||
|
|
||
| - name: Sign image with key | ||
| env: | ||
| COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} | ||
| COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} | ||
| run: | | ||
| set -euo pipefail | ||
| for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' ' '); do | ||
| echo "Signing $tag@${{ steps.build.outputs.digest }}" | ||
| cosign sign --yes --key env://COSIGN_PRIVATE_KEY \ | ||
| "$tag@${{ steps.build.outputs.digest }}" | ||
| done | ||
|
|
||
| - name: Generate SBOM (syft) | ||
| uses: anchore/sbom-action@v0 | ||
| with: | ||
| image: ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }} | ||
| format: spdx-json | ||
| output-file: sbom.spdx.json | ||
|
|
||
| - name: Attach SBOM to image | ||
| env: | ||
| COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} | ||
| COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} | ||
| run: | | ||
| cosign attest --yes --key env://COSIGN_PRIVATE_KEY \ | ||
| --predicate sbom.spdx.json --type spdxjson \ | ||
| "ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }}" | ||
|
|
||
| - name: Verify signature (smoke test) | ||
| run: | | ||
| cosign verify \ | ||
| --key https://gist.githubusercontent.com/Cramraika/c246bdb779518a588617839bfe2a75c1/raw/cosign.pub \ | ||
| "ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }}" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
GitHub gist URL immutable revision pinning raw.githubusercontent.com💡 Result:
To pin a GitHub Gist to an immutable revision using raw.githubusercontent.com URLs: The standard raw URL format for a specific revision (immutable, as it won't change even if the Gist is updated) is: https://gist.githubusercontent.com/[username]/[gist_id]/raw/[revision_hash]/[filename] - [username]: Gist owner's username - [gist_id]: The Gist ID (e.g., from https://gist.github.com/username/123abc) - [revision_hash]: Git commit SHA for that revision (found in Gist history or "Raw" button URL) - [filename]: Name of the file in the Gist For single-file Gists without specifying filename, it returns the first/default file. Example: https://gist.githubusercontent.com/atenni/5604615/raw/30d74d258442c7c65512eafab474568dd706c430/testNewGist Omitting [revision_hash] (e.g., https://gist.githubusercontent.com/[username]/[gist_id]/raw/[filename]) points to the latest version (mutable). To get the revision hash: - View Gist revisions via the clock icon or API (GET /gists/{gist_id}). - Click "Raw" on a file; the URL includes the current revision hash. - Use GitHub Gist API: https://api.github.com/gists/[gist_id] returns files with raw_url (latest) and history. Note: https://gist.github.com/.../raw redirects to the gist.githubusercontent.com equivalent. Use curl -L if needed for redirects. Updates to non-pinned URLs may take 2-5 minutes due to caching. Gists are Git repos, so revisions are Git commits; pinning the SHA ensures immutability.
Citations:
🏁 Script executed:
Repository: Cramraika/bulk
Length of output: 784
🏁 Script executed:
Repository: Cramraika/bulk
Length of output: 542
🏁 Script executed:
Repository: Cramraika/bulk
Length of output: 532
Pin the gist URL to an immutable revision to prevent silent signature validation changes.
The current gist URL lacks a revision hash and points to the latest version, which can be edited at any time. Use the immutable format:
https://gist.githubusercontent.com/Cramraika/c246bdb779518a588617839bfe2a75c1/raw/[commit_hash]/cosign.pub(obtain the commit hash from the gist's Raw button or revision history), or vendor the public key directly in the repository.🤖 Prompt for AI Agents