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

@ -19,6 +19,10 @@ resources:
- metabase.yaml
- backup.yaml
- httproute.yaml
# Default-deny ingress+egress + the tenant's allow list (audit F3 / t_fed52919).
- networkpolicy.yaml
# Tenant guardrails sized from the declared 1-replica shape (same card).
- quota.yaml
# Secrets, SOPS/age-encrypted in git. Flux decrypts them (the `apps`
# Kustomization carries a decryption block; key = flux-system/sops-age).
# Never add a plaintext Secret next to these — see docs/secrets-sops.md.

View file

@ -0,0 +1,78 @@
# Tenant isolation for `customer1` (audit finding F3 / A5-1, card t_fed52919).
#
# Two objects, two jobs:
# 1. `default-deny` (networking.k8s.io/v1) selects every pod in the namespace
# for BOTH directions and allows nothing. It is the only object here that
# creates a deny — a Kubernetes NetworkPolicy with `podSelector: {}` and no
# rules is an unambiguous deny-all in Cilium's k8s-policy path, and unlike a
# CiliumClusterwideNetworkPolicy with `endpointSelector: {}` it cannot
# accidentally select kube-system/Flux/CoreDNS.
# 2. `customer1-allow` (CiliumNetworkPolicy) re-adds exactly the traffic the
# tenant needs. Cilium unions all policies that select an endpoint, so the
# deny above plus this allow list is the effective policy.
#
# Why a CiliumNetworkPolicy for the allows: the sources to permit are Cilium
# *entities* (`ingress` = the Gateway listener proxy, `host` = the node/kubelet),
# which a stock NetworkPolicy cannot name.
#
# What this namespace is allowed to talk to — and nothing else:
# * its own pods (odoo/metabase -> pg:5432, the pg-backup CronJob -> pg),
# * kube-dns on 53.
# It gets NO internet egress (world) and NO API-server egress: the sandbox has
# no external dependency (backup.yaml: dumps stay on the local PVC, the Job has
# `automountServiceAccountToken: false`). If odoo/metabase are ever resumed and
# need an external service, add it here explicitly — that is the point.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: customer1
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
---
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: customer1-allow
namespace: customer1
spec:
description: >-
Customer-1 tenant: gateway + kubelet ingress only, egress to own namespace
and cluster DNS only.
endpointSelector: {}
ingress:
# reserved:ingress Cilium Gateway/listener proxy on siriussec (8086/8087)
# reserved:host this node's kubelet probes / host-network datapath
# reserved:remote-node node-sourced traffic when the pod is on another node
# reserved:health cilium-health probes
- 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: customer1
egress:
# Cluster DNS (CoreDNS only).
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: kube-system
k8s-app: kube-dns
toPorts:
- ports:
- port: "53"
protocol: UDP
- port: "53"
protocol: TCP
# Intra-namespace only: odoo/metabase -> pg:5432 and the backup Job -> pg.
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: customer1

View file

@ -0,0 +1,80 @@
# `customer1` tenant guardrails (audit finding F3 / A5-1, card t_fed52919).
#
# The sandbox is parked (`replicas: 0`, `suspend: true`, both committed in Git —
# see the README and the F21 note in the audit), so these numbers are derived
# from the DECLARED shape, not from `kubectl top` of a running tenant. Measured
# 2026-11-27 with `kubectl -n customer1 get deploy -o json` +
# `get cronjob pg-backup -o json`:
#
# workload requests limits replicas
# metabase 250m / 1Gi 1 CPU / 2Gi 0 (-> 1 when resumed)
# odoo 200m / 512Mi – / 2Gi 0 (-> 1)
# pg 100m / 256Mi – / 1Gi 0 (-> 1)
# pg-backup 50m / 128Mi – / 512Mi suspended Job
# ------------------------------------------------------------------
# total 600m / 1.88Gi 1 CPU / 5.5Gi at 1 replica + 1 Job
#
# The quota is the declared total with room for the one thing that always
# happens on a resumed stack: a RollingUpdate keeps maxSurge=25% of one replica
# alive next to the old pod. So requests get ~2x headroom (2 CPU / 4Gi), limits
# ~2x the declared peak (4 CPU / 10Gi) — a tenant cannot use more than two
# replicas' worth of anything at once, and a runaway pod is still cut off by its
# own limit, which is the LimitRange's job.
#
# Storage: 35Gi is already bound (odoo-data 10Gi + odoo-extra-addons 5Gi +
# pg-data 10Gi + backup-data 10Gi) — measured with `kubectl -n customer1 get
# pvc`. 45Gi allows exactly one more 10Gi claim and nothing more.
#
# Do not copy these numbers to another namespace: they describe this stack.
apiVersion: v1
kind: ResourceQuota
metadata:
name: customer1-quota
namespace: customer1
labels:
app.kubernetes.io/part-of: customer1
spec:
hard:
# Compute. Requests ~2x the declared 1-replica total (550m/1792Mi).
requests.cpu: "2"
requests.memory: 4Gi
limits.cpu: "4"
limits.memory: 10Gi
# Object counts. 3 workloads x 2 pods during a rolling update = 6, plus the
# pg-backup Job and room for one debug pod.
pods: "12"
count/jobs.batch: "8"
count/cronjobs.batch: "2"
services: "6"
# Storage: 35Gi bound -> one more 10Gi claim.
requests.storage: 45Gi
persistentvolumeclaims: "6"
---
# Container defaults so the quota above is satisfiable by every pod in the
# namespace: a ResourceQuota that constrains requests.cpu/limits.cpu rejects any
# pod without them, and the LimitRange injects them. `max` is the per-container
# ceiling — 2Gi is exactly metabase's declared limit, so the parked stack
# schedules unchanged when it is resumed; anything bigger now needs a namespace
# change on purpose.
apiVersion: v1
kind: LimitRange
metadata:
name: customer1-limits
namespace: customer1
labels:
app.kubernetes.io/part-of: customer1
spec:
limits:
- type: Container
defaultRequest:
cpu: 100m
memory: 128Mi
default:
cpu: 500m
memory: 512Mi
max:
cpu: "1"
memory: 2Gi
min:
cpu: 50m
memory: 64Mi