Skip to content

Commit f23b1f2

Browse files
author
Tom Meadows
committed
resolving conflicts from merge with verifiers branch
Signed-off-by: Tom Meadows <[email protected]>
2 parents aa94800 + 69b8fb6 commit f23b1f2

File tree

3 files changed

+51
-25
lines changed

3 files changed

+51
-25
lines changed

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,33 @@ The provider can be configured with a configuration file passed with the
5151
`-config-file=<file>` flag.
5252

5353
The verification options for specific image references can be configured by
54-
defining verifiers.
54+
defining verifiers for an image reference or image reference pattern. The
55+
validator iterates over the list of `imageVerifiers` and uses the first
56+
matching item.
5557

56-
If a matching verifier can't be found then it will return an error for that image
58+
If a matching item can't be found then it will return an error for that image
5759
in the response.
5860

5961
```yaml
60-
verifiers:
61-
# Verify images in the my-project GCR registry with GCP KMS
62+
imageVerifiers:
63+
# Verify images in the my-project GCR registry with GCP KMS and the rekor
64+
# server
6265
- image: "eu.gcr.io/my-project/*"
63-
options:
64-
key: "gcpkms://projects/my-project/locations/global/keyRings/my-keyring/cryptoKeys/my-key"
66+
verifiers:
67+
- options:
68+
key: "gcpkms://projects/my-project/locations/global/keyRings/my-keyring/cryptoKeys/my-key"
69+
- options:
70+
rekorURL: "https://rekor.sigstore.dev"
6571

66-
# Verify images from my-registry with cosign.pub
72+
# Verify images from my-registry with /cosign.pub
6773
- image: "my-registry:12345/*"
68-
options:
69-
key: "/cosign.pub"
74+
verifiers:
75+
- options:
76+
key: "/cosign.pub"
7077

7178
# Verify any other image with the rekor server
7279
- image: "*"
73-
options:
74-
rekorURL: "https://rekor.sigstore.dev"
80+
verifiers:
81+
- options:
82+
rekorURL: "https://rekor.sigstore.dev"
7583
```

config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright The Sigstore Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package main
216

