infra(netpol): default-deny ingress+egress for the six app namespaces

Audit F3 / A5-1. Every pod in customer1, osint, sirius-growth, piedmont,
siriusdevops and forgejo was reachable from every other pod, from the API
server, from the internal WireGuard-only Gateway ports on 10.10.0.2 and from
the internet.

- each namespace: a stock NetworkPolicy 'default-deny' (podSelector {},
  Ingress+Egress, no rules) plus a CiliumNetworkPolicy allow that names the
  gateway/kubelet/health entities, same-namespace pods, cluster DNS and only
  the egress each workload actually uses (world for Telegram/news/inference,
  remote-node :3900 for Garage, :22 for the backup rsync, kube-apiserver :6443
  where CNPG/kubectl needs it, none at all for customer1)
- siriusdevops: replaces the egress-only siriusdevops-site-egress CNP
- customer1: ResourceQuota + LimitRange sized from the declared 1-replica
  shape (35Gi already bound, 2 CPU / 4Gi requests) - the sandbox stays parked
- docs/network-isolation.md: the model plus the five gotchas measured while
  landing it (both-ends enforcement, kube-apiserver identity covering the
  whole node IP, remote-node vs world for Garage, ingress vs host identity)
This commit is contained in:
Lance Walters 2026-11-27 02:19:10 -05:00
commit 69b003705c
15 changed files with 701 additions and 71 deletions

View file

@ -6,6 +6,8 @@ resources:
- namespace.yaml
- ci-runners-namespace.yaml
- httproute.yaml
# Default-deny ingress+egress + the namespace allow list (audit F3 / t_fed52919).
- networkpolicy.yaml
- pvc.yaml
- cluster.yaml
- podmonitor.yaml

View file

@ -0,0 +1,103 @@
# Tenant isolation for `forgejo` (audit finding F3 / A5-1, card t_fed52919).
#
# `default-deny` (stock NetworkPolicy, podSelector {}, both directions) is the
# deny. `forgejo-allow` (CiliumNetworkPolicy) re-adds what this namespace uses:
# ingress: the Cilium Gateway proxy (`reserved:ingress`) for
# forgejo.siriusdevops.com -> forgejo:3000. The CI runners live in
# `ci-runners` and register/poll over the PUBLIC URL
# (runner-amd64.yaml: `--instance https://forgejo.siriusdevops.com`),
# so they arrive through the Gateway as `reserved:ingress` too and no
# cross-namespace rule is needed. Node/health entities cover kubelet
# probes; Prometheus in `monitoring` is allowed on 9187 only (the
# `cnpg-pg` PodMonitor scrapes the CNPG instance manager).
# egress: cluster DNS; its own pods (forgejo -> pg-rw:5432); `world` for
# outbound HTTPS (Forgejo webhooks, avatar/mirror fetches, the
# public-URL callbacks the runner flow needs); node IPs on 22, which
# is the nightly `cluster-backup` CronJob rsyncing to
# [email protected]; and `kube-apiserver`, needed by the CNPG instance
# manager and by cluster-backup's `kubectl get cluster` /
# `kubectl exec` DB dumps.
#
# The CI runner pods themselves are NOT in this namespace (they moved to
# `ci-runners` for `enforce: privileged`) and are out of scope for this card.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: forgejo
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
---
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: forgejo-allow
namespace: forgejo
spec:
description: >-
forgejo: gateway + kubelet + Prometheus ingress; egress to own namespace,
cluster DNS, the internet, 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: forgejo
# Prometheus scrapes the CNPG `pg` 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: forgejo
# Outbound HTTPS: webhooks, mirrors, avatar fetching.
- toEntities:
- world
# cluster-backup rsync/ssh to [email protected] (the Linode node).
- toEntities:
- remote-node
toPorts:
- ports:
- port: "22"
protocol: TCP
# CNPG instance manager and cluster-backup's kubectl calls. 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
# kubectl dials (kubernetes.default:443 -> backend 6443).
- toEntities:
- kube-apiserver
toPorts:
- ports:
- port: "6443"
protocol: TCP
- port: "443"
protocol: TCP