Skip to content

Commit 483c869

Browse files
authored
Fix metrics authorization middleware bleed (#3183)
fix: metrics authorization middleware bleed (#3182) Fixes `extension_metrics_disabled.go` to correctly isolate the authz middleware when the metrics extension is disabled. Signed-off-by: Matthieu Mottet <m.mottet@outlook.com>
1 parent 0c51cb7 commit 483c869

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

pkg/extensions/extension_metrics_disabled.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func SetupMetricsRoutes(conf *config.Config, router *mux.Router,
2929
zcommon.WriteJSON(w, http.StatusOK, m)
3030
}
3131

32-
router.Use(authnFunc)
33-
router.Use(authzFunc)
34-
router.HandleFunc("/metrics", getMetrics).Methods("GET")
32+
extRouter := router.PathPrefix("/metrics").Subrouter()
33+
extRouter.Use(authnFunc)
34+
extRouter.Use(authzFunc)
35+
extRouter.Methods("GET").Handler(http.HandlerFunc(getMetrics))
3536
}

test/blackbox/helpers_dist.bash

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function dist_route_check () {
2+
local servername="http://127.0.0.1:${1}/v2/"
3+
status_code=$(curl --write-out '%{http_code}' ${2} --silent --output /dev/null ${servername})
4+
5+
[ "$status_code" -eq ${3} ]
6+
}

test/blackbox/metrics_minimal.bats

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
load helpers_zot
66
load helpers_metrics
7+
load helpers_dist
78

89
function verify_prerequisites() {
910
if [ ! $(command -v curl) ]; then
@@ -107,4 +108,9 @@ function teardown_file() {
107108
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
108109
run metrics_route_check ${zot_port} "-u ${METRICS_USER}:${METRICS_PASS}" 200
109110
[ "$status" -eq 0 ]
111+
# anonymous policy: /v2/ endpoint should be available
112+
# 200 - http.StatusOK
113+
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
114+
run dist_route_check ${zot_port} "" 200
115+
[ "$status" -eq 0 ]
110116
}

0 commit comments

Comments
 (0)