diff --git a/charts/hub/Chart.yaml b/charts/hub/Chart.yaml index 492e1b4..163f1cd 100644 --- a/charts/hub/Chart.yaml +++ b/charts/hub/Chart.yaml @@ -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 diff --git a/charts/hub/README.md b/charts/hub/README.md index c9f9254..331f322 100644 --- a/charts/hub/README.md +++ b/charts/hub/README.md @@ -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"` | diff --git a/charts/hub/templates/kerberos-hub/hub-api-metrics-ingress.yaml b/charts/hub/templates/kerberos-hub/hub-api-metrics-ingress.yaml new file mode 100644 index 0000000..7db232e --- /dev/null +++ b/charts/hub/templates/kerberos-hub/hub-api-metrics-ingress.yaml @@ -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 }} diff --git a/charts/hub/values.schema.json b/charts/hub/values.schema.json index 0ea6093..9fa2ac4 100644 --- a/charts/hub/values.schema.json +++ b/charts/hub/values.schema.json @@ -138,6 +138,9 @@ "api": { "type": "object", "properties": { + "blockPublicMetrics": { + "type": "boolean" + }, "serviceMonitor": { "type": "object", "additionalProperties": false, diff --git a/charts/hub/values.yaml b/charts/hub/values.yaml index 16193b7..3d956aa 100644 --- a/charts/hub/values.yaml +++ b/charts/hub/values.yaml @@ -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").