201 lines
10 KiB
Markdown
201 lines
10 KiB
Markdown
# Dagger modules
|
|
|
|
The build/scan/deploy logic every CI engine calls. A template renders a
|
|
`dagger call --mod=<base>/<module> <function> --flag=…`, and that indirection is
|
|
what makes seven CI engines run the same code.
|
|
|
|
Two things follow from it, and both were unchecked until 2026-08-21.
|
|
|
|
## The contract gate
|
|
|
|
`tools/scripts/check-dagger-contracts.py` reads every module's `main.go` and
|
|
every `*.j2` under `catalog/templates/`, then asserts that each template's call
|
|
resolves: the module exists, the function exists, and **every flag it passes is
|
|
declared by that function's signature**.
|
|
|
|
The flag half is new. Before it, the gate resolved names and stopped, so a
|
|
template passing `--totally-bogus-flag=x` still printed
|
|
`539 template dagger calls resolve` — measured, not supposed. A misspelt flag
|
|
fails at the very end of a release, inside the customer's repository.
|
|
|
|
Dagger derives a flag from the Go parameter name (`registryUser` →
|
|
`--registry-user`), so the declared set is readable straight from the signature.
|
|
|
|
`_KNOWN_BAD_FLAGS` pins mismatches that are real defects awaiting their own fix.
|
|
It may only shrink, and a pin whose flag the module later declares fails the
|
|
test rather than lingering.
|
|
|
|
## What the gate does NOT check: argument VALUES
|
|
|
|
It validates that `--language` exists. It cannot tell you that the value is one
|
|
the module accepts.
|
|
|
|
`standard-build build` switches on `language` and supports exactly four:
|
|
|
|
go · python · node · php
|
|
|
|
Everything else falls to
|
|
`return nil, fmt.Errorf("unsupported language: %s …")`. Counted across the
|
|
templates today:
|
|
|
|
| language | invocations | `standard-build` supports it |
|
|
|---|---:|---|
|
|
| go | 7 | yes |
|
|
| java | 7 | **no** — falls back to the repo Dockerfile |
|
|
| node | 7 | yes |
|
|
| python | 7 | yes |
|
|
| php | 3 | yes |
|
|
| `{{ jinja }}` | 2 | not statically knowable |
|
|
| generic | 1 | **no** — falls back to the repo Dockerfile |
|
|
|
|
**8 of the 34** `standard-build` invocations name a language the switch does not
|
|
implement, and both fall through to `buildFromDockerfile`. The seven `java` ones
|
|
are `java-spring` across six engines (its Jenkinsfile calls twice); `generic` is
|
|
`_default/.circleci`. Every affected golden-path skeleton ships a Dockerfile —
|
|
checked, all seven — so the fallback has something to build.
|
|
|
|
### Count these PER MODULE, not per repo
|
|
|
|
An earlier revision of this file claimed **22 of 65** invocations passed a
|
|
rejected language, `java` alone being 13. Both numbers came from grepping
|
|
`--language=` across `catalog/templates` and attributing every hit to
|
|
`standard-build`. It is not the only module that takes that flag:
|
|
|
|
| module receiving `--language=` | invocations |
|
|
|---|---:|
|
|
| `standard-build` | 34 |
|
|
| **`sast-scan`** | **23** |
|
|
| not statically attributable | 10 |
|
|
|
|
`sast-scan` has its own language handling, so its 23 hits cannot "pass a language
|
|
`standard-build` rejects" — they were never `standard-build` calls. That is where
|
|
`java 13` came from: 7 real ones plus 5 belonging to `sast-scan` plus 1
|
|
unattributable.
|
|
|
|
The 10 unattributable ones are the single-line call form
|
|
(`--mod=<base>/<module> <function> --flags`), which the contract gate's
|
|
`_MOD_FLAG_RE` also cannot read because it anchors the module at end of line.
|
|
Any count of this kind is only as good as its attribution: a repo-wide grep for a
|
|
flag two modules share measures neither.
|
|
|
|
This is not something a contract gate can catch by reading signatures: the valid
|
|
set lives inside a `switch`, not in the parameter list. Closing it means either
|
|
teaching `standard-build` the missing languages or repointing those templates at
|
|
a module that handles them, and it is a large enough decision to want its own
|
|
review rather than a quiet patch.
|
|
|
|
## Vetting
|
|
|
|
23 of the 26 modules have no `go.mod` — the SDK generates it, with
|
|
`internal/dagger`, at `dagger develop` time. `go vet` cannot resolve them in a
|
|
clean checkout, so `tools/ci/go-vet-modules.sh` vets the modules that do have
|
|
one and reports the rest by name rather than dropping them silently.
|
|
|
|
That script exists because the previous hook (`mirrors-golang`'s `go-vet`)
|
|
invoked `go vet` from the repository root, which has no `go.mod`, so every run
|
|
failed for every path in its scope — `apps/cli` included, which is a real Go
|
|
binary with its own module. It never vetted anything.
|
|
|
|
## Supply-chain evidence (#2143 phase 1, ADR-0068)
|
|
|
|
`standard-build build` reports `image_digest` beside `image_ref`, on both the
|
|
TLS (`Publish`) and plain-HTTP (crane) push paths. `standard-build evidence`
|
|
takes that digest-pinned reference and writes one directory:
|
|
|
|
| file | content |
|
|
|---|---|
|
|
| `sbom.cdx.json` / `sbom.spdx.json` | SBOM of the image (syft, same pin as the `sbom` module) |
|
|
| `provenance.intoto.json` | in-toto Statement, SLSA v1 provenance, subject = the image digest |
|
|
| `SHA256SUMS` | `sha256sum -c` manifest over the two files above |
|
|
|
|
A tag is refused, not resolved: a statement about a tag says nothing about the
|
|
bytes that get deployed. The statement is unsigned evidence; attach it with
|
|
`cosign attest-provenance --predicate evidence/provenance.intoto.json`, which
|
|
refuses a statement whose subject is not `--image`'s digest, and
|
|
`cosign attest-sbom` for the SBOM; both attest functions refuse a tag-only
|
|
`--image`. The logic lives in stdlib-only packages
|
|
(`standard-build/evidence/`, `cosign/attestation/`) so it runs under plain
|
|
`go test`.
|
|
|
|
## Supply-chain stages in the rendered pipelines (#2143 phase 2)
|
|
|
|
All of these are OFF by default. With no switch set, the rendered pipelines
|
|
are byte-identical to before. They are opted in through `spec.pipeline.overrides`.
|
|
|
|
| switch | adds | implies |
|
|
|---|---|---|
|
|
| `supply_chain_evidence: on` | `standard-build evidence` for the published digest, archived as `integraci-evidence/**` | |
|
|
| `evidence_signing: on` | `cosign sign-blob` over `SHA256SUMS` → `SHA256SUMS.sig` + `.bundle` | evidence |
|
|
| `provenance_attestation: on` | `cosign attest-provenance --predicate` on the digest | evidence |
|
|
| `attestation_gate: on` | `cosign verify-attestation-gate`: fails the build when the OPA policy denies | attestation |
|
|
| `scan_sarif: on` | `security-scan sarif`, `secret-scan sarif` (gitleaks, `--redact`), `sast-scan sarif` (semgrep/codeql), archived as `integraci-sarif/*.sarif` | |
|
|
|
|
- **Keyed by digest.** The Build stage chains `image-ref` (digest-pinned when
|
|
the push reports a digest) into `.integraci-image-ref`. Every later step
|
|
re-reads that file and refuses anything that is not `@sha256:<64 hex>`.
|
|
Nothing resolves the tag again.
|
|
- **Wired into the Jenkins templates only.** These are the six whose Build
|
|
stage publishes through `standard-build`: `_default`, go-microservice,
|
|
java-spring, node-nextjs, php-laravel and python-fastapi. The `_default`
|
|
GitHub Actions and GitLab templates call `build` without the required
|
|
`--language` and push with `docker push`, so no digest comes out of them.
|
|
Fix that first.
|
|
- **Credentials.** Jenkins string credentials: the signing key is
|
|
`signing_credential_id` (default `cosign-key`, the one the Sign stage
|
|
already names). The gate's public key is `cosign_public_key_credential`
|
|
(default `cosign-pub`). The key must have an empty password: the stages
|
|
set `COSIGN_PASSWORD=""` and bind no password credential.
|
|
- **Main only for the key.** Evidence runs for every publishing build except
|
|
`uat_pr`. Sign-blob, attest and the gate run in a separate stage limited to
|
|
`branch 'main'` and never for a `*_pr` build, like the Sign stage.
|
|
- **Bound to the pushed name.** Every step also checks that the recorded ref
|
|
is `${IMAGE_NAME}:${INTEGRACI_IMAGE_TAG}@sha256:…`. The file sits in the
|
|
checkout, so a committed one must not be able to redirect the registry
|
|
credential or get a foreign digest signed.
|
|
- **Signed SHA256SUMS.** Verify with
|
|
`cosign verify-blob --insecure-ignore-tlog=true --key cosign.pub --signature SHA256SUMS.sig --bundle SHA256SUMS.bundle SHA256SUMS`
|
|
(drop `--insecure-ignore-tlog` when the pipeline opted into a Rekor), then
|
|
`sha256sum -c --strict SHA256SUMS`.
|
|
- **No public Rekor unless asked for** (owner decision 2026-10-11). Keyed
|
|
signing does not upload to a transparency log by default, so an air-gapped
|
|
build can sign. An entry in the public log would publish the provenance
|
|
itself (registry and git hosts, repository paths, the Jenkins job URL, the
|
|
commit) permanently. Opt in per pipeline with `rekor_public_upload`, or name
|
|
a private Rekor with `rekor_url`; the signing steps and the gate get the same
|
|
choice. See `cosign/README.md` "Transparency log".
|
|
- **The gate.** cosign verifies the signatures, then
|
|
`infra/policies/bundles/attestation-gate` judges the decoded statements:
|
|
subject = this digest, SLSA v1, `builder.id` exactly trusted, a full commit
|
|
pinned, and an SBOM when required. A copy of the policy is embedded in the
|
|
cosign module (`cosign/policy/`) and kept byte-identical by a test. In CI the
|
|
trusted builder is this job (`$JOB_URL`). That proves the signing and
|
|
attaching worked. It is not a promotion-time control, because the job that
|
|
signs is the job that is trusted. Verifying at promotion against
|
|
platform-held trust is still to do.
|
|
|
|
Not yet: the same stages for the non-Jenkins engines and the stack templates
|
|
that do not publish, signing the mirror `SHA256SUMS` (needs a platform signing
|
|
key, see below), promotion-time verification in the deploy gate, the
|
|
render-only fallback, and the rootless/runner matrix.
|
|
|
|
## Air-gapped mirror
|
|
|
|
The modules reach a tenant through `dagger_mirror.py`, which publishes this
|
|
tree into the tenant's own Git server. It now also publishes `SHA256SUMS` at the
|
|
mirror root, computed at publish time over the published bytes, so a runner
|
|
checks its clone with `sha256sum -c --strict SHA256SUMS`. That catches a
|
|
corrupted or partial clone, NOT tampering: the file lives in the same tenant
|
|
repository as the modules, so whoever can push there can recompute it, and
|
|
`sha256sum -c` ignores files it does not list. It becomes tamper evidence only
|
|
once something signs it. That needs a signing key the PLATFORM holds and whose
|
|
public half tenants trust, and no such key exists yet (a product decision, not
|
|
done in phase 2). Evidence `SHA256SUMS` is signable today with
|
|
`cosign sign-blob`; see above.
|
|
|
|
Images are separate. `tools/scripts/dagger-mirror-manifest.py` prints the pinned
|
|
engine image and every tool image the modules pass to `From`, and fails when the
|
|
modules do not agree on one `engineVersion`. `tools/scripts/dagger-mirror-images.sh`
|
|
copies them into the customer registry by digest, reads each one back, and
|
|
writes a lock. Images computed at run time (`From(jdkImage(v))`) are listed as
|
|
unresolved expressions, to be mirrored by hand.
|