homek8s/apps/base/sirius-growth/networkpolicy.yaml
Lance Walters 668011809f fix(netpol): allow cnpg-system operator to read instance status on :8000
The CNPG operator dials each instance's HTTPS status endpoint
(https://<podIP>:8000/pg/status) to derive the system ID and drive
switchover. The tenant isolation added in t_fed52919 opened only
gateway/node/health entities, same-namespace pods and monitoring:9187,
so cnpg-system was denied: forgejo/pg and sirius-growth/portal sat at
Ready=False / ConsistentSystemID=False ('Instance Status Extraction
Error: HTTP communication issue') while their pods served traffic and
automated failover was effectively disabled.

Add one ingress rule to each CNP, scoped to the operator pod label
(app.kubernetes.io/name=cloudnative-pg in cnpg-system) and to TCP 8000
only. Not world, not the whole cluster, not 5432.
2026-12-04 14:25:37 -05:00

121 lines
4.8 KiB
YAML

# Tenant isolation for `sirius-growth` (audit finding F3 / A5-1, card t_fed52919).
#
# `default-deny` (stock NetworkPolicy, podSelector {}, both directions) is the
# deny. `sirius-growth-allow` (CiliumNetworkPolicy) re-adds what the namespace
# actually uses:
# ingress: Cilium Gateway proxy (`reserved:ingress`) for
# siriusgrowthsolutions.com -> site:80 / contact:8090 /
# portal-gate:8080 / portal:8091 / blog:8092, node entities for
# kubelet probes, Prometheus in `monitoring` on 9187 only (the
# `cnpg-portal` PodMonitor scrapes the CNPG instance manager), and
# the CNPG operator in `cnpg-system` on 8000 only — the instance
# manager's HTTPS status endpoint the operator reads to derive the
# system ID and drive failover (card t_4210edec).
# egress: cluster DNS; its own pods (blog/portal -> portal-1:5432,
# portal-gate -> portal:8091); `world` for the Telegram Bot API
# (contact + portal) and the leadgen crawlers; the node IPs on 3900
# (Garage S3: 10.10.0.1 for blog/portal media, 10.10.0.5 for the
# portal WAL ObjectStore) and on 22 (leadgen-backup rsyncs to
# [email protected]); and `kube-apiserver` for the CNPG instance
# manager, which needs the API for leader/status updates.
#
# Garage lives on node IPs, which Cilium maps to `reserved:remote-node`, not
# `world` — see apps/base/siriusdevops/networkpolicy.yaml for the original
# measurement (an `ipBlock`/toCIDR rule for 10.10.0.1 is silently inert here).
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: sirius-growth
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
---
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: sirius-growth-allow
namespace: sirius-growth
spec:
description: >-
sirius-growth: gateway + kubelet + Prometheus ingress; egress to own
namespace, cluster DNS, the internet, Garage/SSH on node IPs and the API.
endpointSelector: {}
ingress:
- fromEntities:
- ingress
- host
- remote-node
- health
# Intra-namespace pod -> pod (app -> db, sidecars, the backup CronJob).
# Cilium enforces policy at BOTH ends, so this allow must exist in ingress as
# well as egress — measured on `piedmont`: with only the egress rule a pod
# could not reach its own Service (TimeoutError).
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: sirius-growth
# The CNPG operator (`cnpg-system`) reads the instance manager's HTTPS
# status endpoint to derive the system ID and drive switchover/promotion.
# Without it the Cluster reports `Instance Status Extraction Error` and
# Ready=False while the pods serve traffic, and automated failover is dead
# (card t_4210edec). Scoped to 8000: not 5432, not the whole namespace.
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: cnpg-system
app.kubernetes.io/name: cloudnative-pg
toPorts:
- ports:
- port: "8000"
protocol: TCP
# Prometheus scrapes the CNPG `portal` instance manager on 9187.
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: monitoring
toPorts:
- ports:
- port: "9187"
protocol: TCP
egress:
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: kube-system
k8s-app: kube-dns
toPorts:
- ports:
- port: "53"
protocol: UDP
- port: "53"
protocol: TCP
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: sirius-growth
# Telegram Bot API + leadgen crawl targets.
- toEntities:
- world
# Garage S3 on the Pi (10.10.0.1) and the Linode (10.10.0.5); leadgen-backup
# SSH/rsync to [email protected]. Node IPs are `remote-node`, not `world`.
- toEntities:
- remote-node
toPorts:
- ports:
- port: "3900"
protocol: TCP
- port: "22"
protocol: TCP
# CNPG instance manager <-> kube-apiserver. Port-scoped on purpose: the
# apiserver is host-networked on 10.10.0.2, and Cilium attaches the
# `kube-apiserver` identity to that whole node IP — an unscoped entity rule
# also opens 8081/8084/8085/8086/8087 (the internal Gateway listeners) and
# :10250/:9100 on the same address. Measured: 10.10.0.2:8085 was OPEN from
# this namespace until the ports were named. 443 is the service port the
# CNPG instance manager dials (kubernetes.default:443 -> backend 6443).
- toEntities:
- kube-apiserver
toPorts:
- ports:
- port: "6443"
protocol: TCP
- port: "443"
protocol: TCP