@@ -27,6 +27,8 @@ import (
27
27
// in this package uses the container signature format defined at https://github.com/containers/image
28
28
// to authenticate that a given release image digest has been signed by a trusted party.
29
29
type Interface interface {
30
+ // Verify should return nil if the provided release digest has suffient signatures to be considered
31
+ // valid. It should return an error in all other cases.
30
32
Verify (ctx context.Context , releaseDigest string ) error
31
33
}
32
34
@@ -50,8 +52,30 @@ func (rejectVerifier) Verify(ctx context.Context, releaseDigest string) error {
50
52
// Reject fails always fails verification.
51
53
var Reject Interface = rejectVerifier {}
52
54
55
+ // ClientBuilder provides a method for generating an HTTP Client configured
56
+ // with cluster proxy settings, if they exist.
57
+ type ClientBuilder interface {
58
+ // HTTPClient returns a client suitable for retrieving signatures. It is not
59
+ // required to be unique per call, but may be called concurrently.
60
+ HTTPClient () (* http.Client , error )
61
+ }
62
+
63
+ // DefaultClient uses the default http.Client for accessing signatures.
64
+ var DefaultClient = simpleClientBuilder {}
65
+
66
+ // simpleClientBuilder implements the ClientBuilder interface and may be used for testing.
67
+ type simpleClientBuilder struct {}
68
+
69
+ // HTTPClient from simpleClientBuilder creates an http.Client with no configuration.
70
+ func (s simpleClientBuilder ) HTTPClient () (* http.Client , error ) {
71
+ return & http.Client {}, nil
72
+ }
73
+
74
+ // maxSignatureSearch prevents unbounded recursion on malicious signature stores (if
75
+ // an attacker was able to take ownership of the store to perform DoS on clusters).
53
76
const maxSignatureSearch = 10
54
77
78
+ // validReleaseDigest is a verification rule to filter clearly invalid digests.
55
79
var validReleaseDigest = regexp .MustCompile (`^[a-zA-Z0-9:]+$` )
56
80
57
81
// ReleaseVerifier implements a signature intersection operation on a provided release
@@ -89,26 +113,9 @@ func (v *ReleaseVerifier) WithStores(stores ...SignatureStore) *ReleaseVerifier
89
113
}
90
114
}
91
115
92
- // ClientBuilder provides a method for generating an HTTP Client configured
93
- // with cluster proxy settings, if they exist.
94
- type ClientBuilder interface {
95
- HTTPClient () (* http.Client , error )
96
- }
97
-
98
- // DefaultClient uses the default http.Client for accessing signatures.
99
- var DefaultClient = simpleClientBuilder {}
100
-
101
- // simpleClientBuilder implements the ClientBuilder interface and may be used for testing.
102
- type simpleClientBuilder struct {}
103
-
104
- // HTTPClient from simpleClientBuilder creates an httpClient with no configuration.
105
- func (s simpleClientBuilder ) HTTPClient () (* http.Client , error ) {
106
- return & http.Client {}, nil
107
- }
108
-
109
116
// Verifiers returns a copy of the verifiers in this payload.
110
117
func (v * ReleaseVerifier ) Verifiers () map [string ]openpgp.EntityList {
111
- out := make (map [string ]openpgp.EntityList )
118
+ out := make (map [string ]openpgp.EntityList , len ( v . verifiers ) )
112
119
for k , v := range v .verifiers {
113
120
out [k ] = v
114
121
}
0 commit comments