• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubevirt / hyperconverged-cluster-operator / 13527461474

25 Feb 2025 05:40PM UTC coverage: 72.139% (-0.2%) from 72.295%
13527461474

push

github

web-flow
Require Bearer token for /metrics endpoint (#3303)

* Require Bearer token for /metrics endpoint

Signed-off-by: João Vilaça <machadovilaca@gmail.com>

* Limit the number of file access operations

Signed-off-by: João Vilaça <machadovilaca@gmail.com>

---------

Signed-off-by: João Vilaça <machadovilaca@gmail.com>

94 of 150 new or added lines in 6 files covered. (62.67%)

6455 of 8948 relevant lines covered (72.14%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/authorization/http.go
1
package authorization
2

3
import (
4
        "net/http"
5
        "strings"
6

7
        "github.com/go-logr/logr"
8
        "k8s.io/client-go/rest"
9
        "sigs.k8s.io/controller-runtime/pkg/metrics/server"
10
)
11

NEW
12
func HttpWithBearerToken(config *rest.Config, httpClient *http.Client) (server.Filter, error) {
×
NEW
13
        return func(log logr.Logger, handler http.Handler) (http.Handler, error) {
×
NEW
14
                return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
×
NEW
15
                        authValue := req.Header.Get("Authorization")
×
NEW
16
                        token := strings.TrimPrefix(authValue, "Bearer ")
×
NEW
17

×
NEW
18
                        if token == "" {
×
NEW
19
                                http.Error(w, "Unauthorized", http.StatusUnauthorized)
×
NEW
20
                                return
×
NEW
21
                        }
×
22

NEW
23
                        valid, err := ValidateToken(token)
×
NEW
24
                        if err != nil || !valid {
×
NEW
25
                                http.Error(w, "Unauthorized", http.StatusUnauthorized)
×
NEW
26
                                return
×
NEW
27
                        }
×
28

NEW
29
                        handler.ServeHTTP(w, req)
×
30
                }), nil
31
        }, nil
32
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc