diff --git a/apps/base/metabase/cluster.yaml b/apps/base/metabase/cluster.yaml new file mode 100644 index 0000000..18d404d --- /dev/null +++ b/apps/base/metabase/cluster.yaml @@ -0,0 +1,38 @@ +# Metabase's application database (its own metadata only: users, dashboards, +# questions, saved queries — never the data it queries). +# +# Same shape as every other CNPG cluster in this repo: one instance, local-path +# on siriussec, no superuser access. `bootstrap.initdb.secret` names the +# out-of-band Secret `metabase/pg-app` (kubernetes.io/basic-auth, username +# `metabase` — CNPG requires the secret's username to equal `owner`). The +# operator materialises `pg-app` with the same credentials for the Deployment. +# +# No barman ObjectStore yet: the other clusters get WAL archiving to Garage via +# the CNPG-I Barman Cloud plugin; this evaluation instance is deliberately left +# with no archive until Lance keeps it (follow-up card, not a silent gap). +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: pg + namespace: metabase +spec: + instances: 1 + imageName: ghcr.io/cloudnative-pg/postgresql:16 + storage: + size: 5Gi + storageClass: local-path + affinity: + nodeSelector: + kubernetes.io/hostname: siriussec + bootstrap: + initdb: + database: metabase + owner: metabase + secret: + name: pg-app + resources: + requests: + cpu: 100m + memory: 256Mi + limits: + memory: 1Gi diff --git a/apps/base/metabase/deployment.yaml b/apps/base/metabase/deployment.yaml new file mode 100644 index 0000000..d7c6fd2 --- /dev/null +++ b/apps/base/metabase/deployment.yaml @@ -0,0 +1,83 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: metabase + namespace: metabase +spec: + replicas: 1 + selector: + matchLabels: + app: metabase + template: + metadata: + labels: + app: metabase + spec: + # Siriussec is the only gateway node (upstream Envoy has to reach the + # backend pod on the same node), and the CNPG primary is pinned here too. + nodeSelector: + kubernetes.io/hostname: siriussec + tolerations: + - key: dedicated + operator: Exists + effect: PreferNoSchedule + containers: + - name: metabase + # Pinned release tag (2026-11-20, multi-arch). Never latest/nightly: + # Metabase auto-migrates its app DB on start, so an unpinned tag turns + # a pod restart into a schema upgrade. + image: metabase/metabase:v0.65.6.3 + imagePullPolicy: IfNotPresent + ports: + - name: http + containerPort: 3000 + env: + # One JVM, 1.5 GiB heap, container limit 2 GiB. The laptop is on a + # marginal USB-C supply; a 2 GiB heap here is what starved it in the + # past (see references/laptop-node-power.md). + - name: JAVA_OPTS + value: "-Xmx1536m" + # All state lives in Postgres (no H2 file, no PVC), so the pod is + # disposable and `strategy: Recreate` is unnecessary. + - name: MB_DB_TYPE + value: postgres + - name: MB_DB_HOST + value: pg-rw.metabase.svc.cluster.local + - name: MB_DB_PORT + value: "5432" + - name: MB_DB_DBNAME + value: metabase + - name: MB_DB_USER + valueFrom: + secretKeyRef: + name: pg-app + key: username + - name: MB_DB_PASS + valueFrom: + secretKeyRef: + name: pg-app + key: password + readinessProbe: + httpGet: + path: /api/health + port: 3000 + # The JVM takes ~30-60 s to migrate/bootstrap its app DB. + initialDelaySeconds: 20 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 6 + livenessProbe: + httpGet: + path: /api/health + port: 3000 + initialDelaySeconds: 120 + periodSeconds: 30 + timeoutSeconds: 10 + failureThreshold: 3 + resources: + requests: + cpu: 250m + memory: 1Gi + limits: + cpu: "2" + memory: 2Gi diff --git a/apps/base/metabase/httproute.yaml b/apps/base/metabase/httproute.yaml new file mode 100644 index 0000000..1ad119e --- /dev/null +++ b/apps/base/metabase/httproute.yaml @@ -0,0 +1,25 @@ +# Internal only, and deliberately HOSTNAME-LESS: it answers on the bare WireGuard +# address http://10.10.0.2:8085/ for every Host header. Phones cannot edit +# /etc/hosts, so a hostname would make the evaluation unusable on mobile. +# +# parentRefs is the dedicated `metabase` Gateway (infrastructure/networking/ +# internal/gateway-metabase.yaml), NOT the shared `internal` one: Cilium merges +# every hostname-less route of a Gateway into one weighted route, so sharing a +# Gateway with Grafana would serve both services on both ports at random. +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: metabase + namespace: metabase +spec: + parentRefs: + - name: metabase + namespace: internal + rules: + - matches: + - path: + type: PathPrefix + value: / + backendRefs: + - name: metabase + port: 3000 diff --git a/apps/base/metabase/kustomization.yaml b/apps/base/metabase/kustomization.yaml new file mode 100644 index 0000000..aaf2916 --- /dev/null +++ b/apps/base/metabase/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - namespace.yaml + # Secret metabase/pg-app (kubernetes.io/basic-auth) is created out of band + # before this Cluster applies — CNPG's initdb reads it. + - cluster.yaml + - deployment.yaml + - service.yaml + - httproute.yaml diff --git a/apps/base/metabase/namespace.yaml b/apps/base/metabase/namespace.yaml new file mode 100644 index 0000000..763c274 --- /dev/null +++ b/apps/base/metabase/namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: metabase + labels: + app.kubernetes.io/part-of: metabase diff --git a/apps/base/metabase/service.yaml b/apps/base/metabase/service.yaml new file mode 100644 index 0000000..89f8d74 --- /dev/null +++ b/apps/base/metabase/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: metabase + namespace: metabase +spec: + type: ClusterIP + selector: + app: metabase + ports: + - name: http + port: 3000 + targetPort: 3000 + protocol: TCP diff --git a/apps/home/kustomization.yaml b/apps/home/kustomization.yaml index 1a08fad..18845da 100644 --- a/apps/home/kustomization.yaml +++ b/apps/home/kustomization.yaml @@ -6,3 +6,4 @@ resources: - ../base/piedmont - ../base/sirius-growth - ../base/osint + - ../base/metabase diff --git a/infrastructure/networking/internal/gateway-metabase.yaml b/infrastructure/networking/internal/gateway-metabase.yaml new file mode 100644 index 0000000..1eedd8b --- /dev/null +++ b/infrastructure/networking/internal/gateway-metabase.yaml @@ -0,0 +1,31 @@ +apiVersion: gateway.networking.k8s.io/v1 +kind: Gateway +metadata: + name: metabase + namespace: internal + labels: + dedicated: network + annotations: + # Why a second Gateway instead of a second listener on `internal`: + # Cilium renders one RouteConfiguration per Gateway shared by all its + # listeners, so a hostname-less route on any listener of `internal` would + # merge with Grafana's into one 50/50 weighted route. Its own Gateway gives + # it its own RouteConfiguration. + sirius.dev/purpose: bare-IP listener for Metabase (WireGuard only) +spec: + gatewayClassName: cilium + listeners: + - name: http-internal + protocol: HTTP + # PORT MUST BE FREE ON *EVERY* NODE THAT RUNS cilium-envoy (siriussec + # 10.10.0.2 is the only `gateway=true` node today). Cilium binds + # 0.0.0.0: hostNetwork, so a port held by anything else on a gateway + # node makes xDS reject the listener there ("cannot bind '0.0.0.0:': + # Address already in use") and restart-loops that node's Envoy — which + # fronts the public ingress. Verified free 2026-11-22: + # `ss -lntH "sport = :8085" | wc -l` = 0 on siriussec. + # 8080 (public), 8081 (Grafana), 8084 (Hubble UI) are taken. + port: 8085 + allowedRoutes: + namespaces: + from: All diff --git a/infrastructure/networking/internal/host-firewall/README.md b/infrastructure/networking/internal/host-firewall/README.md index b8a037b..e03fd2e 100644 --- a/infrastructure/networking/internal/host-firewall/README.md +++ b/infrastructure/networking/internal/host-firewall/README.md @@ -21,7 +21,8 @@ exactly one node. | siriussec (10.10.0.2) — **load bearing** | 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) — **inert guard** | ufw rules inserted above the `allow from 192.168.1.0/24` catch-all | `rpi-ufw-internal-gw.sh` | -Effective policy for `:8081` (Grafana) and `:8084` (Hubble UI): +Effective policy for `:8081` (Grafana), `:8084` (Hubble UI) and `:8085` +(Metabase): **accept from 10.10.0.0/24 and 10.244.0.0/16, accept on lo, drop everything else** (LAN, tailscale, public). Envoy binds every listener on `0.0.0.0`, so a new internal listener port is a LAN exposure until it is added here. The @@ -56,7 +57,7 @@ Verify: # the drop counter non-zero after a LAN request nft list table inet internal_gw # rpi -ufw status | grep -E '8081|8084' +ufw status | grep -E '8081|8084|8085' ``` Negative test from the LAN must be a timeout (DROP), never 200: @@ -70,4 +71,4 @@ When a new internal listener port is added, add it to the `tcp dport { … }` se in `siriussec-internal-gw.nft` and to `PORTS` in `rpi-ufw-internal-gw.sh` (which inserts one deny for the port plus mesh and pod-CIDR allows above the LAN catch-all), then reinstall both and re-run the two negative tests above with the -new port. +new port. \ No newline at end of file diff --git a/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service b/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service index 1d60425..c46890b 100644 --- a/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service +++ b/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service @@ -4,7 +4,7 @@ # Flux-managed); the file lives in git at # infrastructure/networking/internal/host-firewall/. [Unit] -Description=Restrict the internal Gateway listeners (8081, 8082) to WireGuard +Description=Restrict the internal Gateway listeners (8081, 8084, 8085) to WireGuard After=network-online.target Wants=network-online.target @@ -14,4 +14,4 @@ ExecStart=/usr/sbin/nft -f /etc/nftables.d/internal-gw.nft RemainAfterExit=yes [Install] -WantedBy=multi-user.target +WantedBy=multi-user.target \ No newline at end of file diff --git a/infrastructure/networking/internal/host-firewall/rpi-ufw-internal-gw.sh b/infrastructure/networking/internal/host-firewall/rpi-ufw-internal-gw.sh index 9c02418..fcbba69 100644 --- a/infrastructure/networking/internal/host-firewall/rpi-ufw-internal-gw.sh +++ b/infrastructure/networking/internal/host-firewall/rpi-ufw-internal-gw.sh @@ -6,14 +6,15 @@ # Final order per port: allow 10.10.0.0/24, allow 10.244.0.0/16, deny the rest. # # Ports: 8081 = Grafana (`internal` Gateway listener http-internal), -# 8084 = Hubble UI (`internal` Gateway listener hubble-ui). +# 8084 = Hubble UI (`internal` Gateway listener hubble-ui), +# 8085 = Metabase (`metabase` Gateway listener http-internal). # Add a new internal listener port to PORTS; the loop is idempotent, so # re-running after a port is already firewalled only adds what is missing. # # Run as root on rpi (192.168.1.125). set -euo pipefail -PORTS="${PORTS:-8081 8084}" +PORTS="${PORTS:-8081 8084 8085}" for port in $PORTS; do if ufw status | grep -q "${port}/tcp"; then @@ -28,4 +29,4 @@ for port in $PORTS; do echo "$port rules installed:" ufw status | grep "${port}/tcp" || true -done +done \ No newline at end of file diff --git a/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft b/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft index 9f51db6..16a9801 100644 --- a/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft +++ b/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft @@ -1,6 +1,6 @@ #!/usr/sbin/nft -f -# Internal (WireGuard-only) gateway listeners: TCP 8081 (Grafana) and 8084 -# (Hubble UI). +# Internal (WireGuard-only) gateway listeners: TCP 8081 (Grafana), 8084 +# (Hubble UI) and 8085 (Metabase). # # Cilium's hostNetwork Envoy binds every Gateway listener on 0.0.0.0, so the # internal listeners are open on the LAN interface the moment the Gateway is @@ -22,13 +22,13 @@ table inet internal_gw { type filter hook input priority filter; policy accept; # local process / kubelet probes - tcp dport { 8081, 8084 } iifname "lo" counter accept + tcp dport { 8081, 8084, 8085 } iifname "lo" counter accept # WireGuard mesh (Legion = 10.10.0.3, nodes, remote hub spokes) # and the pod network (in-cluster scrapers, probes) - tcp dport { 8081, 8084 } ip saddr { 10.10.0.0/24, 10.244.0.0/16 } counter accept + tcp dport { 8081, 8084, 8085 } ip saddr { 10.10.0.0/24, 10.244.0.0/16 } counter accept # everything else: LAN, tailscale, public - tcp dport { 8081, 8084 } counter drop + tcp dport { 8081, 8084, 8085 } counter drop } -} +} \ No newline at end of file diff --git a/infrastructure/networking/internal/kustomization.yaml b/infrastructure/networking/internal/kustomization.yaml index 60f44f2..d6d0f1e 100644 --- a/infrastructure/networking/internal/kustomization.yaml +++ b/infrastructure/networking/internal/kustomization.yaml @@ -4,3 +4,4 @@ resources: - namespace.yaml - gateway.yaml - gateway-hubble-ui.yaml + - gateway-metabase.yaml