feat(metrics): anonymous access when enabled in accessControl config (#4110)

* feat: add anonymouspolicy support in metrics

Signed-off-by: uaggarwa <uaggarwa@akamai.com>

* test: add unit tests

Signed-off-by: uaggarwa <uaggarwa@akamai.com>

---------

Signed-off-by: uaggarwa <uaggarwa@akamai.com>
This commit is contained in:
uaggarwa
2026-06-10 03:19:28 -04:00
committed by GitHub
parent 273b15364b
commit 66e9cfb01f
7 changed files with 334 additions and 5 deletions
+39
View File
@@ -895,6 +895,45 @@ Behaviour-based action list
}
```
##### Metrics access control
The `metrics` key inside `accessControl` controls access to the Prometheus scrape endpoint independently of repository policies. It supports two fields:
- `users` - list of named authenticated users allowed to scrape. Requires authentication (e.g. htpasswd) to be configured.
- `anonymousPolicy` - set to `["read"]` to allow unauthenticated access to the metrics endpoint when authentication is configured for other routes.
To restrict scraping to specific named users:
```
"accessControl": {
"metrics": {
"users": ["prometheus"]
}
}
```
See [config-metrics-authz.json](config-metrics-authz.json) for a complete example combining htpasswd authentication with repository policies.
When authentication is configured and repositories have non-anonymous policies, `anonymousPolicy` on `metrics` allows unauthenticated scrapers to reach the metrics endpoint while keeping repository routes protected:
```
"http": {
"auth": {
"htpasswd": { "path": "test/data/htpasswd" }
},
"accessControl": {
"metrics": {
"anonymousPolicy": ["read"]
},
"repositories": {
"**": { "defaultPolicy": ["read", "create"] }
}
}
}
```
See [config-metrics-authn-anonymous-access.json](config-metrics-authn-anonymous-access.json) for a complete example.
##### Conditional access on policies
Policy entries can carry an optional list of `conditions`: CEL boolean
@@ -0,0 +1,31 @@
{
"distSpecVersion": "1.1.1",
"storage": {
"rootDirectory": "/tmp/zot"
},
"http": {
"address": "127.0.0.1",
"port": "8080",
"auth": {
"htpasswd": {
"path": "/tmp/zot-test-htpasswd"
}
},
"accessControl": {
"metrics": {
"anonymousPolicy": ["read"]
}
}
},
"log": {
"level": "debug"
},
"extensions": {
"metrics": {
"enable": true,
"prometheus": {
"path": "/metrics"
}
}
}
}