Skip to content

Commit c44dde9

Browse files
authored
Add Rekor v2 and TSA probers (#1719)
Signed-off-by: Aaron Lew <[email protected]>
1 parent 3dfdfa6 commit c44dde9

File tree

5 files changed

+220
-24
lines changed

5 files changed

+220
-24
lines changed

.github/workflows/prober-test.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ permissions:
1818

1919
jobs:
2020
prober-test:
21-
name: 'Prober test'
21+
name: 'Prober test (${{ matrix.env }})'
2222
runs-on: ubuntu-latest
2323
permissions:
2424
id-token: write
2525
contents: read
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
include:
30+
- env: prod
31+
args: ""
32+
- env: staging
33+
args: "--staging"
2634
steps:
2735
- name: 'Checkout'
2836
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
@@ -47,4 +55,4 @@ jobs:
4755
4856
- name: Run prober test
4957
id: prober-test
50-
run: ./prober --one-time --write-prober --logStyle dev
58+
run: ./prober --one-time --write-prober --logStyle dev ${{ matrix.args }}

cmd/prober/endpoints.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ var ShardlessRekorEndpoints = []ReadProberCheck{
5555
},
5656
}
5757

58+
var RekorV2ReadEndpoints = []ReadProberCheck{
59+
{
60+
Endpoint: "/healthz",
61+
Method: GET,
62+
},
63+
}
64+
5865
var FulcioEndpoints = []ReadProberCheck{
5966
{
6067
Endpoint: "/api/v1/rootCert",

cmd/prober/prober.go

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ var (
121121
oneTime bool
122122
runWriteProber bool
123123

124+
rekorV2URL string
125+
124126
versionInfo version.Info
125127
)
126128

@@ -141,6 +143,8 @@ func init() {
141143
flag.BoolVar(&oneTime, "one-time", false, "Whether to run only one time and exit")
142144
flag.BoolVar(&runWriteProber, "write-prober", false, " [Kubernetes only] run the probers for the write endpoints")
143145

146+
flag.StringVar(&rekorV2URL, "rekor-v2-url", "", "Set to the Rekor v2 URL to run probers against (will take precedence over any instances listed in the signing config)")
147+
144148
var rekorV1RequestsJSON string
145149
flag.StringVar(&rekorV1RequestsJSON, "rekor-requests", "[]", "Additional rekor requests (JSON array)")
146150

@@ -234,7 +238,17 @@ func main() {
234238

235239
rekorV1Services, err := root.SelectServices(signingConfig.RekorLogURLs(), root.ServiceConfiguration{Selector: prototrustroot.ServiceSelector_ALL}, []uint32{1}, time.Now())
236240
if err != nil {
237-
log.Fatal("Failed to select Rekor services: ", err)
241+
log.Fatal("Failed to select Rekor v1 services: ", err)
242+
}
243+
244+
var rekorV2Services []root.Service
245+
if rekorV2URL != "" {
246+
rekorV2Services = []root.Service{{URL: rekorV2URL, MajorAPIVersion: 2}}
247+
} else {
248+
rekorV2Services, err = root.SelectServices(signingConfig.RekorLogURLs(), root.ServiceConfiguration{Selector: prototrustroot.ServiceSelector_ALL}, []uint32{2}, time.Now())
249+
if err != nil {
250+
rekorV2Services = nil
251+
}
238252
}
239253

240254
fulcioService, err := root.SelectService(signingConfig.FulcioCertificateAuthorityURLs(), sign.FulcioAPIVersions, time.Now())
@@ -260,7 +274,7 @@ func main() {
260274
if fulcioClient, err := NewFulcioGrpcClient(fulcioGrpcURL); err != nil {
261275
Logger.Fatalf("error creating fulcio grpc client %v", err)
262276
} else {
263-
go runProbers(ctx, frequency, oneTime, fulcioClient, rekorV1Services, fulcioService, fulcioGrpcURL, tsaServices, trustedRoot)
277+
go runProbers(ctx, frequency, oneTime, fulcioClient, rekorV1Services, rekorV2Services, fulcioService, fulcioGrpcURL, tsaServices, trustedRoot)
264278
}
265279
// Expose the registered metrics via HTTP.
266280
http.Handle("/metrics", promhttp.HandlerFor(
@@ -290,7 +304,7 @@ func NewFulcioGrpcClient(fulcioGrpcURL string) (fulciopb.CAClient, error) {
290304
return fulciopb.NewCAClient(conn), nil
291305
}
292306

293-
func runProbers(ctx context.Context, freq int, runOnce bool, fulcioGrpcClient fulciopb.CAClient, rekorV1Services []root.Service, fulcioService root.Service, fulcioGrpcURL string, tsaServices []root.Service, trustedRoot *root.TrustedRoot) {
307+
func runProbers(ctx context.Context, freq int, runOnce bool, fulcioGrpcClient fulciopb.CAClient, rekorV1Services []root.Service, rekorV2Services []root.Service, fulcioService root.Service, fulcioGrpcURL string, tsaServices []root.Service, trustedRoot *root.TrustedRoot) {
294308
for {
295309
hasErr := false
296310

@@ -305,23 +319,32 @@ func runProbers(ctx context.Context, freq int, runOnce bool, fulcioGrpcClient fu
305319
rekorEndpointsUnderTest = append(rekorEndpointsUnderTest, ShardlessRekorEndpoints...)
306320

307321
for _, r := range rekorEndpointsUnderTest {
308-
if err := observeRequest(s.URL, r); err != nil {
322+
if _, err := observeRequest(s.URL, r); err != nil {
323+
hasErr = true
324+
Logger.Errorf("error running request %s: %v", r.Endpoint, err)
325+
}
326+
}
327+
}
328+
329+
for _, s := range rekorV2Services {
330+
for _, r := range RekorV2ReadEndpoints {
331+
if _, err := observeRequest(s.URL, r); err != nil {
309332
hasErr = true
310333
Logger.Errorf("error running request %s: %v", r.Endpoint, err)
311334
}
312335
}
313336
}
314337

315338
for _, r := range FulcioEndpoints {
316-
if err := observeRequest(fulcioService.URL, r); err != nil {
339+
if _, err := observeRequest(fulcioService.URL, r); err != nil {
317340
hasErr = true
318341
Logger.Errorf("error running request %s: %v", r.Endpoint, err)
319342
}
320343
}
321344

322345
for _, s := range tsaServices {
323346
for _, r := range TSAEndpoints {
324-
if err := observeRequest(s.URL, r); err != nil {
347+
if _, err := observeRequest(s.URL, r); err != nil {
325348
hasErr = true
326349
Logger.Errorf("error running request %s: %v", r.Endpoint, err)
327350
}
@@ -350,10 +373,20 @@ func runProbers(ctx context.Context, freq int, runOnce bool, fulcioGrpcClient fu
350373
hasErr = true
351374
Logger.Errorf("error running fulcio v1 write prober: %v", err)
352375
}
353-
if err := rekorWriteEndpoint(ctx, cert, priv, rekorV1Services, trustedRoot); err != nil {
376+
if err := rekorV1WriteEndpoint(ctx, cert, priv, rekorV1Services, trustedRoot); err != nil {
354377
hasErr = true
355378
Logger.Errorf("error running rekor write prober: %v", err)
356379
}
380+
if err := tsaWriteEndpoint(ctx, priv, tsaServices, trustedRoot); err != nil {
381+
hasErr = true
382+
Logger.Errorf("error running tsa write prober: %v", err)
383+
}
384+
if len(rekorV2Services) > 0 {
385+
if err := rekorV2WriteEndpoint(ctx, cert, priv, rekorV2Services); err != nil {
386+
hasErr = true
387+
Logger.Errorf("error running rekor v2 write prober: %v", err)
388+
}
389+
}
357390
}
358391

359392
if runOnce {
@@ -369,18 +402,18 @@ func runProbers(ctx context.Context, freq int, runOnce bool, fulcioGrpcClient fu
369402
}
370403
}
371404

372-
func observeRequest(host string, r ReadProberCheck) error {
405+
func observeRequest(host string, r ReadProberCheck) ([]byte, error) {
373406
req, err := httpRequest(host, r)
374407
if err != nil {
375-
return err
408+
return nil, err
376409
}
377410

378411
s := time.Now()
379412
resp, err := retryableClient.Do(req)
380413
latency := time.Since(s).Milliseconds()
381414

382415
if err != nil {
383-
return err
416+
return nil, err
384417
}
385418
defer resp.Body.Close()
386419

@@ -394,12 +427,14 @@ func observeRequest(host string, r ReadProberCheck) error {
394427
}
395428
exportDataToPrometheus(resp, host, sloEndpoint, r.Method, latency)
396429

397-
// right we're not doing anything with the body, but let's at least read it all from the server
398-
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
399-
return fmt.Errorf("error reading response: %w", err)
430+
var respBuffer bytes.Buffer
431+
if _, err := io.Copy(&respBuffer, resp.Body); err != nil {
432+
return nil, fmt.Errorf("error reading response: %w", err)
400433
}
401-
402-
return nil
434+
if resp.StatusCode >= 300 {
435+
return respBuffer.Bytes(), fmt.Errorf("error response: status: %s, body: %s", resp.Status, respBuffer.String())
436+
}
437+
return respBuffer.Bytes(), nil
403438
}
404439

405440
func observeGrpcGetTrustBundleRequest(ctx context.Context, fulcioGrpcClient fulciopb.CAClient, fulcioGrpcURL string) error {

0 commit comments

Comments
 (0)