Skip to content

Commit

Permalink
Merge pull request #179 from docker/fix-sign-unsigned-statements
Browse files Browse the repository at this point in the history
fix: only sign statements
  • Loading branch information
mrjoelkamp authored Sep 26, 2024
2 parents 203577e + bb0843c commit 2a4bef0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion attestation/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ func layersFromImage(image v1.Image) ([]*Layer, error) {
// copy original annotations
ann := maps.Clone(layerDesc.Annotations)
// only decode intoto statements
stmt := new(intoto.Statement)
var stmt *intoto.Statement
if mt == types.MediaType(intoto.PayloadType) {
stmt = new(intoto.Statement)
err = json.NewDecoder(r).Decode(&stmt)
if err != nil {
return nil, fmt.Errorf("failed to decode statement layer contents: %w", err)
Expand Down
9 changes: 6 additions & 3 deletions sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ func SignStatements(ctx context.Context, idx v1.ImageIndex, signer dsse.SignerVe
// sign every attestation layer in each manifest
for _, manifest := range attestationManifests {
for _, layer := range manifest.OriginalLayers {
err = manifest.Add(ctx, signer, layer.Statement, opts)
if err != nil {
return nil, fmt.Errorf("failed to sign attestation layer %w", err)
// skip layers without statements
if layer.Statement != nil {
err = manifest.Add(ctx, signer, layer.Statement, opts)
if err != nil {
return nil, fmt.Errorf("failed to sign attestation layer %w", err)
}
}
}
}
Expand Down

0 comments on commit 2a4bef0

Please sign in to comment.