Skip to content

fix attestation manifest serializing layers as null with zero statements - #7417

Closed
ToniAdreal wants to merge 1 commit into
moby:masterfrom
ToniAdreal:fix-7411-attestation-layers-null
Closed

ToniAdreal wants to merge 1 commit into
moby:masterfrom
ToniAdreal:fix-7411-attestation-layers-null

Conversation

@ToniAdreal

Copy link
Copy Markdown

Fixes #7411

Problem

#7343 fixed the distribution manifest: a layerless image no longer serializes "layers": null. The same pattern is still present in the attestation manifest path. In exporter/containerimage/writer.go, commitAttestationsManifest builds its manifest literal without setting Layers, and the append loop only runs once per statement, so when statements is empty, mfst.Layers stays nil and the marshaled manifest contains "layers": null. The image-spec Manifest.Layers field has no omitempty, so this is the same schema-validating-registry rejection waiting to happen.

Reachability (all on current master):

  • The call site (writer.go:317) enters the attestation path whenever inp.Attestations contains an entry for the platform, there is no length guard.
  • attestation.Unbundle validates and then allocates an empty slice on empty input, no error.
  • attestation.MakeInTotoStatements maps empty in to empty out.

Fix

The same one-liner #7343 used for the distribution manifest: initialize Layers in the manifest literal with make([]ocispecs.Descriptor, 0, len(statements)).

Verification

  • gofmt clean, go vet ./exporter/containerimage/ clean, go build ./exporter/containerimage/ passes.
  • go test ./exporter/containerimage/... passes (the package itself has no test files; exptypes passes).
  • Standalone marshal check: a manifest assembled the same way (literal with the initialized Layers, zero statements) serializes "layers": [] instead of "layers": null (Go 1.27.3, image-spec v1.1.1 as pinned by buildkit).

Scope

I have not reproduced this in a real build: triggering it needs a platform entry in Attestations whose attestation list is empty, and I have not produced that state end to end. The evidence is source-level plus the marshal check above. The integration-test coverage for this path lives in the client tests, which need a daemon, so I am leaving that to CI here.

commitAttestationsManifest builds its manifest without setting Layers,
and the append loop runs zero times when statements is empty, so the
marshaled manifest contains "layers": null. This is the same defect
moby#7341 reported for the distribution manifest, fixed there by moby#7343.
Initialize Layers the same way so an attestation manifest with zero
statements serializes "layers": [].

Fixes moby#7411

Signed-off-by: ToniAdreal <184365500+ToniAdreal@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attestation manifest can still serialize "layers": null when a platform has an empty attestation list (follow-up to #7341 / #7343)

1 participant