feat: adjust logging; implement pem crl endpoint; add crl entries metric; lock on UseCrl
This commit is contained in:
@@ -16,19 +16,26 @@ var (
|
|||||||
}, []string{labelPath})
|
}, []string{labelPath})
|
||||||
|
|
||||||
responseStatus = prometheus.NewCounterVec(prometheus.CounterOpts{
|
responseStatus = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
Name: "response_status",
|
Name: "http_response_status",
|
||||||
Help: "Status of HTTP response",
|
Help: "Status of HTTP response",
|
||||||
}, []string{labelPath, labelStatus})
|
}, []string{labelPath, labelStatus})
|
||||||
|
|
||||||
httpDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
httpDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||||
Name: "http_response_time_seconds",
|
Name: "http_response_time_seconds",
|
||||||
Help: "Duration of HTTP requests.",
|
Help: "Duration of HTTP requests.",
|
||||||
Buckets: prometheus.DefBuckets,
|
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 10),
|
||||||
}, []string{labelPath})
|
}, []string{labelPath})
|
||||||
|
|
||||||
|
CrlEntries = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: "ocspcrl",
|
||||||
|
Name: "crl_entries_total",
|
||||||
|
Help: "Number of entries in the CRL",
|
||||||
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
prometheus.MustRegister(totalRequests)
|
prometheus.MustRegister(totalRequests)
|
||||||
prometheus.MustRegister(responseStatus)
|
prometheus.MustRegister(responseStatus)
|
||||||
prometheus.MustRegister(httpDuration)
|
prometheus.MustRegister(httpDuration)
|
||||||
|
prometheus.MustRegister(CrlEntries)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/crypto/ocsp"
|
"golang.org/x/crypto/ocsp"
|
||||||
@@ -16,6 +17,7 @@ type CrlSource struct {
|
|||||||
responderCertificate *x509.Certificate
|
responderCertificate *x509.Certificate
|
||||||
responderKey crypto.Signer
|
responderKey crypto.Signer
|
||||||
crl *x509.RevocationList
|
crl *x509.RevocationList
|
||||||
|
crlMutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCrlSource(caCertificate *x509.Certificate, responderKeyPair tls.Certificate) *CrlSource {
|
func NewCrlSource(caCertificate *x509.Certificate, responderKeyPair tls.Certificate) *CrlSource {
|
||||||
@@ -26,8 +28,10 @@ func NewCrlSource(caCertificate *x509.Certificate, responderKeyPair tls.Certific
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (source *CrlSource) UseCrl(crl *x509.RevocationList) {
|
func (source *CrlSource) UseCrl(crl x509.RevocationList) {
|
||||||
source.crl = crl
|
source.crlMutex.Lock()
|
||||||
|
defer source.crlMutex.Unlock()
|
||||||
|
source.crl = &crl
|
||||||
}
|
}
|
||||||
|
|
||||||
func (source *CrlSource) Response(request *ocsp.Request) ([]byte, http.Header, error) {
|
func (source *CrlSource) Response(request *ocsp.Request) ([]byte, http.Header, error) {
|
||||||
|
|||||||
11
main.go
11
main.go
@@ -91,7 +91,8 @@ func main() {
|
|||||||
if loadCrlError != nil {
|
if loadCrlError != nil {
|
||||||
log.Fatalf("failed to load crl: %v", loadCrlError)
|
log.Fatalf("failed to load crl: %v", loadCrlError)
|
||||||
}
|
}
|
||||||
source.UseCrl(crl)
|
metrics.CrlEntries.Set(float64(len(crl.RevokedCertificateEntries)))
|
||||||
|
source.UseCrl(*crl)
|
||||||
|
|
||||||
signalChan := make(chan os.Signal, 1)
|
signalChan := make(chan os.Signal, 1)
|
||||||
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
|
||||||
@@ -102,6 +103,10 @@ func main() {
|
|||||||
w.Header().Set("Content-Type", "application/pkix-crl")
|
w.Header().Set("Content-Type", "application/pkix-crl")
|
||||||
w.Write(crl.Raw)
|
w.Write(crl.Raw)
|
||||||
})
|
})
|
||||||
|
applicationRouter.HandleFunc("/crl.pem", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/pkix-crl")
|
||||||
|
pem.Encode(w, &pem.Block{Type: "X509 CRL", Bytes: crl.Raw})
|
||||||
|
})
|
||||||
|
|
||||||
applicationServer := &http.Server{Addr: config.applicationListenAddress, Handler: metrics.Middleware(applicationRouter)}
|
applicationServer := &http.Server{Addr: config.applicationListenAddress, Handler: metrics.Middleware(applicationRouter)}
|
||||||
metricsSever := &http.Server{Addr: config.metricsListenAddress, Handler: promhttp.Handler()}
|
metricsSever := &http.Server{Addr: config.metricsListenAddress, Handler: promhttp.Handler()}
|
||||||
@@ -109,14 +114,14 @@ func main() {
|
|||||||
applicationServerClosed := make(chan any)
|
applicationServerClosed := make(chan any)
|
||||||
metricsServerClosed := make(chan any)
|
metricsServerClosed := make(chan any)
|
||||||
go func() {
|
go func() {
|
||||||
log.Printf("starting application server on %s", config.applicationListenAddress)
|
log.Printf("starting application server on %+q", config.applicationListenAddress)
|
||||||
if listenError := applicationServer.ListenAndServe(); listenError != nil {
|
if listenError := applicationServer.ListenAndServe(); listenError != nil {
|
||||||
log.Printf("application error: %v", listenError)
|
log.Printf("application error: %v", listenError)
|
||||||
}
|
}
|
||||||
close(applicationServerClosed)
|
close(applicationServerClosed)
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
log.Printf("starting metrics server on %s", config.metricsListenAddress)
|
log.Printf("starting metrics server on %+q", config.metricsListenAddress)
|
||||||
if listenError := metricsSever.ListenAndServe(); listenError != nil {
|
if listenError := metricsSever.ListenAndServe(); listenError != nil {
|
||||||
log.Printf("metrics error: %v", listenError)
|
log.Printf("metrics error: %v", listenError)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user