From d3741df61949d51631076b5c14cbc5b580198653 Mon Sep 17 00:00:00 2001 From: Lance Walters Date: Tue, 27 Oct 2026 00:12:38 -0400 Subject: [PATCH] monitoring: kube-prometheus-stack + WireGuard-only Grafana via the internal gateway - clusters/homek8s/monitoring.yaml: the 'monitoring' Flux Kustomization was declared only under clusters/home, which the bootstrapped flux-system Kustomization never reads (its path is ./clusters/homek8s), so it had never been created. Declare it in the tree that actually reconciles. - monitoring/controllers/home: HelmRepository + HelmRelease (chart pinned 92.14.0), values.yaml via configMapGenerator, Grafana admin from the monitoring/grafana-admin Secret (out of band, never in git). - Everything pinned to siriussec, Prometheus on a 10Gi local-path PVC with 7d AND 8GB retention caps; alertmanager off; no remote write. - internal gateway listener now accepts routes from any namespace; the security boundary is the host firewall, not the namespace. - host-firewall/: nft table + oneshot unit for siriussec and the ufw script for rpi that close :8081 to everything but 10.10.0.0/24 and 10.244.0.0/16. --- clusters/homek8s/monitoring.yaml | 16 ++ .../networking/internal/gateway.yaml | 6 +- .../internal/host-firewall/README.md | 49 ++++++ .../internal-gw-firewall.service | 17 +++ .../internal/host-firewall/rpi-ufw-8081.sh | 22 +++ .../host-firewall/siriussec-internal-gw.nft | 26 ++++ monitoring/controllers/home/httproute.yaml | 28 ++++ .../controllers/home/kustomization.yaml | 13 +- .../controllers/home/kustomizeconfig.yaml | 6 + monitoring/controllers/home/namespace.yaml | 4 + monitoring/controllers/home/release.yaml | 34 +++++ monitoring/controllers/home/repository.yaml | 8 + monitoring/controllers/home/values.yaml | 140 ++++++++++++++++++ 13 files changed, 367 insertions(+), 2 deletions(-) create mode 100644 clusters/homek8s/monitoring.yaml create mode 100644 infrastructure/networking/internal/host-firewall/README.md create mode 100644 infrastructure/networking/internal/host-firewall/internal-gw-firewall.service create mode 100644 infrastructure/networking/internal/host-firewall/rpi-ufw-8081.sh create mode 100644 infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft create mode 100644 monitoring/controllers/home/httproute.yaml create mode 100644 monitoring/controllers/home/kustomizeconfig.yaml create mode 100644 monitoring/controllers/home/namespace.yaml create mode 100644 monitoring/controllers/home/release.yaml create mode 100644 monitoring/controllers/home/repository.yaml create mode 100644 monitoring/controllers/home/values.yaml diff --git a/clusters/homek8s/monitoring.yaml b/clusters/homek8s/monitoring.yaml new file mode 100644 index 0000000..a4b2e17 --- /dev/null +++ b/clusters/homek8s/monitoring.yaml @@ -0,0 +1,16 @@ +apiVersion: kustomize.toolkit.fluxcd.io/v1 +kind: Kustomization +metadata: + name: monitoring + namespace: flux-system +spec: + interval: 1m0s + retryInterval: 1m + timeout: 15m + sourceRef: + kind: GitRepository + name: flux-system + path: ./monitoring/controllers/home + prune: true + dependsOn: + - name: infrastructure diff --git a/infrastructure/networking/internal/gateway.yaml b/infrastructure/networking/internal/gateway.yaml index cc2beef..397b668 100644 --- a/infrastructure/networking/internal/gateway.yaml +++ b/infrastructure/networking/internal/gateway.yaml @@ -11,6 +11,10 @@ spec: - name: http-internal protocol: HTTP port: 8081 + # Any namespace may attach a route: the security boundary for this listener + # is the HOST firewall (only 10.10.0.0/24 + pod CIDR may reach :8081), not + # the namespace. Keeps the pattern reusable for the next internal service + # (Hubble lives in kube-system) without editing this Gateway again. allowedRoutes: namespaces: - from: Same + from: All diff --git a/infrastructure/networking/internal/host-firewall/README.md b/infrastructure/networking/internal/host-firewall/README.md new file mode 100644 index 0000000..c8db9af --- /dev/null +++ b/infrastructure/networking/internal/host-firewall/README.md @@ -0,0 +1,49 @@ +# Internal Gateway host firewall + +Cilium programs every Gateway listener on **all** nodes carrying +`node-role.kubernetes.io/gateway=true` (`rpi` = 10.10.0.1, `siriussec` = +10.10.0.2) and its Envoy binds `0.0.0.0:` in the host network +namespace. So `gateway-system/public` on 8080 and `internal/internal` on 8081 +are *both* listening on the LAN interfaces; the Gateway API object cannot say +"WireGuard only". The host firewall is the enforcement point: + +| Host | Mechanism | Artifact | +|------|-----------|----------| +| siriussec (10.10.0.2) | nftables table `inet internal_gw`, loaded by a oneshot unit (same pattern as `k8s-api-firewall.service`) | `siriussec-internal-gw.nft`, `internal-gw-firewall.service` | +| rpi (10.10.0.1) | ufw rules inserted above the `allow from 192.168.1.0/24` catch-all | `rpi-ufw-8081.sh` | + +Effective policy for `:8081` on both hosts: **accept from 10.10.0.0/24 and +10.244.0.0/16, accept on lo, drop everything else** (LAN, tailscale, public). + +These are host units, not Flux objects — a node reinstall has to re-apply them. +Install: + +```bash +# siriussec, as root +install -m 0644 siriussec-internal-gw.nft /etc/nftables.d/internal-gw.nft +install -m 0644 internal-gw-firewall.service /etc/systemd/system/ +systemctl daemon-reload && systemctl enable --now internal-gw-firewall.service + +# rpi, as root +bash rpi-ufw-8081.sh +``` + +Verify: + +```bash +# siriussec +nft list table inet internal_gw +# rpi +ufw status | grep 8081 +``` + +Negative test from the LAN must be a timeout (DROP), never 200: + +```bash +curl -m 3 -sS -o /dev/null -w '%{http_code}\n' http://192.168.1.179:8081/ # empty/000 +curl -m 3 -sS -o /dev/null -w '%{http_code}\n' http://192.168.1.125:8081/ # empty/000 +``` + +When a new internal listener port is added, add the same three lines with the +new port to both artifacts — one deny for the port, allows for the mesh and the +pod CIDR, inserted above the LAN catch-all. diff --git a/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service b/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service new file mode 100644 index 0000000..93a3582 --- /dev/null +++ b/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service @@ -0,0 +1,17 @@ +# /etc/systemd/system/internal-gw-firewall.service (siriussec) +# +# Same shape as k8s-api-firewall.service. Installed by hand (host unit, not +# Flux-managed); the file lives in git at +# infrastructure/networking/internal/host-firewall/. +[Unit] +Description=Restrict the internal Gateway listener (8081) to WireGuard +After=network-online.target +Wants=network-online.target + +[Service] +Type=oneshot +ExecStart=/usr/sbin/nft -f /etc/nftables.d/internal-gw.nft +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/infrastructure/networking/internal/host-firewall/rpi-ufw-8081.sh b/infrastructure/networking/internal/host-firewall/rpi-ufw-8081.sh new file mode 100644 index 0000000..9f85934 --- /dev/null +++ b/infrastructure/networking/internal/host-firewall/rpi-ufw-8081.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# rpi: restrict the internal Gateway listener (TCP 8081) to WireGuard + pods. +# +# ufw on rpi already has `allow from 192.168.1.0/24` (any port), so the deny has +# to sit ABOVE it — hence `ufw insert`, not `ufw allow/deny` (which appends). +# Final order for 8081: allow 10.10.0.0/24, allow 10.244.0.0/16, deny the rest. +# +# Idempotent: re-running after the rules exist is a no-op. +# Run as root on rpi (192.168.1.125). +set -euo pipefail + +if ufw status | grep -q '8081'; then + echo "8081 rules already present:" + ufw status | grep '8081' + exit 0 +fi + +ufw insert 1 deny to any port 8081 proto tcp comment 'internal gateway: wg only' +ufw insert 1 allow from 10.10.0.0/24 to any port 8081 proto tcp comment 'internal gateway (wg mesh)' +ufw insert 2 allow from 10.244.0.0/16 to any port 8081 proto tcp comment 'internal gateway (pods)' + +ufw status | grep '8081' diff --git a/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft b/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft new file mode 100644 index 0000000..8acecbe --- /dev/null +++ b/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft @@ -0,0 +1,26 @@ +#!/usr/sbin/nft -f +# Internal (WireGuard-only) gateway listener: TCP 8081. +# +# Cilium's hostNetwork Envoy binds every Gateway listener on 0.0.0.0, so the +# internal listener is open on the LAN interface the moment the Gateway is +# programmed. This table makes :8081 answer only from the WireGuard mesh and the +# pod network. DROP (not reject) so a LAN scan sees a timeout, not a port that +# tells you something is listening. +# +# Loaded by internal-gw-firewall.service on siriussec. +# The equivalent on rpi is the ufw rules in rpi-ufw-8081.sh. +table inet internal_gw { + chain input { + type filter hook input priority filter; policy accept; + + # local process / kubelet probes + tcp dport 8081 iifname "lo" accept + + # WireGuard mesh (Legion = 10.10.0.3, nodes, remote hub spokes) + # and the pod network (in-cluster scrapers, probes) + tcp dport 8081 ip saddr { 10.10.0.0/24, 10.244.0.0/16 } accept + + # everything else: LAN, tailscale, public + tcp dport 8081 counter drop + } +} diff --git a/monitoring/controllers/home/httproute.yaml b/monitoring/controllers/home/httproute.yaml new file mode 100644 index 0000000..45e8b5b --- /dev/null +++ b/monitoring/controllers/home/httproute.yaml @@ -0,0 +1,28 @@ +# Grafana is served by the INTERNAL gateway only (gateway-system is the public +# one, fed by the Cloudflare tunnel). There is no Cloudflare ingress entry for +# this hostname and there must never be one. +# +# Reachable at http://grafana.lab.internal:8081 over WireGuard: +# Legion /etc/hosts: 10.10.0.2 grafana.lab.internal +# The listener answers only on 10.10.0.0/24 + the pod CIDR — the host firewall +# (see docs/internal-wireguard-services.md) drops :8081 everywhere else. +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: grafana + namespace: monitoring +spec: + parentRefs: + - name: internal + namespace: internal + sectionName: http-internal + hostnames: + - grafana.lab.internal + rules: + - matches: + - path: + type: PathPrefix + value: / + backendRefs: + - name: kube-prometheus-stack-grafana + port: 80 diff --git a/monitoring/controllers/home/kustomization.yaml b/monitoring/controllers/home/kustomization.yaml index b83b23e..a18bc33 100644 --- a/monitoring/controllers/home/kustomization.yaml +++ b/monitoring/controllers/home/kustomization.yaml @@ -1,3 +1,14 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization -resources: [] +namespace: monitoring +resources: + - namespace.yaml + - repository.yaml + - release.yaml + - httproute.yaml +configMapGenerator: + - name: kube-prometheus-stack-values + files: + - values.yaml=values.yaml +configurations: + - kustomizeconfig.yaml diff --git a/monitoring/controllers/home/kustomizeconfig.yaml b/monitoring/controllers/home/kustomizeconfig.yaml new file mode 100644 index 0000000..a80be15 --- /dev/null +++ b/monitoring/controllers/home/kustomizeconfig.yaml @@ -0,0 +1,6 @@ +nameReference: + - kind: ConfigMap + version: v1 + fieldSpecs: + - path: spec/valuesFrom/name + kind: HelmRelease diff --git a/monitoring/controllers/home/namespace.yaml b/monitoring/controllers/home/namespace.yaml new file mode 100644 index 0000000..d325236 --- /dev/null +++ b/monitoring/controllers/home/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: monitoring diff --git a/monitoring/controllers/home/release.yaml b/monitoring/controllers/home/release.yaml new file mode 100644 index 0000000..75ba0d1 --- /dev/null +++ b/monitoring/controllers/home/release.yaml @@ -0,0 +1,34 @@ +apiVersion: helm.toolkit.fluxcd.io/v2 +kind: HelmRelease +metadata: + name: kube-prometheus-stack + namespace: monitoring +spec: + releaseName: kube-prometheus-stack + interval: 30m + chart: + spec: + chart: kube-prometheus-stack + # Pinned — never a floating range. Bump deliberately. + version: "92.14.0" + sourceRef: + kind: HelmRepository + name: prometheus-community + namespace: monitoring + install: + crds: Create + timeout: 15m + remediation: + retries: 3 + upgrade: + crds: CreateReplace + timeout: 15m + cleanupOnFail: true + remediation: + retries: 3 + remediateLastFailure: true + # Values live in monitoring/controllers/home/values.yaml, rendered to a + # Flux ConfigMap (kube-prometheus-stack-values-) by kustomize. + valuesFrom: + - kind: ConfigMap + name: kube-prometheus-stack-values diff --git a/monitoring/controllers/home/repository.yaml b/monitoring/controllers/home/repository.yaml new file mode 100644 index 0000000..96e0994 --- /dev/null +++ b/monitoring/controllers/home/repository.yaml @@ -0,0 +1,8 @@ +apiVersion: source.toolkit.fluxcd.io/v1 +kind: HelmRepository +metadata: + name: prometheus-community + namespace: monitoring +spec: + interval: 24h + url: https://prometheus-community.github.io/helm-charts diff --git a/monitoring/controllers/home/values.yaml b/monitoring/controllers/home/values.yaml new file mode 100644 index 0000000..51be14a --- /dev/null +++ b/monitoring/controllers/home/values.yaml @@ -0,0 +1,140 @@ +# kube-prometheus-stack values — home cluster (Sirius DevOps) +# +# Pinned in release.yaml to chart 92.14.0 (appVersion v0.94.2). +# Everything lands on siriussec: amd64 image (rpi is arm64) + local-path PVs. +# Prometheus is capped twice (time AND bytes) so a metrics burst can never +# repeat the ephemeral-storage / DiskPressure incident (see docs/cluster-overview.md). + +# --- Alertmanager: off. No receivers in this card; alerts fire to nowhere on purpose. +alertmanager: + enabled: false + +defaultRules: + create: true + # Control-plane / proxy components that this cluster does not expose to + # Prometheus: kube-proxy is replaced by Cilium, and the kubeadm static pods + # only bind their metrics on 127.0.0.1. Rules for them would sit "firing" + # forever, so drop the whole groups that depend on those targets. + rules: + kubeProxy: false + kubeControllerManager: false + kubeScheduler: false + kubeEtcd: false + +# --- Control-plane targets that are unreachable or lift-heavy for a lab box +kubeProxy: + enabled: false +kubeControllerManager: + enabled: false +kubeScheduler: + enabled: false +kubeEtcd: + enabled: false +kubeApiServer: + enabled: true + +prometheusOperator: + nodeSelector: + kubernetes.io/hostname: siriussec + resources: + requests: + cpu: 50m + memory: 128Mi + limits: + cpu: 500m + memory: 256Mi + admissionWebhooks: + patch: + nodeSelector: + kubernetes.io/hostname: siriussec + +prometheus: + enabled: true + prometheusSpec: + # Storage: local-path on siriussec. 10Gi PVC + an 8GB TSDB cap leaves + # headroom for WAL/checkpoint files inside the same volume. + retention: 7d + retentionSize: 8GB + scrapeInterval: 30s + evaluationInterval: 30s + nodeSelector: + kubernetes.io/hostname: siriussec + resources: + requests: + cpu: 200m + memory: 512Mi + limits: + cpu: "1" + memory: 2Gi + storageSpec: + volumeClaimTemplate: + spec: + storageClassName: local-path + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + # No remoteWrite / remoteRead / receivers: metrics never leave the cluster. + +grafana: + enabled: true + nodeSelector: + kubernetes.io/hostname: siriussec + # Admin credentials live in the monitoring/grafana-admin Secret (created out of + # band with kubectl, never in git). Keys: admin-user, admin-password. + admin: + existingSecret: grafana-admin + resources: + requests: + cpu: 50m + memory: 128Mi + limits: + cpu: 500m + memory: 512Mi + # Dashboards and datasources are provisioned from ConfigMaps (chart-generated, + # sidecar-loaded) — nothing is created by hand in the UI. + defaultDashboardsEnabled: true + sidecar: + dashboards: + enabled: true + label: grafana_dashboard + datasources: + enabled: true + label: grafana_datasource + # No persistence: Grafana state is provisioned from git, and a PVC here would + # only compete for the same disk that Prometheus needs. + persistence: + enabled: false + grafana.ini: + auth.anonymous: + enabled: false + users: + allow_sign_up: false + analytics: + reporting_enabled: false + +kube-state-metrics: + nodeSelector: + kubernetes.io/hostname: siriussec + resources: + requests: + cpu: 20m + memory: 32Mi + limits: + cpu: 200m + memory: 256Mi + +prometheus-node-exporter: + # DaemonSet; pinned to siriussec per the stack's scheduling rule. Only + # siriussec's node metrics are collected (kubelet/cAdvisor metrics for the + # other nodes still arrive via the kubelet ServiceMonitor). + nodeSelector: + kubernetes.io/hostname: siriussec + resources: + requests: + cpu: 20m + memory: 32Mi + limits: + cpu: 200m + memory: 128Mi