@@ -5,47 +5,46 @@ import (
5
5
"context"
6
6
"errors"
7
7
"fmt"
8
+ "net/http"
8
9
"net/url"
9
10
"strings"
10
11
"sync"
11
12
13
+ configv1 "github.com/openshift/api/config/v1"
12
14
configv1listers "github.com/openshift/client-go/config/listers/config/v1"
13
15
"github.com/openshift/library-go/pkg/verify/store"
14
16
"github.com/openshift/library-go/pkg/verify/store/parallel"
15
17
"github.com/openshift/library-go/pkg/verify/store/sigstore"
18
+ utilerrors "k8s.io/apimachinery/pkg/util/errors"
19
+ "k8s.io/klog/v2"
16
20
)
17
21
18
22
type Store struct {
19
23
// Name is the name of the ClusterVersion object that configures this store.
20
24
Name string
21
25
22
- // Lister allows the store to fetch the current ClusterVersion configuration.
23
- Lister configv1listers.ClusterVersionLister
26
+ // ClusterVersionLister allows the store to fetch the current ClusterVersion configuration.
27
+ ClusterVersionLister configv1listers.ClusterVersionLister
24
28
25
- // HTTPClient is called once for each Signatures call to ensure
26
- // requests are made with the currently-recommended parameters.
27
- HTTPClient sigstore.HTTPClient
29
+ // HTTPClient construct which respects the customstore CA certs and cluster proxy configuration
30
+ HTTPClient func (string ) (* http.Client , error )
28
31
29
32
// lock allows the store to be locked while mutating or accessing internal state.
30
33
lock sync.Mutex
31
34
32
- // customURIs tracks the most-recently retrieved ClusterVersion configuration.
33
- customURIs []* url. URL
35
+ // customStores tracks the most-recently retrieved ClusterVersion configuration.
36
+ customStores []configv1. SignatureStore
34
37
}
35
38
36
39
// Signatures fetches signatures for the provided digest.
37
40
func (s * Store ) Signatures (ctx context.Context , name string , digest string , fn store.Callback ) error {
38
- uris , err := s .refreshConfiguration (ctx )
41
+ customStores , err := s .refreshConfiguration ()
39
42
if err != nil {
40
43
return err
41
- }
42
-
43
- if uris == nil {
44
+ } else if customStores == nil {
44
45
return nil
45
- }
46
-
47
- if len (uris ) == 0 {
48
- return errors .New ("ClusterVersion spec.signatureStores is an empty array. Unset signatureStores entirely if you want to to enable the default signature stores." )
46
+ } else if len (customStores ) == 0 {
47
+ return errors .New ("ClusterVersion spec.signatureStores is an empty array. Unset signatureStores entirely if you want to enable the default signature stores" )
49
48
}
50
49
51
50
allDone := false
@@ -58,44 +57,66 @@ func (s *Store) Signatures(ctx context.Context, name string, digest string, fn s
58
57
return done , err
59
58
}
60
59
61
- stores := make ([]store.Store , 0 , len (uris ))
62
- for i := range uris {
63
- uri := * uris [i ]
60
+ var errs []error
61
+ stores := make ([]store.Store , 0 , len (customStores ))
62
+ for _ , customStore := range customStores {
63
+ uri , err := url .Parse (customStore .URL )
64
+ if err != nil {
65
+ errs = append (errs , fmt .Errorf ("failed to parse the ClusterVersion spec.signatureStores %w" , err ))
66
+ continue
67
+ }
68
+ newHttpClient , err := s .HTTPClient (customStore .CA .Name )
69
+ if err != nil {
70
+ errs = append (errs , fmt .Errorf ("failed to process the ClusterVersion spec.signatureStores %w" , err ))
71
+ continue
72
+ }
73
+
64
74
stores = append (stores , & sigstore.Store {
65
- URI : & uri ,
66
- HTTPClient : s .HTTPClient ,
67
- })
75
+ URI : uri ,
76
+ HTTPClient : func () (* http.Client , error ) { return newHttpClient , nil }})
77
+ }
78
+
79
+ if len (stores ) == 0 {
80
+ return utilerrors .NewAggregate (errs )
68
81
}
69
82
store := & parallel.Store {Stores : stores }
70
- if err := store .Signatures (ctx , name , digest , wrapper ); err != nil || allDone {
71
- return err
83
+ if err := store .Signatures (ctx , name , digest , wrapper ); allDone {
84
+ if len (errs ) > 0 {
85
+ klog .V (2 ).Infof ("%s" , utilerrors .NewAggregate (errs ))
86
+ }
87
+ return nil
88
+ } else if err != nil {
89
+ errs = append (errs , err )
90
+ return utilerrors .NewAggregate (errs )
72
91
}
73
- return errors .New ("ClusterVersion spec.signatureStores exhausted without finding a valid signature." )
92
+
93
+ errs = append (errs , errors .New ("ClusterVersion spec.signatureStores exhausted without finding a valid signature" ))
94
+ return utilerrors .NewAggregate (errs )
74
95
}
75
96
76
- func (s * Store ) refreshConfiguration (ctx context.Context ) ([]* url.URL , error ) {
77
- config , err := s .Lister .Get (s .Name )
97
+ // refreshConfiguration retrieves the latest configuration from the ClusterVersionLister
98
+ // and updates the customStores with the URL and CA information from the retrieved configuration.
99
+ // It returns the updated customStores slice and any error encountered during the retrieval process.
100
+ func (s * Store ) refreshConfiguration () ([]configv1.SignatureStore , error ) {
101
+
102
+ config , err := s .ClusterVersionLister .Get (s .Name )
78
103
if err != nil {
79
104
return nil , err
80
105
}
81
106
82
- var uris [] * url. URL
107
+ var customStores = make ([]configv1. SignatureStore , 0 , len ( config . Spec . SignatureStores ))
83
108
if config .Spec .SignatureStores != nil {
84
- uris = make ([]* url.URL , 0 , len (config .Spec .SignatureStores ))
85
109
for _ , store := range config .Spec .SignatureStores {
86
- uri , err := url .Parse (store .URL )
87
- if err != nil {
88
- return uris , err
89
- }
90
-
91
- uris = append (uris , uri )
110
+ url := store .URL
111
+ caCert := store .CA
112
+ customStores = append (customStores , configv1.SignatureStore {URL : url , CA : caCert })
92
113
}
93
114
}
94
115
95
116
s .lock .Lock ()
96
117
defer s .lock .Unlock ()
97
- s .customURIs = uris
98
- return uris , nil
118
+ s .customStores = customStores
119
+ return customStores , nil
99
120
}
100
121
101
122
// String returns a description of where this store finds
@@ -104,14 +125,14 @@ func (s *Store) String() string {
104
125
s .lock .Lock ()
105
126
defer s .lock .Unlock ()
106
127
107
- if s .customURIs == nil {
108
- return "ClusterVersion signatureStores unset , falling back to default stores"
109
- } else if len (s .customURIs ) == 0 {
128
+ if s .customStores == nil {
129
+ return "ClusterVersion signatureStores not set , falling back to default stores"
130
+ } else if len (s .customStores ) == 0 {
110
131
return "0 ClusterVersion signatureStores"
111
132
}
112
- uris := make ([]string , 0 , len (s .customURIs ))
113
- for _ , uri := range s .customURIs {
114
- uris = append (uris , uri . String () )
133
+ customStores := make ([]string , 0 , len (s .customStores ))
134
+ for _ , customStore := range s .customStores {
135
+ customStores = append (customStores , customStore . URL )
115
136
}
116
- return fmt .Sprintf ("ClusterVersion signatureStores: %s" , strings .Join (uris , ", " ))
137
+ return fmt .Sprintf ("ClusterVersion signatureStores: %s" , strings .Join (customStores , ", " ))
117
138
}
0 commit comments