Compare commits

...
2 Commits
Author SHA1 Message Date
Cédric Verstraeten 1cc483a67c Merge pull request #258 from kerberos-io/feat/hub-api-block-public-metrics
feat(hub): deny /metrics on hub-api's public hosts (0.202.0)
2026-11-21 23:17:18 +01:00
Cédric VerstraetenandClaude Opus 5.5 a6981c11c0 feat(hub): deny /metrics on hub-api's public hosts (0.202.0)
hub-api serves Prometheus metrics on the API port, and hub-api-ingress
routes every path to it, so /metrics (now including mongodb_client_*
database, collection and command names) was public. With ingress: nginx,
add hub-api-metrics-deny: an Ingress for /metrics on the API, legacy and
admin hosts with denylist-source-range 0.0.0.0/0,::/0. ingress-nginx
applies its annotations only to these paths, so other paths keep
hub-api-ingress's settings, and Prometheus still scrapes the Service.

On by default; kerberoshub.api.blockPublicMetrics: false turns it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 22:10:24 +00:00
5 changed files with 59 additions and 1 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.201.0
version: 0.202.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
+1
View File
@@ -929,6 +929,7 @@ kerberospipeline:
| `kerberoshub.api.resources.limits.cpu` | CPU limit for `kerberoshub.api`. | `"250m"` |
| `kerberoshub.api.serviceMonitor.enabled` | Create a Prometheus `ServiceMonitor` for hub-api `/metrics` on the backend port (request metrics and `mongodb_client_*` command metrics). Requires `kerberoshub.api.serviceEnabled`. | `true` |
| `kerberoshub.api.serviceMonitor.interval` | hub-api metrics scrape interval. | `"15s"` |
| `kerberoshub.api.blockPublicMetrics` | With `ingress: nginx`, add the `hub-api-metrics-deny` Ingress so `/metrics` answers 403 on the API, legacy and admin hosts. Prometheus scrapes the Service directly and is not affected. | `true` |
| `kerberoshub.api.serverTLS.enabled` | Enable or disable `kerberoshub.api.serverTLS`. | `false` |
| `kerberoshub.api.serverTLS.secretName` | Kubernetes Secret name used by `kerberoshub.api.serverTLS`. | `""` |
| `kerberoshub.api.serverTLS.mountPath` | Filesystem path where the Hub API TLS secret is mounted. | `"/etc/hub-api/tls"` |
@@ -0,0 +1,50 @@
{{- if and (or (eq .Values.mode "all") (eq .Values.mode "ui")) (eq .Values.ingress "nginx") .Values.kerberoshub.api.blockPublicMetrics (.Capabilities.APIVersions.Has "networking.k8s.io/v1") -}}
# Deny /metrics on hub-api's public hosts. hub-api serves Prometheus metrics
# (request metrics and mongodb_client_* database, collection and command
# names) on the same port as the API, and hub-api-ingress routes every path to
# it. ingress-nginx applies this Ingress's annotations only to its own paths,
# so /metrics answers 403 while every other path keeps hub-api-ingress's
# settings. Prometheus scrapes the Service directly and is not affected.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hub-api-metrics-deny
namespace: {{ .Release.Namespace }}
annotations:
nginx.ingress.kubernetes.io/denylist-source-range: "0.0.0.0/0,::/0"
spec:
ingressClassName: {{ .Values.ingress }}
rules:
- host: "{{ .Values.kerberoshub.api.url }}"
http:
paths:
- path: /metrics
pathType: Prefix
backend:
service:
name: hub-api-svc
port:
number: 8081
{{- if .Values.kerberoshub.api.legacyUrl }}
- host: "{{ .Values.kerberoshub.api.legacyUrl }}"
http:
paths:
- path: /metrics
pathType: Prefix
backend:
service:
name: hub-api-svc
port:
number: 8081
{{- end }}
- host: "admin.{{ .Values.kerberoshub.api.url }}"
http:
paths:
- path: /metrics
pathType: Prefix
backend:
service:
name: hub-api-svc
port:
number: 80
{{- end }}
+3
View File
@@ -138,6 +138,9 @@
"api": {
"type": "object",
"properties": {
"blockPublicMetrics": {
"type": "boolean"
},
"serviceMonitor": {
"type": "object",
"additionalProperties": false,
+4
View File
@@ -419,6 +419,10 @@ kerberoshub:
serviceMonitor:
enabled: true
interval: 15s
# With ingress: nginx, answer 403 for /metrics on the API hosts, so the
# Prometheus metrics (including database and collection names) are not
# public. Prometheus scrapes the Service directly and is not affected.
blockPublicMetrics: true
logLevel: "info" # possible values: trace, debug, info, warn, error
jwtSecret: "this-is-a-secret-please-change-to-random-string" # change to a random value, this is for generating JWT tokens.
# How long a user stays signed in (Go durations, e.g. "15m", "12h").