2021-07-09 18:01:46 -07:00
|
|
|
package cosign
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto"
|
2021-11-04 23:26:22 -07:00
|
|
|
"crypto/x509"
|
2021-10-01 11:10:36 -07:00
|
|
|
"encoding/base64"
|
2021-07-09 18:01:46 -07:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2021-10-28 15:48:35 -07:00
|
|
|
"strings"
|
|
|
|
|
2021-11-04 23:26:22 -07:00
|
|
|
"github.com/sigstore/cosign/cmd/cosign/cli/fulcio"
|
2021-11-03 10:45:35 +03:00
|
|
|
"github.com/sigstore/cosign/pkg/oci/remote"
|
2021-08-02 13:51:36 -07:00
|
|
|
|
2021-07-09 18:01:46 -07:00
|
|
|
"github.com/go-logr/logr"
|
|
|
|
"github.com/google/go-containerregistry/pkg/name"
|
2021-11-03 10:45:35 +03:00
|
|
|
"github.com/in-toto/in-toto-golang/in_toto"
|
|
|
|
"github.com/kyverno/kyverno/pkg/engine/common"
|
2021-12-11 01:16:22 +05:30
|
|
|
"github.com/minio/pkg/wildcard"
|
2021-07-09 18:01:46 -07:00
|
|
|
"github.com/pkg/errors"
|
2021-11-03 10:45:35 +03:00
|
|
|
"github.com/sigstore/cosign/cmd/cosign/cli/options"
|
2021-07-09 18:01:46 -07:00
|
|
|
"github.com/sigstore/cosign/pkg/cosign"
|
2021-11-03 10:45:35 +03:00
|
|
|
"github.com/sigstore/cosign/pkg/cosign/attestation"
|
|
|
|
"github.com/sigstore/cosign/pkg/oci"
|
|
|
|
sigs "github.com/sigstore/cosign/pkg/signature"
|
2021-07-09 18:01:46 -07:00
|
|
|
"github.com/sigstore/sigstore/pkg/signature"
|
2021-12-11 01:16:22 +05:30
|
|
|
"github.com/sigstore/sigstore/pkg/signature/payload"
|
2021-07-09 18:01:46 -07:00
|
|
|
)
|
|
|
|
|
2022-01-17 04:06:44 +00:00
|
|
|
// ImageSignatureRepository is an alternate signature repository
|
|
|
|
var ImageSignatureRepository string
|
2021-12-06 18:08:16 -06:00
|
|
|
|
2021-11-04 23:26:22 -07:00
|
|
|
type Options struct {
|
2021-12-16 11:49:44 +05:30
|
|
|
ImageRef string
|
|
|
|
Key string
|
|
|
|
Roots []byte
|
|
|
|
Subject string
|
|
|
|
Issuer string
|
|
|
|
Annotations map[string]string
|
|
|
|
Repository string
|
|
|
|
Log logr.Logger
|
2021-11-04 23:26:22 -07:00
|
|
|
}
|
|
|
|
|
2021-10-29 16:06:03 +01:00
|
|
|
// VerifySignature verifies that the image has the expected key
|
2021-11-04 23:26:22 -07:00
|
|
|
func VerifySignature(opts Options) (digest string, err error) {
|
|
|
|
log := opts.Log
|
2021-11-03 10:45:35 +03:00
|
|
|
ctx := context.Background()
|
2021-11-04 23:26:22 -07:00
|
|
|
var remoteOpts []remote.Option
|
|
|
|
ro := options.RegistryOptions{}
|
|
|
|
remoteOpts, err = ro.ClientOpts(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.Wrap(err, "constructing client options")
|
|
|
|
}
|
2021-11-03 10:45:35 +03:00
|
|
|
|
2021-11-04 23:26:22 -07:00
|
|
|
cosignOpts := &cosign.CheckOpts{
|
|
|
|
Annotations: map[string]interface{}{},
|
|
|
|
RegistryClientOpts: remoteOpts,
|
2021-07-09 18:01:46 -07:00
|
|
|
}
|
|
|
|
|
2021-11-04 23:26:22 -07:00
|
|
|
if opts.Key != "" {
|
|
|
|
if strings.HasPrefix(opts.Key, "-----BEGIN PUBLIC KEY-----") {
|
|
|
|
cosignOpts.SigVerifier, err = decodePEM([]byte(opts.Key))
|
|
|
|
} else {
|
|
|
|
cosignOpts.SigVerifier, err = sigs.PublicKeyFromKeyRef(ctx, opts.Key)
|
|
|
|
}
|
|
|
|
} else {
|
2021-12-11 01:16:22 +05:30
|
|
|
cosignOpts.CertEmail = ""
|
2021-11-04 23:26:22 -07:00
|
|
|
cosignOpts.RootCerts, err = getX509CertPool(opts.Roots)
|
2021-07-09 18:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2021-11-04 23:26:22 -07:00
|
|
|
return "", errors.Wrap(err, "loading credentials")
|
2021-07-09 18:01:46 -07:00
|
|
|
}
|
|
|
|
|
2021-11-04 23:26:22 -07:00
|
|
|
if opts.Repository != "" {
|
|
|
|
signatureRepo, err := name.NewRepository(opts.Repository)
|
2021-09-16 16:11:38 -07:00
|
|
|
if err != nil {
|
2021-11-04 23:26:22 -07:00
|
|
|
return "", errors.Wrapf(err, "failed to parse signature repository %s", opts.Repository)
|
2021-09-16 16:11:38 -07:00
|
|
|
}
|
2021-11-03 10:45:35 +03:00
|
|
|
|
2021-11-04 23:26:22 -07:00
|
|
|
cosignOpts.RegistryClientOpts = append(cosignOpts.RegistryClientOpts, remote.WithTargetRepository(signatureRepo))
|
2021-11-03 10:45:35 +03:00
|
|
|
}
|
2021-09-16 16:11:38 -07:00
|
|
|
|
2021-11-04 23:26:22 -07:00
|
|
|
ref, err := name.ParseReference(opts.ImageRef)
|
2021-11-03 10:45:35 +03:00
|
|
|
if err != nil {
|
|
|
|
return "", errors.Wrap(err, "failed to parse image")
|
2021-09-16 16:11:38 -07:00
|
|
|
}
|
|
|
|
|
2021-11-03 10:45:35 +03:00
|
|
|
verified, _, err := client.Verify(ctx, ref, cosign.SignaturesAccessor, cosignOpts)
|
2021-07-09 18:01:46 -07:00
|
|
|
if err != nil {
|
2021-07-20 20:28:11 -07:00
|
|
|
msg := err.Error()
|
2021-11-04 23:26:22 -07:00
|
|
|
log.Info("image verification failed", "error", msg)
|
2021-10-26 10:41:27 -07:00
|
|
|
if strings.Contains(msg, "MANIFEST_UNKNOWN: manifest unknown") {
|
2021-07-20 20:28:11 -07:00
|
|
|
return "", fmt.Errorf("signature not found")
|
|
|
|
} else if strings.Contains(msg, "no matching signatures") {
|
2021-10-26 10:41:27 -07:00
|
|
|
return "", fmt.Errorf("signature mismatch")
|
2021-07-20 20:28:11 -07:00
|
|
|
}
|
|
|
|
|
2021-10-26 10:41:27 -07:00
|
|
|
return "", err
|
2021-07-09 18:01:46 -07:00
|
|
|
}
|
|
|
|
|
2021-12-11 01:16:22 +05:30
|
|
|
payload, err := extractPayload(opts.ImageRef, verified, log)
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.Wrap(err, "failed to get payload")
|
|
|
|
}
|
|
|
|
|
2022-01-12 20:49:52 -08:00
|
|
|
if opts.Issuer != "" {
|
|
|
|
issuer, err := extractIssuer(opts.ImageRef, payload, log)
|
|
|
|
if err == nil && (issuer != opts.Issuer) {
|
|
|
|
return "", errors.Wrap(err, "issuer mismatch")
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", errors.Wrap(err, "issuer not found")
|
2021-12-11 01:16:22 +05:30
|
|
|
}
|
|
|
|
|
2022-01-12 20:49:52 -08:00
|
|
|
if opts.Subject != "" {
|
|
|
|
subject, err := extractSubject(opts.ImageRef, payload, log)
|
|
|
|
if err == nil && wildcard.Match(opts.Subject, subject) {
|
|
|
|
return "", errors.Wrap(err, "subject mismatch")
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", errors.Wrap(err, "subject not found")
|
2021-12-11 01:16:22 +05:30
|
|
|
}
|
|
|
|
|
2021-12-16 11:49:44 +05:30
|
|
|
err = checkAnnotations(payload, opts.Annotations, log)
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.Wrap(err, "annotation mismatch")
|
|
|
|
}
|
|
|
|
|
2021-12-11 01:16:22 +05:30
|
|
|
digest, err = extractDigest(opts.ImageRef, payload, log)
|
2021-07-09 18:01:46 -07:00
|
|
|
if err != nil {
|
|
|
|
return "", errors.Wrap(err, "failed to get digest")
|
|
|
|
}
|
|
|
|
|
|
|
|
return digest, nil
|
|
|
|
}
|
|
|
|
|
2021-11-04 23:26:22 -07:00
|
|
|
func getX509CertPool(roots []byte) (*x509.CertPool, error) {
|
|
|
|
if roots == nil {
|
|
|
|
return fulcio.GetRoots(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cp := x509.NewCertPool()
|
|
|
|
if !cp.AppendCertsFromPEM(roots) {
|
|
|
|
return nil, fmt.Errorf("error creating root cert pool")
|
|
|
|
}
|
|
|
|
|
|
|
|
return cp, nil
|
|
|
|
}
|
|
|
|
|
2021-10-05 22:42:42 -07:00
|
|
|
// FetchAttestations retrieves signed attestations and decodes them into in-toto statements
|
|
|
|
// https://github.com/in-toto/attestation/blob/main/spec/README.md#statement
|
2021-11-04 23:26:22 -07:00
|
|
|
func FetchAttestations(imageRef string, key string, repository string, log logr.Logger) ([]map[string]interface{}, error) {
|
2021-11-03 10:45:35 +03:00
|
|
|
ctx := context.Background()
|
|
|
|
var pubKey signature.Verifier
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if strings.HasPrefix(key, "-----BEGIN PUBLIC KEY-----") {
|
|
|
|
pubKey, err = decodePEM([]byte(key))
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "decode pem")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pubKey, err = sigs.PublicKeyFromKeyRef(ctx, key)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "loading public key")
|
|
|
|
}
|
2021-10-01 11:10:36 -07:00
|
|
|
}
|
|
|
|
|
2021-11-03 10:45:35 +03:00
|
|
|
var opts []remote.Option
|
|
|
|
ro := options.RegistryOptions{}
|
|
|
|
|
|
|
|
opts, err = ro.ClientOpts(ctx)
|
2021-10-01 11:10:36 -07:00
|
|
|
if err != nil {
|
2021-11-03 10:45:35 +03:00
|
|
|
return nil, errors.Wrap(err, "constructing client options")
|
|
|
|
}
|
|
|
|
|
|
|
|
if repository != "" {
|
|
|
|
signatureRepo, err := name.NewRepository(repository)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "failed to parse signature repository %s", repository)
|
|
|
|
}
|
|
|
|
opts = append(opts, remote.WithTargetRepository(signatureRepo))
|
2021-10-01 11:10:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
cosignOpts := &cosign.CheckOpts{
|
2021-11-03 10:45:35 +03:00
|
|
|
ClaimVerifier: cosign.IntotoSubjectClaimVerifier,
|
2021-11-19 00:12:12 -08:00
|
|
|
SigVerifier: pubKey,
|
2021-11-03 10:45:35 +03:00
|
|
|
RegistryClientOpts: opts,
|
2021-10-01 11:10:36 -07:00
|
|
|
}
|
|
|
|
|
2021-11-03 10:45:35 +03:00
|
|
|
ref, err := name.ParseReference(imageRef)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to parse image")
|
2021-10-01 11:10:36 -07:00
|
|
|
}
|
|
|
|
|
2021-11-03 10:45:35 +03:00
|
|
|
verified, _, err := client.Verify(context.Background(), ref, cosign.AttestationsAccessor, cosignOpts)
|
2021-10-01 11:10:36 -07:00
|
|
|
if err != nil {
|
2021-10-26 10:41:27 -07:00
|
|
|
msg := err.Error()
|
2021-11-04 23:26:22 -07:00
|
|
|
log.Info("failed to fetch attestations", "error", msg)
|
2021-10-26 10:41:27 -07:00
|
|
|
if strings.Contains(msg, "MANIFEST_UNKNOWN: manifest unknown") {
|
|
|
|
return nil, fmt.Errorf("not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, err
|
2021-10-01 11:10:36 -07:00
|
|
|
}
|
|
|
|
|
2021-10-05 22:42:42 -07:00
|
|
|
inTotoStatements, err := decodeStatements(verified)
|
2021-10-01 11:10:36 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-10-05 22:42:42 -07:00
|
|
|
return inTotoStatements, nil
|
2021-10-01 11:10:36 -07:00
|
|
|
}
|
|
|
|
|
2021-11-03 10:45:35 +03:00
|
|
|
func decodeStatements(sigs []oci.Signature) ([]map[string]interface{}, error) {
|
2021-10-05 22:42:42 -07:00
|
|
|
if len(sigs) == 0 {
|
|
|
|
return []map[string]interface{}{}, nil
|
2021-10-01 11:10:36 -07:00
|
|
|
}
|
|
|
|
|
2021-10-05 22:42:42 -07:00
|
|
|
decodedStatements := make([]map[string]interface{}, len(sigs))
|
|
|
|
for i, sig := range sigs {
|
2021-11-03 10:45:35 +03:00
|
|
|
payload, err := sig.Payload()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to get payload")
|
|
|
|
}
|
2021-10-05 22:42:42 -07:00
|
|
|
data := make(map[string]interface{})
|
2021-11-03 10:45:35 +03:00
|
|
|
if err := json.Unmarshal(payload, &data); err != nil {
|
2021-10-05 22:42:42 -07:00
|
|
|
return nil, errors.Wrapf(err, "failed to unmarshal JSON payload: %v", sig)
|
|
|
|
}
|
2021-11-03 10:45:35 +03:00
|
|
|
decodedStatement, err := decodeStatement(data["payload"].(string))
|
2021-10-02 01:19:47 -07:00
|
|
|
if err != nil {
|
2021-11-03 10:45:35 +03:00
|
|
|
return nil, errors.Wrapf(err, "failed to decode statement %s", string(payload))
|
2021-10-02 01:19:47 -07:00
|
|
|
}
|
|
|
|
|
2021-10-05 22:42:42 -07:00
|
|
|
decodedStatements[i] = decodedStatement
|
|
|
|
}
|
2021-10-01 11:10:36 -07:00
|
|
|
|
2021-10-05 22:42:42 -07:00
|
|
|
return decodedStatements, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeStatement(payloadBase64 string) (map[string]interface{}, error) {
|
|
|
|
statementRaw, err := base64.StdEncoding.DecodeString(payloadBase64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "failed to base64 decode payload for %v", statementRaw)
|
|
|
|
}
|
|
|
|
|
2021-10-06 11:18:36 -07:00
|
|
|
var statement in_toto.Statement
|
|
|
|
if err := json.Unmarshal(statementRaw, &statement); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if statement.PredicateType != attestation.CosignCustomProvenanceV01 {
|
|
|
|
// This assumes that the following statements are JSON objects:
|
|
|
|
// - in_toto.PredicateSLSAProvenanceV01
|
|
|
|
// - in_toto.PredicateLinkV1
|
|
|
|
// - in_toto.PredicateSPDX
|
|
|
|
// any other custom predicate
|
|
|
|
return common.ToMap(statement)
|
|
|
|
}
|
2021-10-05 22:42:42 -07:00
|
|
|
|
|
|
|
return decodeCosignCustomProvenanceV01(statement)
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeCosignCustomProvenanceV01(statement in_toto.Statement) (map[string]interface{}, error) {
|
|
|
|
if statement.PredicateType != attestation.CosignCustomProvenanceV01 {
|
|
|
|
return nil, fmt.Errorf("invalid statement type %s", attestation.CosignCustomProvenanceV01)
|
|
|
|
}
|
|
|
|
|
|
|
|
predicate, ok := statement.Predicate.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("failed to decode CosignCustomProvenanceV01")
|
|
|
|
}
|
|
|
|
|
|
|
|
cosignPredicateData := predicate["Data"]
|
|
|
|
if cosignPredicateData == nil {
|
|
|
|
return nil, fmt.Errorf("missing predicate in CosignCustomProvenanceV01")
|
|
|
|
}
|
|
|
|
|
|
|
|
// attempt to parse as a JSON object type
|
|
|
|
data, err := stringToJSONMap(cosignPredicateData)
|
|
|
|
if err == nil {
|
|
|
|
predicate["Data"] = data
|
|
|
|
statement.Predicate = predicate
|
|
|
|
}
|
|
|
|
|
|
|
|
return common.ToMap(statement)
|
|
|
|
}
|
2021-10-02 01:19:47 -07:00
|
|
|
|
2021-10-05 22:42:42 -07:00
|
|
|
func stringToJSONMap(i interface{}) (map[string]interface{}, error) {
|
|
|
|
s, ok := i.(string)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("expected string type")
|
2021-10-01 11:10:36 -07:00
|
|
|
}
|
|
|
|
|
2021-10-05 22:42:42 -07:00
|
|
|
var data = map[string]interface{}{}
|
|
|
|
if err := json.Unmarshal([]byte(s), &data); err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to marshal JSON: %s", err.Error())
|
2021-10-01 11:10:36 -07:00
|
|
|
}
|
|
|
|
|
2021-10-05 22:42:42 -07:00
|
|
|
return data, nil
|
2021-10-01 11:10:36 -07:00
|
|
|
}
|
|
|
|
|
2021-08-02 13:51:36 -07:00
|
|
|
func decodePEM(raw []byte) (signature.Verifier, error) {
|
2021-07-09 18:01:46 -07:00
|
|
|
// PEM encoded file.
|
|
|
|
ed, err := cosign.PemToECDSAKey(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "pem to ecdsa")
|
|
|
|
}
|
|
|
|
|
2021-08-02 13:51:36 -07:00
|
|
|
return signature.LoadECDSAVerifier(ed, crypto.SHA256)
|
2021-07-09 18:01:46 -07:00
|
|
|
}
|
|
|
|
|
2021-12-11 01:16:22 +05:30
|
|
|
func extractPayload(imgRef string, verified []oci.Signature, log logr.Logger) ([]payload.SimpleContainerImage, error) {
|
|
|
|
var sigPayload []payload.SimpleContainerImage
|
|
|
|
for _, sig := range verified {
|
|
|
|
p, err := sig.Payload()
|
2021-11-03 10:45:35 +03:00
|
|
|
if err != nil {
|
2021-12-11 01:16:22 +05:30
|
|
|
return nil, errors.Wrap(err, "failed to get payload")
|
2021-11-03 10:45:35 +03:00
|
|
|
}
|
2021-11-04 23:26:22 -07:00
|
|
|
|
2021-12-11 01:16:22 +05:30
|
|
|
ss := payload.SimpleContainerImage{}
|
|
|
|
if err := json.Unmarshal(p, &ss); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error decoding the payload")
|
2021-07-09 18:01:46 -07:00
|
|
|
}
|
|
|
|
|
2021-12-11 01:16:22 +05:30
|
|
|
log.V(3).Info("image verification response", "image", imgRef, "payload", ss)
|
2021-10-28 15:48:35 -07:00
|
|
|
// The expected payload is in one of these JSON formats:
|
2021-07-09 18:01:46 -07:00
|
|
|
// {
|
|
|
|
// "critical": {
|
|
|
|
// "identity": {
|
|
|
|
// "docker-reference": "registry-v2.nirmata.io/pause"
|
|
|
|
// },
|
|
|
|
// "image": {
|
|
|
|
// "docker-manifest-digest": "sha256:4a1c4b21597c1b4415bdbecb28a3296c6b5e23ca4f9feeb599860a1dac6a0108"
|
|
|
|
// },
|
|
|
|
// "type": "cosign container image signature"
|
|
|
|
// },
|
|
|
|
// "optional": null
|
|
|
|
// }
|
2021-10-28 15:48:35 -07:00
|
|
|
//
|
|
|
|
// {
|
|
|
|
// "Critical": {
|
|
|
|
// "Identity": {
|
|
|
|
// "docker-reference": "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/nop"
|
|
|
|
// },
|
|
|
|
// "Image": {
|
|
|
|
// "Docker-manifest-digest": "sha256:6a037d5ba27d9c6be32a9038bfe676fb67d2e4145b4f53e9c61fb3e69f06e816"
|
|
|
|
// },
|
|
|
|
// "Type": "Tekton container signature"
|
|
|
|
// },
|
|
|
|
// "Optional": {}
|
|
|
|
// }
|
2021-12-11 01:16:22 +05:30
|
|
|
|
|
|
|
sigPayload = append(sigPayload, ss)
|
|
|
|
}
|
|
|
|
return sigPayload, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func extractDigest(imgRef string, payload []payload.SimpleContainerImage, log logr.Logger) (string, error) {
|
|
|
|
for _, p := range payload {
|
|
|
|
if digest := p.Critical.Image.DockerManifestDigest; digest != "" {
|
|
|
|
return digest, nil
|
2021-10-28 15:48:35 -07:00
|
|
|
} else {
|
2021-12-11 01:16:22 +05:30
|
|
|
log.Info("failed to extract image digest from verification response", "image", imgRef, "payload", p)
|
2021-10-28 15:48:35 -07:00
|
|
|
return "", fmt.Errorf("unknown image response for " + imgRef)
|
2021-07-09 18:01:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return "", fmt.Errorf("digest not found for " + imgRef)
|
|
|
|
}
|
2021-10-28 15:48:35 -07:00
|
|
|
|
2021-12-11 01:16:22 +05:30
|
|
|
func extractIssuer(imgRef string, payload []payload.SimpleContainerImage, log logr.Logger) (string, error) {
|
|
|
|
for _, p := range payload {
|
|
|
|
if issuer := p.Optional["Issuer"]; issuer != nil {
|
|
|
|
return issuer.(string), nil
|
|
|
|
} else {
|
2022-01-12 20:49:52 -08:00
|
|
|
log.V(3).Info("failed to extract image issuer from verification response", "image", imgRef, "payload", p)
|
2021-12-11 01:16:22 +05:30
|
|
|
return "", fmt.Errorf("unknown image response for " + imgRef)
|
2021-10-28 15:48:35 -07:00
|
|
|
}
|
|
|
|
}
|
2021-12-11 01:16:22 +05:30
|
|
|
return "", fmt.Errorf("issuer not found for " + imgRef)
|
2021-10-28 15:48:35 -07:00
|
|
|
}
|
|
|
|
|
2021-12-11 01:16:22 +05:30
|
|
|
func extractSubject(imgRef string, payload []payload.SimpleContainerImage, log logr.Logger) (string, error) {
|
|
|
|
for _, p := range payload {
|
|
|
|
if subject := p.Optional["Subject"]; subject != nil {
|
|
|
|
return subject.(string), nil
|
|
|
|
} else {
|
2022-01-12 20:49:52 -08:00
|
|
|
log.V(3).Info("failed to extract image subject from verification response", "image", imgRef, "payload", p)
|
2021-12-11 01:16:22 +05:30
|
|
|
return "", fmt.Errorf("unknown image response for " + imgRef)
|
2021-10-28 15:48:35 -07:00
|
|
|
}
|
|
|
|
}
|
2021-12-11 01:16:22 +05:30
|
|
|
return "", fmt.Errorf("image subject not found for " + imgRef)
|
2021-10-28 15:48:35 -07:00
|
|
|
}
|
2021-12-16 11:49:44 +05:30
|
|
|
|
|
|
|
func checkAnnotations(payload []payload.SimpleContainerImage, annotations map[string]string, log logr.Logger) error {
|
|
|
|
for _, p := range payload {
|
|
|
|
for key, val := range annotations {
|
|
|
|
if val != p.Optional[key] {
|
|
|
|
return fmt.Errorf("value of " + key + " does not match")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|