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"
|
|
|
|
|
)
|
|
|
|
|
|
2024-08-01 15:35:15 +01:00
|
|
|
// 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 {
|
2024-07-05 09:29:14 +01:00
|
|
|
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 {
|
2024-07-16 10:05:17 +01:00
|
|
|
for _, layer := range manifest.OriginalLayers {
|
2024-08-12 14:49:52 -05:00
|
|
|
err = manifest.Add(ctx, signer, layer.Statement, opts)
|
2024-07-16 10:05:17 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to sign attestation layer %w", err)
|
|
|
|
|
}
|
2024-04-29 15:02:21 -05:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-05 09:29:14 +01:00
|
|
|
return attestationManifests, nil
|
2024-04-29 15:02:21 -05:00
|
|
|
}
|