# IntegraCI Cosign Dagger Module Signs and verifies container images with [Cosign / Sigstore](https://sigstore.dev/) inside an isolated Dagger container. ## First-time setup This module follows the standard Dagger module convention — the SDK stub types (`Container`, `Secret`, `File`, `dag`) are generated by Dagger when you run `dagger develop`. Until you do, your IDE will show "undefined" errors. That is expected and matches the other modules in `dagger/`. ```bash cd dagger/cosign dagger develop # generates internal/dagger/, go.mod, go.sum ``` ## Functions | Function | What it does | |---|---| | `Sign` | Sign an image. Either keyless (Fulcio + Rekor + ambient OIDC) or with a private key from OpenBao / file. | | `SignMethod` | Engine-agnostic signing entrypoint: `cosign`, `notation`, `gpg`, `in-toto` or `none`. What the rendered tenant pipelines call. cosign is keyed with `--key` (the rendered default since 2026-10-18) or keyless with `--keyless` (+ `--identity-token`, handed to cosign as `SIGSTORE_ID_TOKEN`, never on argv). With neither flag it signs keyless as it always did and prints a deprecation notice (see below). `--password` for an encrypted key; `--rekor-public-key` with a private `--rekor-url`. | | `Verify` | Verify an image signature. Keyless requires `--identity-regex` + `--issuer-regex` (both anchored to the whole value). | | `AttestSBOM` | Attach a CycloneDX or SPDX SBOM to the image as an in-toto attestation. `--image` must be digest-pinned. | | `AttestProvenance` | Attach an **SLSA Build L3** provenance attestation (predicate type `slsaprovenance1`). `--image` must be digest-pinned (`[:tag]@sha256:<64 hex>`) and `--source-digest` a full commit id (40 or 64 hex). Either builds the predicate from the flags, or attaches the statement `standard-build evidence` wrote (`--predicate`). Private registries: `--registry-username` + `--registry-password` (mounted as a `DOCKER_CONFIG` secret, never on argv) and `--registry-insecure` for plain-HTTP / self-signed registries. | | `VerifyProvenance` | Verify the SLSA provenance is signed, and that its decoded in-toto statement names the image digest as a subject, carries exactly the expected `builder.id`, and has a digest-pinned source dependency from the expected repo (`--image` must be digest-pinned). Use this in admission controllers / ArgoCD `policy-controller` to gate prod promotion. | | `SignBlob` | `cosign sign-blob` a file (written for the `SHA256SUMS` of the evidence set); returns `.sig` and `.bundle`. | | `VerifyAttestationGate` | Verify the attestations with `--public-key`, then judge the decoded statements with the embedded `attestation-gate` OPA policy (subject = digest, `builder.id` in `--trusted-builder`, full commit; SBOM too with `--require-sbom`). Returns an error when the gate denies. Same registry flags as `AttestProvenance`. | ## Transparency log (Rekor) Uploading to the **public** Sigstore Rekor is **off by default** (owner decision, 2026-10-11). A Rekor entry is public and permanent, and for an attestation it carries the provenance itself: registry and git hosts, repository paths, the CI job URL and the commit. | Flag | Effect | |---|---| | *(none)* | Keyed `sign`, `sign-method`, `attest-provenance`, `attest-sbom`, `sign-blob`: no upload (`--tlog-upload=false`). Keyed `verify` / `verify-attestation-gate`: the key alone is checked (`--insecure-ignore-tlog=true`). | | `--public-rekor` | Opt in to the public Sigstore Rekor. | | `--rekor-url https://…` | Use a private Rekor instead (wins over `--public-rekor`). Plain https URL only: no credentials, query or fragment. | | `--rekor-public-key env://…` | The private Rekor's public key (PEM). Mounted and pointed to by `SIGSTORE_REKOR_PUBLIC_KEY`, which then REPLACES the public Sigstore Rekor keys. Accepted by every function above. | **Private Rekor (2026-10-18, #2479):** cosign checks a log entry's signed timestamp (SET) against the Rekor keys it trusts — Sigstore's unless `SIGSTORE_REKOR_PUBLIC_KEY` names a file. `verify`, `verify-provenance` and `verify-attestation-gate` therefore **refuse** `--rekor-url` without `--rekor-public-key` (fail closed, with an error naming the missing flag) instead of failing later with one that reads like a bad signature. Signing functions accept the key and pass it on; they do not require it. Not yet measured against cosign v2.4.1 on a real private Rekor (the module image is v3.1.4 since 2026-11-04, with v2 signing defaults restored by COSIGN_USE_SIGNING_CONFIG=false / COSIGN_NEW_BUNDLE_FORMAT=false; re-measure on staging) (staging test plan). Sign and verify must make the **same** choice. In the rendered Jenkins pipelines the tenant opts in per pipeline with the `spec.pipeline.overrides` keys `rekor_public_upload` / `rekor_url`, and the signing steps and the gate get the same flags. **Keyless is the exception.** A Fulcio certificate lives about ten minutes, so a keyless signature without a log entry cannot be verified later. Keyless calls keep using the public Rekor unless `--rekor-url` names a private one. Owner decision 2026-10-18: rendered pipelines sign **keyed** by default; keyless is a per-service opt-in (`governance.image_signing_mode: keyless`) that always needs an explicit acknowledgement: even with a private Rekor, the public Fulcio CA (this module sets no `--fulcio-url`) logs each certificate publicly. Services that were already keyless are stamped `keyless-legacy` and render exactly as before. `sign-method --method cosign` with neither `--key` nor `--keyless` — the call those older pipelines make, and the modules are not version-pinned — still signs keyless and prints a notice pointing at `docs/customer-docs/image-signing.md`. Keyed signatures made without a log verify like this: ```bash cosign verify-blob --insecure-ignore-tlog=true --key cosign.pub \ --signature SHA256SUMS.sig --bundle SHA256SUMS.bundle SHA256SUMS ``` ## Usage ### Keyless sign in GitHub Actions ```yaml - uses: dagger/dagger-for-github@v6 with: version: latest cmds: | dagger -m ./dagger/cosign call sign \ --image ghcr.io/${{ github.repository }}:${{ github.sha }} \ --keyless \ --identity-token env:ACTIONS_ID_TOKEN_REQUEST_TOKEN ``` ### Keyed sign with OpenBao secret ```bash # Fetch private key from OpenBao first, then: dagger -m ./dagger/cosign call sign \ --image harbor.acme.com/payments/api:1.4.2 \ --private-key file:./cosign.key \ --password env:COSIGN_PASSWORD \ --registry-user robot$payments+ci \ --registry-password env:HARBOR_TOKEN \ --annotations 'sha=$GIT_SHA,build=$BUILD_ID' ``` ### Verify ```bash # Keyed dagger -m ./dagger/cosign call verify \ --image harbor.acme.com/payments/api:1.4.2 \ --public-key file:./cosign.pub # Keyless (any signer from this org with a GitHub Actions token) dagger -m ./dagger/cosign call verify \ --image harbor.acme.com/payments/api:1.4.2 \ --keyless \ --identity-regex '.+@example\.com' \ --issuer-regex 'https://token\.actions\.githubusercontent\.com' ``` ### Attach SBOM as attestation ```bash dagger -m ./dagger/cosign call attest-sbom \ --image harbor.acme.com/payments/api:1.4.2@sha256:<64 hex image digest> \ --sbom file:./sbom-cyclonedx.json \ --predicate-type cyclonedx \ --keyless ``` ### Attach SLSA L3 provenance (release pipeline) ```bash dagger -m ./dagger/cosign call attest-provenance \ --image ghcr.io/integraci/payments-api:1.2.3@sha256:<64 hex image digest> \ --builder-id "https://github.com/integraci/integraci/.github/workflows/release.yml@refs/tags/v1.2.3" \ --source-uri "git+https://github.com/integraci/integraci@refs/tags/v1.2.3" \ --source-digest "$(git rev-parse HEAD)" \ --invocation-id "${{ github.run_id }}" \ --keyless ``` `--image` must name the digest: cosign would otherwise resolve the tag at attest time, and a tag pushed again between build and attest would sign provenance about another build. `--source-digest` is the full commit id (40 or 64 hex; a `sha1:`/`sha256:` prefix is tolerated), never a short sha. Attaching the statement `standard-build evidence` wrote, keyed, to a private registry: ```bash dagger -m ./dagger/cosign call attest-provenance \ --image registry.example/team/orders:abc@sha256:<64 hex> \ --predicate evidence/provenance.intoto.json \ --private-key env://COSIGN_KEY \ --registry-username "$REG_USER" \ --registry-password env://REG_PASS \ --registry-insecure # only for plain-HTTP / self-signed registries ``` ### Verify SLSA provenance before deploy ```bash dagger -m ./dagger/cosign call verify-provenance \ --image ghcr.io/integraci/payments-api:1.2.3@sha256:<64 hex> \ --expected-builder-id "https://github.com/integraci/integraci/.github/workflows/release.yml@refs/tags/v1.2.3" \ --expected-source-repo "https://github.com/integraci/integraci" \ --issuer-regex 'https://token\.actions\.githubusercontent\.com' ``` A refusal is an error: the call exits non-zero, so `verify-provenance … && deploy` stops. Nothing in this repo calls it yet — no OPA rule or pipeline step enforces it (an earlier version of this README named a `golden_standard` rule `require_slsa_l3_provenance` that does not exist). Wiring it into a deploy gate is the consumer's job. Scope: keyless (Fulcio) SLSA v1 attestations only. Key-signed attestations — `attest-provenance --private-key`, and the Jenkins path `tools/ci/attest-provenance.sh` (key-signed, SLSA v0.2) — cannot be verified by this function today. `verify-provenance` decodes each DSSE envelope cosign prints (the statement is base64 inside it) and compares fields exactly: `runDetails.builder.id` must equal `--expected-builder-id`, the source — the FIRST `resolvedDependencies` entry — must be `--expected-source-repo` or that repo followed by `@` (a `git+` prefix and `.git` suffix are tolerated; `…/app-evil` and `…/app/fork` do not match `…/app`) with a full commit id (`gitCommit`/`sha1`/`sha256`, 40 or 64 hex) as its digest, and a subject's sha256 must be the `--image` digest. A repo that lists the expected one only as a later dependency does not pass. Output it cannot parse — anywhere in the stream, even after a match — is a failure, not a skip. `builder.id` is only a string inside what was signed, so the trust anchor is the signer. Without `--identity-regex` the certificate identity must equal `--expected-builder-id` exactly (for GitHub Actions keyless signing both are the workflow ref). `--identity-regex` replaces that binding: a broad pattern such as `https://github\.com/integraci/.+` lets any workflow it admits sign a statement that names the expected builder. Both regexes are wrapped as `^(?:…)$` before cosign sees them (#2435): cosign matches anywhere in the string, so the default issuer regex once also accepted an issuer that merely contained `token.actions.githubusercontent.com`. Keep an identity regex narrow to the one workflow. Before #2337 it substring-matched the raw output, which never contains the base64-encoded builder id, so it could not pass. ## How it integrates with IntegraCI - The Golden Path pipelines call `cosign sign` immediately after `harbor push` so every artifact in Harbor is signed. - The OPA `golden_standard` bundle has a rule (`require_signed_image`) that blocks deploys of unsigned images. - ArgoCD's `policy-controller` admission webhook (in user's cluster) validates the same signature against the public key stored in the user's OpenBao.