feat(build): attach an agent manifest attestation to built images

Aperta
#55 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, go

Direzione di ricerca

Start with pkg/build/build.go to trace buildImage() and handleAgent(), then read pkg/agentkit/effective/agent.go, pkg/agentkit/abi/render.go, and pkg/agentkit/config/validate.go for manifest inputs. Use pkg/build/build_test.go and its fakeBuildClient to check per-platform attachments, including single-platform builds. Done means deterministic manifests are attached to registry/OCI outputs, contain no secret values or instruction text, --load succeeds, and the documented format is covered by tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/build enhancement security

Problem

Teams want rules such as "in production, only run agents that use our approved model endpoint" or "no agent may run a local command tool". Today there's no easy way to check these before an agent runs:

  • What an agent does is written only in /agent/agent.yaml inside the image. Reading it means pulling the image and opening its files. Policy tools such as Kyverno, Gatekeeper with Ratify, or cosign policies don't do that.
  • The image labels name the runtime and list what the runtime can do (ai.agentkit.capabilities). They don't say what this agent uses: its model, its tools, or the secrets it expects.

What

When AgentKit builds an image, also attach a small JSON document that describes the agent: an agent manifest. Use the in-toto attestation format, the same format BuildKit uses for its SBOM and provenance records. Existing tools can then find it next to the image, and a signature on the image also covers it.

Example contents (the in-toto "predicate"):

{
  "agentkitVersion": "v0.5.0",
  "name": "url-summarizer",
  "runtime": "pydantic-ai",
  "abiVersion": "v1alpha1",
  "agentConfigDigest": "sha256:…",
  "instructionsDigest": "sha256:…",
  "model": {
    "provider": "openai-compatible",
    "name": "gpt-4o-mini",
    "baseURL": "https://api.openai.com/v1",
    "apiKeyEnv": "OPENAI_API_KEY"
  },
  "tools": [
    {"name": "fetch", "transport": "stdio", "command": ["uvx", "mcp-server-fetch"], "env": ["FETCH_TIMEOUT"]},
    {"name": "toolbox", "transport": "streamable-http", "urlEnv": "TOOLBOX_ENDPOINT", "headers": ["Foundry-Features"], "auth": "bearer"}
  ],
  "contextProviders": [{"name": "knowledge", "type": "search"}],
  "env": [{"name": "REQUIRED_FOO", "required": true}],
  "capabilities": ["stdio-mcp", "streamable-http-mcp"]
}

Rules:

  • Names and settings only. No secret values; the build never has them anyway. No instruction text either: record only its SHA-256 (instructionsDigest).
  • For headers, record names only, never values.
  • Same input, same output. Use a stable field order and no timestamps, so rebuilding the same file gives an identical manifest.
  • Every platform gets one. In a multi-platform build, attach a manifest to each platform's image.
  • Include pinned tool packages. If #54 has landed, include each tool's pinned package.
Out of scope
  • Signing. People sign images in their own CI, as AgentKit's release workflow does. Signing the image index also covers the attestations listed inside it.
  • Ready-made Kyverno or Gatekeeper policies. A follow-up can add examples.
  • Changes to image labels or to /agent/agent.yaml.

Why

  • Platform teams can allow or block agents based on what they do, before they run, using policy tools they already have.
  • Each build leaves a record to review: which model, which tools and which secrets the agent uses. Changes show up as a diff between two builds.
  • A hand-written Dockerfile can't easily produce this. It's a reason to trust AgentKit-built images.

How

Where things are
File What it does
pkg/build/build.go buildImage() builds one platform. handleAgent() combines the platforms into one client.Result. The attestation is attached here.
pkg/agentkit/effective/agent.go The build-ready agent. Build the manifest from it.
pkg/agentkit/abi/render.go abi.Render() returns the exact bytes of /agent/agent.yaml. Hash these bytes for agentConfigDigest.
pkg/agentkit/config/validate.go requiredCapabilities() works out which capabilities an agent needs. Reuse it for capabilities.
pkg/version/version.go The AgentKit version string.
pkg/build/build_test.go fakeBuildClient lets you test builds without a real BuildKit.
Steps
  1. Render the manifest. Add a package pkg/agentkit/manifest with a function like Render(agent effective.Agent, agentYAML []byte) ([]byte, error) that returns the JSON above. Keep the field order stable.
  2. Attach it in buildImage(), once per platform:
    • Put the JSON in a file on an empty filesystem, llb.Scratch().File(llb.Mkfile("/agent-manifest.json", 0o644, data)), and solve that to get a reference.
    • Add it to the result:
      res.AddAttestation(platformID, client.Attestation{
          Kind:   gatewaypb.AttestationKindInToto,
          Ref:    ref,
          Path:   "/agent-manifest.json",
          InToto: result.InTotoAttestation{PredicateType: "https://github.com/orka-agents/agentkit/attestations/agent-manifest/v1"},
      })
      
      Leave Subjects empty. BuildKit then points the attestation at the image itself.
    • Use Ref + Path, not ContentFunc. AgentKit runs as a frontend image, and BuildKit rejects ContentFunc there with attestation callback cannot be sent through gateway.
  3. Platform IDs. BuildKit matches attestations to images by platform ID.
    • Today handleAgent() sets the platform list (exptypes.ExporterPlatformsKey) only for multi-platform builds.
    • BuildKit's own Dockerfile frontend sets it for single-platform builds too (see frontend/dockerui/build.go in the buildkit module). You'll likely need to do the same.
  4. --load must still work. Loading into Docker's classic image store may drop attestations. That's acceptable, but the build must not fail.
Tests
  • A golden test for manifest.Render using a full fixture with stdio and remote tools, a context provider and env entries. Compare the exact JSON.
  • A test that the output never contains the instruction text, header values or other config values that could be secret.
  • fakeBuildClient tests that the result has one attestation per platform with the right predicate type and path, for both single- and multi-platform builds.
  • An end-to-end check:
    • Build a fixture to a registry or an OCI layout (--output type=oci,dest=…).
    • Read the attestation back and compare it with the expected JSON.
    • Separately, confirm that a --load build still succeeds.

Run:

go test ./...
make lint
Docs
  • Add docs/agent-manifest.md. It should cover:
    • every field and the predicate type;
    • the stability promise: v1 only adds fields and never renames or removes them;
    • one working way to read the manifest from a registry, for example docker buildx imagetools inspect --raw to find the attestation manifest, then crane or oras to fetch it;
    • an example policy idea, such as blocking agents whose model.baseURL isn't on an allow list.
  • Link the new page from README.md under "More docs".

Done when

  • Images pushed to a registry or exported as OCI include one agent manifest attestation per platform.
  • The manifest matches the documented format and contains no secret values or instruction text.
  • Building the same file twice gives byte-identical manifests.
  • --load builds still succeed.
  • docs/agent-manifest.md explains the format and how to read it.
Lingua principale
Python
Stelle
7
Fork
5
Merge medio
3h 39m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di orka-agents/agentkit

Tutte le issue di orka-agents/agentkit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.