317
import (

provider.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import (
3737
"github.com/sigstore/cosign/pkg/cosign/pkcs11key"
3838
"github.com/sigstore/cosign/pkg/oci"
3939
sigs "github.com/sigstore/cosign/pkg/signature"
40+
rekorclient "github.com/sigstore/rekor/pkg/generated/client"
41+
"github.com/sigstore/sigstore/pkg/signature"
4042
"github.com/sigstore/sigstore/pkg/signature/payload"
4143
)
4244

@@ -129,8 +131,8 @@ func validate(cfg *Config) func(w http.ResponseWriter, req *http.Request) {
129131
}
130132

131133
type checkedMetadata struct {
132-
ImageSignatures []payload.SimpleContainerImage `json:"imageSignatures"`
133-
AttestationSignatures []in_toto.Statement `json:"attestationSignatures"`
134+
Signatures []payload.SimpleContainerImage `json:"signatures"`
135+
Attestations []in_toto.Statement `json:"attestations"`
134136
}
135137

136138
func verifyImageSignatures(ctx context.Context, key string, verifiers []Verifier) (*checkedMetadata, error) {
@@ -149,17 +151,19 @@ func verifyImageSignatures(ctx context.Context, key string, verifiers []Verifier
149151
RootCerts: fulcio.GetRoots(),
150152
}
151153
if o.Options.RekorURL != "" {
152-
rekorClient, err := rekor.NewClient(o.Options.RekorURL)
154+
var rekorClient *rekorclient.Rekor
155+
rekorClient, err = rekor.NewClient(o.Options.RekorURL)
153156
if err != nil {
154-
return nil, fmt.Errorf("rekor.NewClient: %v", err)
157+
return nil, fmt.Errorf("creating rekor client: %v", err)
155158
}
156159
co.RekorClient = rekorClient
157-
fmt.Printf("using rekor url %s to verify %s\n", o.Options.RekorURL, key)
160+
fmt.Printf("error using rekor url %s to verify %s\n", o.Options.RekorURL, key)
158161
}
159162
if o.Options.Key != "" {
160-
pubKey, err := sigs.PublicKeyFromKeyRef(ctx, o.Options.Key)
163+
var pubKey signature.Verifier
164+
pubKey, err = sigs.PublicKeyFromKeyRef(ctx, o.Options.Key)
161165
if err != nil {
162-
return nil, fmt.Errorf("publicKeyFromKeyRef: %v", err)
166+
return nil, fmt.Errorf("error getting public key from key reference: %v", err)
163167
}
164168
pkcs11Key, ok := pubKey.(*pkcs11key.Key)
165169
if ok {
@@ -171,14 +175,14 @@ func verifyImageSignatures(ctx context.Context, key string, verifiers []Verifier
171175

172176
ref, err := name.ParseReference(key)
173177
if err != nil {
174-
return nil, fmt.Errorf("parseReference: %v", err)
178+
return nil, fmt.Errorf("error parsing image reference: %v", err)
175179
}
176180

177181
metadata := &checkedMetadata{}
178182
if contains(o.Verifies, "imageSignature") {
179183
checkedSignatures, bundleVerified, err := cosign.VerifyImageSignatures(ctx, ref, co)
180184
if err != nil {
181-
return nil, fmt.Errorf("verifyImageSignatures: %v", err)
185+
return nil, fmt.Errorf("error verifying image signatures: %v", err)
182186
}
183187

184188
if co.RekorClient != nil && !bundleVerified {
@@ -189,9 +193,9 @@ func verifyImageSignatures(ctx context.Context, key string, verifiers []Verifier
189193
return nil, fmt.Errorf("no valid signatures found for %s", key)
190194
}
191195

192-
metadata.ImageSignatures, err = formatSignaturePayloads(checkedSignatures)
196+
metadata.Signatures, err = formatSignaturePayloads(checkedSignatures)
193197
if err != nil {
194-
return nil, fmt.Errorf("formatSignaturePayloads: %v", err)
198+
return nil, fmt.Errorf("error formatting signature payload: %v", err)
195199
}
196200

197201
fmt.Println("signature verified for: ", key)
@@ -202,7 +206,7 @@ func verifyImageSignatures(ctx context.Context, key string, verifiers []Verifier
202206

203207
checkedAttestations, bundleVerified, err := cosign.VerifyImageAttestations(ctx, ref, co)
204208
if err != nil {
205-
return nil, fmt.Errorf("verifyImageAttestations: %v", err)
209+
return nil, fmt.Errorf("error verifying attestations: %v", err)
206210
}
207211
if co.RekorClient != nil && !bundleVerified {
208212
return nil, fmt.Errorf("no valid attestations found for: %s", key)
@@ -213,7 +217,7 @@ func verifyImageSignatures(ctx context.Context, key string, verifiers []Verifier
213217
return nil, fmt.Errorf("formatAttestations: %v", err)
214218
}
215219

216-
metadata.AttestationSignatures = AttestationPayloads
220+
metadata.Attestations = AttestationPayloads
217221

218222
fmt.Println("attestation verified for: ", key)
219223
fmt.Printf("%d number of valid attestations found for %s, found attestations: %v\n", len(checkedAttestations), key, checkedAttestations)
@@ -254,7 +258,7 @@ func formatAttestations(verifiedAttestations []oci.Signature) ([]in_toto.Stateme
254258

255259
statementRaw, err := base64.StdEncoding.DecodeString(payload)
256260
if err != nil {
257-
fmt.Fprintf(os.Stderr, "error decoding payload: %v", err)
261+
fmt.Fprintf(os.Stderr, "error decoding attestation payload: %v", err)
258262
}
259263

260264
var statement in_toto.Statement

0 commit comments

Comments
 (0)