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
@@ -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"},
},
},