Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

security: add telemetry for OCSP server checks #53685

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/security/ocsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"io/ioutil"
"net/http"

"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/util/contextutil"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/errors"
Expand All @@ -39,6 +40,9 @@ func makeOCSPVerifier(settings TLSSettings) func([][]byte, [][]*x509.Certificate

return contextutil.RunWithTimeout(context.Background(), "OCSP verification", settings.ocspTimeout(),
func(ctx context.Context) error {
// Per-conn telemetry counter.
telemetry.Inc(ocspChecksCounter)

errG, gCtx := errgroup.WithContext(ctx)
for _, chain := range verifiedChains {
// Ignore the last cert in the chain; it's the root and if it
Expand All @@ -60,10 +64,26 @@ func makeOCSPVerifier(settings TLSSettings) func([][]byte, [][]*x509.Certificate
}
}

// ocspChecksCounter counts the number of connections that are
// undergoing OCSP validations. This counter exists so that the value
// of ocspCheckWithOCSPServerInCertCounter can be interpreted as a
// percentage.
var ocspChecksCounter = telemetry.GetCounterOnce("server.ocsp.conn-verifications")

// ocspCheckWithOCSPServerInCert counts the number of certificate
// verifications performed with a populated OCSPServer field in one of
// the certs in the validation chain.
var ocspCheckWithOCSPServerInCertCounter = telemetry.GetCounterOnce("server.ocsp.cert-verifications")

func verifyOCSP(ctx context.Context, settings TLSSettings, cert, issuer *x509.Certificate) error {
if len(cert.OCSPServer) == 0 {
return nil
}

// Per-cert telemetry counter. We only count requests when there is
// an OCSP server to check in the first place.
telemetry.Inc(ocspCheckWithOCSPServerInCertCounter)

var errs []error
for _, url := range cert.OCSPServer {
ok, err := queryOCSP(ctx, url, cert, issuer)
Expand Down