Files
attest/pkg/attest/sign.go

30 lines
988 B
Go
Raw Normal View History

2024-04-29 12:52:39 -05:00
package attest
2024-04-29 15:02:21 -05:00
import (
"context"
"fmt"
"github.com/docker/attest/pkg/attestation"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/secure-systems-lab/go-securesystemslib/dsse"
)
// this is only relevant if there are (unsigned) in-toto statements.
func SignStatements(ctx context.Context, idx v1.ImageIndex, signer dsse.SignerVerifier, opts *attestation.SigningOptions) ([]*attestation.Manifest, error) {
2024-04-30 12:23:07 -05:00
// extract attestation manifests from index
2024-08-12 14:49:52 -05:00
attestationManifests, err := attestation.ManifestsFromIndex(idx)
2024-04-29 15:02:21 -05:00
if err != nil {
return nil, fmt.Errorf("failed to load attestation manifests from index: %w", err)
2024-04-29 15:02:21 -05:00
}
2024-04-30 12:23:07 -05:00
// sign every attestation layer in each manifest
for _, manifest := range attestationManifests {
for _, layer := range manifest.OriginalLayers {
2024-08-12 14:49:52 -05:00
err = manifest.Add(ctx, signer, layer.Statement, opts)
if err != nil {
return nil, fmt.Errorf("failed to sign attestation layer %w", err)
}
2024-04-29 15:02:21 -05:00
}
}
return attestationManifests, nil
2024-04-29 15:02:21 -05:00
}