chore: publish IntegraCI build modules a11ec75d3e09

This commit is contained in:
dhimaz0445 committed 2026-11-11 03:41:55 +00:00
1 parent 694710104a
commit 3c2b80914e
78 files changed
+4982 -405

No files matched your search

+1 -1
View File
@@ -49,7 +49,7 @@ timestamp (SET) against the Rekor keys it trusts — Sigstore's unless
`--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 (staging test plan).
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
+1 -1
View File
@@ -13,7 +13,7 @@
// do not pass a statement. It replaces a template that shipped literal
// `${BUILD_STARTED_ON}` / `${ACTOR_ID}` placeholders nothing ever
// expanded, labelled a commit id as `sha1` after stripping `sha256:`, and
// claimed `dagger v0.15.0` while every module pins v0.21.7.
// claimed `dagger v0.15.0` while every module pinned v0.21.7.
package attestation
import (
+2 -2
View File
@@ -92,7 +92,7 @@ func validInput() ProvenanceInput {
SourceURI: "git+https://github.com/acme/app@refs/tags/v1.2.3",
SourceDigest: "sha256:" + commit, // what the old docstring told callers to pass
InvocationID: "123",
EngineVersion: "v0.21.7",
EngineVersion: "v0.21.11",
Now: time.Date(2026, 10, 11, 8, 0, 0, 0, time.UTC),
}
}
@@ -115,7 +115,7 @@ func TestProvenancePredicateHasNoPlaceholders(t *testing.T) {
if !strings.Contains(s, `"startedOn": "2026-10-11T08:00:00Z"`) {
t.Fatalf("defaulted timestamp missing:\n%s", s)
}
if strings.Contains(s, "v0.15.0") || !strings.Contains(s, "v0.21.7") {
if strings.Contains(s, "v0.15.0") || !strings.Contains(s, "v0.21.11") {
t.Fatalf("engine version wrong:\n%s", s)
}
}
+128
View File
@@ -0,0 +1,128 @@
package attestation
// Pure helpers for `platform-sign` (ADR-0093 §5, WP-07): the request the sign
// step sends to the platform, and the checks on the platform's answer before
// `cosign attach signature` publishes it. Standard library only.
import (
"encoding/base64"
"encoding/json"
"fmt"
"regexp"
"strings"
)
// PlatformSignPath is the platform route, with the digest as one path segment.
const PlatformSignPath = "/api/v1/artifacts/%s/sign"
var (
platformDigestRE = regexp.MustCompile(`^sha256:[0-9a-f]{64}$`)
// The API's own patterns (app/security/schemas/platform_signing.py).
platformVersionRE = regexp.MustCompile(`^[A-Za-z0-9_][A-Za-z0-9._-]{0,127}$`)
platformRepositoryRE = regexp.MustCompile(`^[a-z0-9][a-z0-9.:/_-]{2,254}$`)
platformServiceRE = regexp.MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)
// A problem `type` URI's last segment: what a refusal is called.
problemSlugRE = regexp.MustCompile(`[a-z0-9-]{1,80}$`)
)
// PlatformSignRequest returns the JSON body of the sign request, after checking
// every value against the API's own grammar (so a refusal is about the image,
// never about a malformed call).
func PlatformSignRequest(serviceID, version, repository, digest string) ([]byte, error) {
if !platformDigestRE.MatchString(digest) {
return nil, fmt.Errorf("--image-digest %q is not sha256:<64 hex>", digest)
}
if !platformServiceRE.MatchString(serviceID) {
return nil, fmt.Errorf("--service-id %q is not a UUID", serviceID)
}
if !platformVersionRE.MatchString(version) {
return nil, fmt.Errorf("--version %q is not an image tag or commit", version)
}
if !platformRepositoryRE.MatchString(repository) || strings.ContainsAny(repository, "@") {
return nil, fmt.Errorf("--repository %q must be a lower-case registry/path with no tag or digest", repository)
}
return json.Marshal(map[string]string{
"service_id": serviceID,
"version": version,
"repository": repository,
})
}
// PlatformSignature is what `cosign attach signature` needs from the answer.
type PlatformSignature struct {
// Payload is the exact simple-signing payload the platform signed.
Payload []byte
// SignatureB64 is the base64 signature over SHA-256(Payload).
SignatureB64 string
KeyFingerprint string
}
// ParsePlatformSignature judges the platform's answer to a sign request.
//
// Anything but 200 is a refusal and an error naming the HTTP status and the
// problem slug (never the request's token). A 200 is accepted only when it is
// about the digest that was asked for, its payload is the cosign simple-signing
// payload for that SAME digest, and the signature is base64: a payload about
// another image must never be attached to this one.
func ParsePlatformSignature(status int, body []byte, digest string) (*PlatformSignature, error) {
if status != 200 {
var problem struct {
Type string `json:"type"`
Detail any `json:"detail"`
}
_ = json.Unmarshal(body, &problem)
slug := problemSlugRE.FindString(problem.Type)
detail := fmt.Sprint(problem.Detail)
if problem.Detail == nil {
detail = ""
}
if len(detail) > 300 {
detail = detail[:300]
}
if status == 0 {
return nil, fmt.Errorf("NOT signed: the platform did not answer")
}
return nil, fmt.Errorf("NOT signed (HTTP %d %s): %s", status, slug, detail)
}
var answer struct {
ImageDigest string `json:"image_digest"`
Payload string `json:"payload"`
Signature string `json:"signature"`
KeyFingerprint string `json:"key_fingerprint"`
}
if err := json.Unmarshal(body, &answer); err != nil {
return nil, fmt.Errorf("NOT signed: the platform's answer is not JSON: %w", err)
}
if answer.ImageDigest != digest {
return nil, fmt.Errorf("NOT signed: the platform signed %q, not %q", answer.ImageDigest, digest)
}
payload, err := base64.StdEncoding.DecodeString(answer.Payload)
if err != nil {
return nil, fmt.Errorf("NOT signed: the payload is not base64: %w", err)
}
var doc struct {
Critical struct {
Image struct {
Digest string `json:"docker-manifest-digest"`
} `json:"image"`
Type string `json:"type"`
} `json:"critical"`
}
if err := json.Unmarshal(payload, &doc); err != nil {
return nil, fmt.Errorf("NOT signed: the payload is not a simple-signing document: %w", err)
}
if doc.Critical.Image.Digest != digest {
return nil, fmt.Errorf("NOT signed: the payload names %q, not %q", doc.Critical.Image.Digest, digest)
}
if doc.Critical.Type != "cosign container image signature" {
return nil, fmt.Errorf("NOT signed: the payload type %q is not a cosign image signature", doc.Critical.Type)
}
if _, err := base64.StdEncoding.DecodeString(answer.Signature); err != nil || answer.Signature == "" {
return nil, fmt.Errorf("NOT signed: the signature is not base64")
}
return &PlatformSignature{
Payload: payload,
SignatureB64: answer.Signature,
KeyFingerprint: answer.KeyFingerprint,
}, nil
}
+121
View File
@@ -0,0 +1,121 @@
package attestation
import (
"encoding/base64"
"encoding/json"
"strings"
"testing"
)
// MUTATION-CHECK (staging, both directions; each must FAIL, not error):
// - ParsePlatformSignature skips the image_digest comparison →
// TestAnAnswerAboutAnotherDigestIsNotAttached FAILS;
// - it skips the payload digest comparison →
// TestAPayloadAboutAnotherImageIsNotAttached FAILS;
// - it treats any 2xx (or 0) as signed → TestARefusalNamesTheSlugAndSignsNothing FAILS;
// - tighten the repository grammar to `[a-z0-9./-]` (drop `:`) →
// TestLegitimateRequestsAreAccepted FAILS on the `host:5000/...` case;
// - loosen PlatformSignRequest to accept any repository →
// TestUnsafeRequestValuesAreRefused FAILS.
const goodDigest = "sha256:" + "ab12ab12ab12ab12ab12ab12ab12ab12ab12ab12ab12ab12ab12ab12ab12ab12"
const otherDigest = "sha256:" + "cd34cd34cd34cd34cd34cd34cd34cd34cd34cd34cd34cd34cd34cd34cd34cd34"
const svc = "66666666-7777-4888-9999-000000000000"
func payloadFor(digest string) string {
doc := map[string]any{
"critical": map[string]any{
"identity": map[string]string{"docker-reference": "registry.acme.test/shop/api"},
"image": map[string]string{"docker-manifest-digest": digest},
"type": "cosign container image signature",
},
"optional": nil,
}
raw, _ := json.Marshal(doc)
return base64.StdEncoding.EncodeToString(raw)
}
func answer(t *testing.T, imageDigest, payloadDigest string) []byte {
t.Helper()
raw, err := json.Marshal(map[string]any{
"image_digest": imageDigest,
"payload": payloadFor(payloadDigest),
"signature": base64.StdEncoding.EncodeToString([]byte("der-signature")),
"key_fingerprint": "fp",
"key_version": 1,
"public_key_pem": "-----BEGIN PUBLIC KEY-----",
})
if err != nil {
t.Fatal(err)
}
return raw
}
func TestLegitimateRequestsAreAccepted(t *testing.T) {
for _, repo := range []string{
"registry.acme.test/shop/api",
"registry.acme.test:5000/repository/docker/shop-api",
"10.0.0.5:8082/team/svc_name",
} {
body, err := PlatformSignRequest(svc, "3f1c30981b56", repo, goodDigest)
if err != nil {
t.Fatalf("%s: %v", repo, err)
}
var got map[string]string
if err := json.Unmarshal(body, &got); err != nil || got["repository"] != repo || got["service_id"] != svc {
t.Fatalf("%s: body %s", repo, body)
}
}
}
func TestUnsafeRequestValuesAreRefused(t *testing.T) {
cases := []struct{ svc, version, repo, digest string }{
{svc, "v1", "registry.acme.test/shop/api", "sha256:short"},
{svc, "v1", "registry.acme.test/shop/api@sha256:x", goodDigest},
{svc, "v1", "registry.acme.test/shop/api;id", goodDigest},
{svc, "v1", "Registry.acme.test/Shop", goodDigest},
{svc, "v1;rm", "registry.acme.test/shop/api", goodDigest},
{"not-a-uuid", "v1", "registry.acme.test/shop/api", goodDigest},
}
for _, c := range cases {
if _, err := PlatformSignRequest(c.svc, c.version, c.repo, c.digest); err == nil {
t.Fatalf("accepted %+v", c)
}
}
}
func TestAMatchingAnswerIsAttached(t *testing.T) {
sig, err := ParsePlatformSignature(200, answer(t, goodDigest, goodDigest), goodDigest)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(sig.Payload), goodDigest) || sig.SignatureB64 == "" {
t.Fatalf("%+v", sig)
}
}
func TestAnAnswerAboutAnotherDigestIsNotAttached(t *testing.T) {
if _, err := ParsePlatformSignature(200, answer(t, otherDigest, otherDigest), goodDigest); err == nil {
t.Fatal("an answer about another digest was accepted")
}
}
func TestAPayloadAboutAnotherImageIsNotAttached(t *testing.T) {
if _, err := ParsePlatformSignature(200, answer(t, goodDigest, otherDigest), goodDigest); err == nil {
t.Fatal("a payload about another image was accepted")
}
}
func TestARefusalNamesTheSlugAndSignsNothing(t *testing.T) {
body := []byte(`{"type":"https://integraci.co/problems/signing-verdict-block","title":"Signing Refused","status":409,"detail":"cve blocks"}`)
_, err := ParsePlatformSignature(409, body, goodDigest)
if err == nil || !strings.Contains(err.Error(), "signing-verdict-block") || !strings.Contains(err.Error(), "409") {
t.Fatalf("got %v", err)
}
if _, err := ParsePlatformSignature(0, nil, goodDigest); err == nil {
t.Fatal("no answer was taken as signed")
}
if _, err := ParsePlatformSignature(202, answer(t, goodDigest, goodDigest), goodDigest); err == nil {
t.Fatal("a non-200 answer was taken as signed")
}
}
+1 -1
View File
@@ -86,7 +86,7 @@ func statementJSON(t *testing.T, o stOpts) []byte {
"resolvedDependencies": deps,
},
"runDetails": map[string]any{
"builder": map[string]any{"id": o.builder, "version": map[string]string{"dagger-engine": "v0.21.7"}},
"builder": map[string]any{"id": o.builder, "version": map[string]string{"dagger-engine": "v0.21.11"}},
"metadata": map[string]string{"invocationId": "42"},
},
},
+4 -2
View File
@@ -1,6 +1,6 @@
{
"name": "cosign",
"engineVersion": "v0.21.7",
"engineVersion": "v0.21.11",
"sdk": {
"source": "go"
},
@@ -11,6 +11,8 @@
"./attestation/gate.go",
"./attestation/verify.go",
"./attestation/tlog.go",
"./policy/attestation_gate.rego"
"./policy/attestation_gate.rego",
"./platform_sign.go",
"./attestation/platformsign.go"
]
}
+12 -3
View File
@@ -49,7 +49,7 @@ const opaImage = "openpolicyagent/opa:1.0.0"
// daggerEngineVersion is the engine every module's dagger.json pins; recorded
// as the provenance builder version. Before #2143 this said v0.15.0.
const daggerEngineVersion = "v0.21.7"
const daggerEngineVersion = "v0.21.11"
// Cosign is the IntegraCI artifact signing module.
type Cosign struct{}
@@ -79,9 +79,18 @@ type VerifyResult struct {
// runs don't pollute each other's keychain / SIGSTORE_* state.
func (m *Cosign) cosignContainer() *dagger.Container {
return dag.Container().
From("gcr.io/projectsigstore/cosign:v2.4.1").
From("gcr.io/projectsigstore/cosign:v3.1.4").
WithEnvVariable("HOME", "/tmp/cosign-home").
WithEnvVariable("COSIGN_YES", "true") // non-interactive
WithEnvVariable("COSIGN_YES", "true"). // non-interactive
// cosign v3 (2026-11-04 bump, docs/security/vuln-remediation-20261104.md)
// defaults to a TUF-fetched signing config, which REFUSES the keyed
// `--tlog-upload=false` this module signs with (v3.1.4
// signcommon.ValidateSigningOptions) and fetches from the public TUF root
// on every call. cosign reads every flag from COSIGN_<FLAG> (options/
// root.go BindViper), and an explicit flag still wins: these two keep
// the v2.4.1 behaviour every caller and verifier here was written for.
WithEnvVariable("COSIGN_USE_SIGNING_CONFIG", "false").
WithEnvVariable("COSIGN_NEW_BUNDLE_FORMAT", "false")
}
// Sign signs a container image with Cosign.
+111
View File
@@ -0,0 +1,111 @@
package main
// PlatformSign: the pipeline's sign step under platform-held signing
// (ADR-0093 §5, WP-07). The private key never leaves the platform's OpenBao;
// this step asks the platform to sign ONE pushed digest and attaches the
// answer with `cosign attach signature`.
import (
"bytes"
"context"
"dagger/cosign/attestation"
"dagger/cosign/internal/dagger"
"fmt"
"io"
"net/http"
"strings"
"time"
)
// PlatformSign asks IntegraCI to sign `<repository>@<image-digest>` with the
// tenant's platform-held key, then attaches that signature to the image.
//
// The call is `POST <api-url>/api/v1/artifacts/<digest>/sign` with
// `{service_id, version, repository}` and the `ci-sign:<service>` token
// (`--token`, scope `artifacts:sign`, bound to the service). The platform
// signs only a digest its own registry read ties to the version's tag, with an
// analysis-of-record image scan of that version and no `block`/`unknown` in
// the security verdict. Any refusal FAILS this call ("NOT signed (HTTP 409
// signing-...)"), so a pipeline whose push was refused, or whose image is
// blocked, carries no signature.
//
// Before attaching, the answer is checked: it must be about the digest that
// was asked for and its payload must name that digest. Nothing goes to a
// transparency log; the platform's own verifier reads the signature with the
// tenant's public key (GET /api/v1/artifact-attestations/custody).
//
// +cache="never"
func (m *Cosign) PlatformSign(
ctx context.Context,
// IntegraCI API base URL
apiURL string,
// The `ci-sign:<service>` token (INTEGRACI_SIGN_TOKEN)
token *dagger.Secret,
serviceID string,
// The commit or image tag the image was built as (its scans are filed under it)
version string,
// registry/path of the pushed image, no tag and no digest
repository string,
// The pushed digest, sha256:<hex> (the archive digest push-archive verified)
imageDigest string,
// Registry username, so cosign can push the signature
// +optional
registryUsername string,
// Registry password/token for --registry-username
// +optional
registryPassword *dagger.Secret,
// The registry is served over plain HTTP / self-signed TLS
// +optional
registryInsecure bool,
) (string, error) {
body, err := attestation.PlatformSignRequest(serviceID, version, repository, imageDigest)
if err != nil {
return "", err
}
if strings.TrimSpace(apiURL) == "" || token == nil {
return "", fmt.Errorf("NOT signed: no --api-url or --token (the platform holds the key)")
}
tokenStr, err := token.Plaintext(ctx)
if err != nil {
return "", fmt.Errorf("read token secret: %w", err)
}
endpoint := strings.TrimRight(apiURL, "/") + fmt.Sprintf(attestation.PlatformSignPath, imageDigest)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(body))
if err != nil {
return "", fmt.Errorf("build request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+tokenStr)
status, answer := 0, []byte(nil)
client := &http.Client{Timeout: 60 * time.Second}
if resp, err := client.Do(req); err == nil {
status = resp.StatusCode
answer, _ = io.ReadAll(io.LimitReader(resp.Body, 64<<10))
resp.Body.Close()
}
sig, err := attestation.ParsePlatformSignature(status, answer, imageDigest)
if err != nil {
return "", err
}
ref := repository + "@" + imageDigest
c, err := withRegistryAuth(ctx, m.cosignContainer(), ref, registryUsername, registryPassword)
if err != nil {
return "", err
}
args := []string{
"cosign", "attach", "signature",
"--payload", "/tmp/sign/payload.json",
"--signature", "/tmp/sign/signature.b64",
}
args = append(args, insecureRegistryArgs(registryInsecure)...)
args = append(args, ref)
_, err = c.
WithNewFile("/tmp/sign/payload.json", string(sig.Payload)).
WithNewFile("/tmp/sign/signature.b64", sig.SignatureB64).
WithExec(args).
Sync(ctx)
if err != nil {
return "", fmt.Errorf("cosign attach signature failed: %w", err)
}
return fmt.Sprintf("signed %s (platform key %s)\n", ref, sig.KeyFingerprint), nil
}