Skip to content

Commit

Permalink
Add prober for verifying Rekor write correctness (#390)
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Soyland <[email protected]>

Signed-off-by: Cody Soyland <[email protected]>
  • Loading branch information
codysoyland authored Sep 29, 2022
1 parent 78069fb commit 97ca633
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func main() {
fmt.Printf("running create_ct_config Version: %s GitCommit: %s BuildDate: %s", versionInfo.GitVersion, versionInfo.GitCommit, versionInfo.BuildDate)

reg := prometheus.NewRegistry()
reg.MustRegister(endpointLatenciesSummary, endpointLatenciesHistogram)
reg.MustRegister(endpointLatenciesSummary, endpointLatenciesHistogram, verificationCounter)
reg.MustRegister(NewVersionCollector("sigstore_prober"))

go runProbers(ctx, frequency, oneTime)
Expand Down
9 changes: 9 additions & 0 deletions cmd/prober/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
hostLabel = "host"
statusCodeLabel = "status_code"
methodLabel = "method"
verifiedLabel = "verified"
)

var (
Expand All @@ -45,6 +46,14 @@ var (
Buckets: []float64{0.0, 200.0, 400.0, 600.0, 800.0, 1000.0},
},
[]string{endpointLabel, hostLabel, statusCodeLabel, methodLabel})

verificationCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "verification",
Help: "Rekor verification correctness counter",
},
[]string{verifiedLabel},
)
)

func exportDataToPrometheus(resp *http.Response, host, endpoint, method string, latency int64) {
Expand Down
33 changes: 25 additions & 8 deletions cmd/prober/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"time"

"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/prometheus/client_golang/prometheus"

"github.com/sigstore/cosign/pkg/cosign"
"github.com/sigstore/cosign/pkg/providers"
"github.com/sigstore/fulcio/pkg/api"
rclient "github.com/sigstore/rekor/pkg/client"
"github.com/sigstore/rekor/pkg/generated/models"
hashedrekord "github.com/sigstore/rekor/pkg/types/hashedrekord/v0.0.1"
"github.com/sigstore/sigstore/pkg/cryptoutils"
Expand Down Expand Up @@ -121,17 +122,33 @@ func rekorWriteEndpoint(ctx context.Context) error {
t := time.Now()
resp, err := http.DefaultClient.Do(req)
latency := time.Since(t).Milliseconds()
exportDataToPrometheus(resp, rekorURL, endpoint, POST, latency)
if err != nil {
fmt.Printf("error adding entry: %v\n", err.Error())
return fmt.Errorf("error adding entry: %w", err)
}

// Export data to prometheus
exportDataToPrometheus(resp, rekorURL, endpoint, POST, latency)

// If entry was added successfully, we should verify it
rekorClient, err := rclient.GetRekorClient(rekorURL, rclient.WithUserAgent(fmt.Sprintf("Sigstore_Scaffolding_Prober/%s", versionInfo.GitVersion)))
if err != nil {
return fmt.Errorf("creating rekor client: %w", err)
}
defer resp.Body.Close()
body, _ = io.ReadAll(resp.Body)
fmt.Println(string(body))
return nil
var logEntry models.LogEntry
err = json.NewDecoder(resp.Body).Decode(&logEntry)
if err != nil {
return fmt.Errorf("unmarshal: %w", err)
}
var logEntryAnon models.LogEntryAnon
for _, e := range logEntry {
logEntryAnon = e
break
}
verified := "true"
if err = cosign.VerifyTLogEntry(ctx, rekorClient, &logEntryAnon); err != nil {
verified = "false"
}
verificationCounter.With(prometheus.Labels{verifiedLabel: verified}).Inc()
return err
}

func rekorEntryRequest() ([]byte, error) {
Expand Down

0 comments on commit 97ca633

Please sign in to comment.