disable metrics access if no token is set (#1469)

This commit is contained in:
Anbraten 2022-12-09 18:03:43 +01:00 committed by GitHub
parent cfb288201f
commit a3f4f3056c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View file

@ -294,6 +294,7 @@ Read the value for `WOODPECKER_DATABASE_DATASOURCE` from the specified filepath
> Default: empty > Default: empty
Token to secure the Prometheus metrics endpoint. Token to secure the Prometheus metrics endpoint.
Must be set to enable the endpoint.
### `WOODPECKER_PROMETHEUS_AUTH_TOKEN_FILE` ### `WOODPECKER_PROMETHEUS_AUTH_TOKEN_FILE`
> Default: empty > Default: empty

View file

@ -17,6 +17,7 @@ package metrics
import ( import (
"errors" "errors"
"fmt" "fmt"
"net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
@ -35,7 +36,7 @@ func PromHandler() gin.HandlerFunc {
token := server.Config.Prometheus.AuthToken token := server.Config.Prometheus.AuthToken
if token == "" { if token == "" {
handler.ServeHTTP(c.Writer, c.Request) c.AbortWithStatus(http.StatusNotFound)
return return
} }