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

Merged
sirius merged 1 commit from wt/t_fed52919 into master 2026-11-27 07:19:43 +00:00
15 changed files with 701 additions and 71 deletions
Showing only changes of commit 69b003705c - Show all commits

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)
Lance Walters 2026-11-27 02:19:10 -05:00

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

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

View file

@ -19,6 +19,8 @@ resources:
- news-scraper-deployment.yaml
- news-summarizer-deployment.yaml
- httproute.yaml
# Default-deny ingress+egress + the namespace allow list (audit F3 / t_fed52919).
- networkpolicy.yaml
# exec-only RBAC so forgejo/cluster-backup can pg_dump this namespace's plain
# Postgres Deployment (osint-db) — not a CNPG cluster, so it needs its own path.
- backup-exec-rbac.yaml

View file

@ -0,0 +1,75 @@
# Tenant isolation for `osint` (audit finding F3 / A5-1, card t_fed52919).
#
# `default-deny` (stock NetworkPolicy, podSelector {}, both directions) makes
# every pod in this namespace reachable by nothing and able to reach nothing.
# `osint-allow` (CiliumNetworkPolicy) re-adds the traffic the workload actually
# uses, in both directions:
# ingress: the Cilium Gateway proxy (`reserved:ingress`) for
# osint.siriusdevops.com -> app:8000 / titiler:8000, plus node/health
# entities for kubelet probes.
# egress: cluster DNS, its own pods (app -> osint-db:5432, -> nats:4222,
# -> titiler:8000), and `world` — the ingester/news-scraper/
# news-summarizer fetch external news + Nominatim
# (nominatim.openstreetmap.org) + the Nous inference API, and
# camera-service reads RTSP cameras on the LAN.
#
# `world` in Cilium is everything outside the cluster (internet, LAN, VPN peers)
# but NOT other namespaces' pods and NOT the node IPs — so cross-namespace
# reachability and the internal WireGuard gateway ports stay closed.
#
# Deliberately absent:
# * kube-apiserver egress — no workload here calls the API; the audit's
# `SA token mounted` observation is a separate finding and denying the path
# does not depend on removing the token.
# * monitoring ingress — no PodMonitor/ServiceMonitor selects osint pods.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: osint
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
---
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: osint-allow
namespace: osint
spec:
description: >-
osint: gateway + kubelet ingress; egress to own namespace, cluster DNS and
the public internet only.
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: osint
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: osint
# Internet / LAN / VPN peers: news sources, Nominatim, inference API, RTSP.
- toEntities:
- world

View file

@ -7,6 +7,8 @@ resources:
- service.yaml
- service-api.yaml
- httproute.yaml
# Default-deny ingress+egress + the namespace allow list (audit F3 / t_fed52919).
- networkpolicy.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,63 @@
# Tenant isolation for `piedmont` (audit finding F3 / A5-1, card t_fed52919).
#
# `default-deny` (stock NetworkPolicy, podSelector {}, both directions) is the
# deny. `piedmont-allow` (CiliumNetworkPolicy) re-adds:
# ingress: the Cilium Gateway proxy (`reserved:ingress`) for
# piedmonthomesvc.com -> site:80 / contact:8090, plus node/health
# entities for kubelet probes.
# egress: cluster DNS; its own pods (nginx may proxy /api/contact in-namespace);
# and `world` for the Telegram Bot API used by piedmont-contact.
#
# `world` is everything outside the cluster (internet, LAN, VPN peers) but not
# other namespaces' pods and not node IPs, so the tenant boundary holds.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: piedmont
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
---
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: piedmont-allow
namespace: piedmont
spec:
description: >-
piedmont: gateway + kubelet ingress; egress to own namespace, cluster DNS
and the public internet only.
endpointSelector: {}
ingress:
- fromEntities:
- ingress
- host
- remote-node
- health
# Intra-namespace: nginx -> contact (and any future pod -> pod call). Cilium
# enforces policy at BOTH ends, so the same-namespace allow must exist in
# ingress as well as egress — measured: with only the egress rule, a pod in
# this namespace could not reach its own Service (TimeoutError).
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: piedmont
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: piedmont
# Telegram Bot API (contact form delivery).
- toEntities:
- world

View file

@ -14,6 +14,8 @@ resources:
- service-blog.yaml
- service-portal-gate.yaml
- httproute.yaml
# Default-deny ingress+egress + the namespace allow list (audit F3 / t_fed52919).
- networkpolicy.yaml
# The WAL archive store must exist before the Cluster references it.
- objectstore-portal-wal.yaml
- cluster.yaml

View file

@ -0,0 +1,105 @@
# 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, and Prometheus in `monitoring` on 9187 only (the
# `cnpg-portal` PodMonitor scrapes the CNPG instance manager).
# 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
# 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

View file

@ -7,7 +7,9 @@ resources:
- service-site.yaml
- service-api.yaml
- httproute.yaml
- networkpolicy-site-egress.yaml
# Replaces the egress-only `siriusdevops-site-egress` CNP: same Garage +
# DNS allow, plus a namespace-wide default-deny and ingress rules (F3).
- networkpolicy.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

@ -1,70 +0,0 @@
# Egress policy for the public site pod — the first policy in this namespace
# (there were zero before 2026-11-19, so every pod could reach every WireGuard
# address).
#
# What it is for: `siriusdevops-site` runs an initContainer that pulls owner
# media out of the private Garage bucket over the mesh
# (http://10.10.0.1:3900). Nothing else about that pod needs to talk to the
# WireGuard network, and the pod is internet-facing, so it is the right first
# pod to fence off.
#
# WHY A CiliumNetworkPolicy AND NOT A networking.k8s.io NetworkPolicy:
# 10.10.0.1 is a CLUSTER NODE (rpi, the WireGuard hub), not a bare address.
# Cilium resolves it to `reserved:remote-node` (identity 6) in its ipcache
# (`cilium-dbg bpf ipcache list | grep 10.10.0.1` -> identity=6), and `ipBlock`
# / toCIDR rules are only evaluated for `reserved:world`. A standard
# NetworkPolicy with `ipBlock: 10.10.0.1/32` is silently inert here — measured:
# the pod's request to 10.10.0.1:3900 timed out exactly like the denied ports,
# while Prometheus (unrestricted namespace) scraped the same host fine.
#
# The narrower `toNodes: [{matchLabels: {kubernetes.io/hostname: rpi}}]` form
# would name the node exactly, but the agent rejects it unless Cilium runs with
# `enable-node-selector-labels: true` — status: "FromNodes/ToNodes rules can
# only be applied when the \"enable-node-selector-labels\" flag is set". Rather
# than change a cluster-wide Cilium flag for one policy, this uses the
# `remote-node` entity: any cluster node, TCP 3900 only. Every cluster node is
# on the WireGuard overlay, so this still cannot reach the LAN or the public
# internet, and the port scope is what makes the denial test meaningful.
#
# Scope: Egress only, one pod selector. Other pods in siriusdevops (and every
# other namespace) remain unrestricted — this proves the pattern, it is not
# namespace segregation. Ingress is untouched: the Cilium Gateway must still be
# able to reach nginx on :80.
#
# The policy is a whitelist: once it selects a pod, ALL egress from that pod is
# denied except what is listed. Two allowances:
# 1. TCP 3900 to a cluster node — Garage's S3 API on 10.10.0.1. Deliberately
# port-scoped: 10.10.0.1 also serves the container registry on 5000, and
# that stays unreachable from this pod.
# 2. Cluster DNS. Nothing in this pod resolves names today (the S3 endpoint
# is a literal IP); the rule costs one line and removes the trap of
# breaking name resolution in a pod that later grows a container.
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: siriusdevops-site-egress
namespace: siriusdevops
spec:
endpointSelector:
matchLabels:
app: siriusdevops-site
egress:
# Garage S3 API, on a WireGuard-overlay node, port 3900 only.
- toEntities:
- remote-node
toPorts:
- ports:
- port: "3900"
protocol: TCP
# 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

View file

@ -0,0 +1,88 @@
# Tenant isolation for `siriusdevops` (audit finding F3 / A5-1, card t_fed52919).
#
# Replaces the egress-only `siriusdevops-site-egress` CiliumNetworkPolicy. That
# policy proved the mechanism but restricted one pod in one direction; this file
# adds the namespace-wide deny and keeps the two allow rules that measurement
# established:
#
# WHY THE GARAGE RULE IS `remote-node` AND NOT `ipBlock`:
# 10.10.0.1 is a CLUSTER NODE (rpi, the WireGuard hub), not a bare address.
# Cilium resolves it to `reserved:remote-node` (identity 6) in its ipcache
# (`cilium-dbg bpf ipcache list | grep 10.10.0.1` -> identity=6), and
# `ipBlock`/toCIDR rules are only evaluated for `reserved:world`. A standard
# NetworkPolicy with `ipBlock: 10.10.0.1/32` is silently inert here — measured:
# the pod's request to 10.10.0.1:3900 timed out exactly like the denied ports,
# while Prometheus (unrestricted namespace) scraped the same host fine.
# `toNodes` would name the node exactly but needs Cilium's
# `enable-node-selector-labels` flag; the port-scoped `remote-node` entity gives
# the same reach (any cluster node is on the WireGuard overlay, TCP 3900 only)
# without a cluster-wide flag change.
#
# `default-deny` (stock NetworkPolicy, podSelector {}, both directions) is the
# deny. `siriusdevops-allow` (CiliumNetworkPolicy) re-adds:
# ingress: Cilium Gateway proxy (`reserved:ingress`) for siriusdevops.com ->
# site:80 / contact:8090, plus node/health entities for kubelet probes.
# egress: cluster DNS; its own pods; `world` for the Telegram Bot API used by
# siriusdevops-contact; node IPs on 3900 for the media pull the site
# runs in its initContainer (Garage S3, http://10.10.0.1:3900).
#
# Port 5000 (the container registry on the same node) stays unreachable from
# these pods, exactly as before.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: siriusdevops
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
---
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: siriusdevops-allow
namespace: siriusdevops
spec:
description: >-
siriusdevops: gateway + kubelet ingress; egress to own namespace, cluster
DNS, the internet and Garage on node IPs (TCP 3900) only.
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: siriusdevops
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: siriusdevops
# Telegram Bot API (contact form delivery).
- toEntities:
- world
# Garage S3 API, on a WireGuard-overlay node, port 3900 only.
- toEntities:
- remote-node
toPorts:
- ports:
- port: "3900"
protocol: TCP

94
docs/network-isolation.md Normal file
View file

@ -0,0 +1,94 @@
# Namespace network isolation
**State since 2026-11-27 (audit finding F3 / A5-1, card `t_fed52919`).** Before that the cluster
was one flat L2/L3 domain: a pod in any namespace could reach every other namespace's services, the
API server, the internal Gateway ports on `10.10.0.2` (`:8081` Grafana, `:8084` Hubble,
`:8085` Metabase, `:8086/:8087` customer1) and the internet.
## What is covered
Each app namespace carries two objects in `apps/base/<ns>/networkpolicy.yaml`,
applied by the `apps` Flux Kustomization:
| namespace | default-deny | allow policy | internet egress | Garage/S3 | CI/backup SSH | API |
|---|---|---|---|---|---|---|
| `customer1` | yes | `customer1-allow` | **no** (by design) | no | no | no |
| `osint` | yes | `osint-allow` | yes | no | no | no |
| `sirius-growth` | yes | `sirius-growth-allow` | yes | 3900 | 22 | yes |
| `piedmont` | yes | `piedmont-allow` | yes | no | no | no |
| `siriusdevops` | yes | `siriusdevops-allow` | yes | 3900 | no | no |
| `forgejo` | yes | `forgejo-allow` | yes | no | 22 | yes |
`customer1` also carries `quota.yaml`: a `ResourceQuota` + `LimitRange` sized from the declared
1-replica shape of the parked sandbox (2 CPU / 4Gi requests, 4 CPU / 10Gi limits, 45Gi storage,
`max` 1 CPU / 2Gi per container). See the comments in that file for the arithmetic.
`metabase`, `monitoring`, `logging`, `kube-system`, `ci-runners`, `netsec` and `secops` are **not**
isolated yet — they are the next tier (monitoring/logging legitimately reach everything).
## How the deny is expressed
* **Deny**: `networking.k8s.io/v1 NetworkPolicy` named `default-deny`,
`podSelector: {}`, `policyTypes: [Ingress, Egress]`, no rules. A stock NetworkPolicy is
unambiguous in Cilium's k8s-policy path, and unlike a `CiliumClusterwideNetworkPolicy` with
`endpointSelector: {}` it cannot silently select `kube-system`/CoreDNS/Flux.
* **Allow**: `CiliumNetworkPolicy` per namespace with `endpointSelector: {}`. Cilium *unions* all
policies that select an endpoint, so deny + allow = the effective policy. The Cilium CRD is needed
because the permitted sources/destinations are Cilium **entities**.
## The five rules every namespace needs
```yaml
ingress:
- fromEntities: [ingress, host, remote-node, health] # Gateway proxy + kubelet + cilium-health
- fromEndpoints: # INTRA-NAMESPACE, see below
- matchLabels: {io.kubernetes.pod.namespace: <ns>}
egress:
- toEndpoints: kube-dns :53 (UDP+TCP)
- toEndpoints: own namespace
- toEntities: [world] # internet + LAN + VPN peers, NOT pods/nodes
```
Entities that matter here:
| entity | what it is | why it appears |
|---|---|---|
| `ingress` | Cilium Gateway/listener proxy | **measured**: `hubble observe --to-namespace forgejo --to-port 3000` shows the source identity as `reserved:ingress` (identity 8), not `host`. Traffic arrives via cloudflared → hostNetwork Envoy → pod. |
| `host` | the local node IP | kubelet probes and host-network datapath |
| `remote-node` | other nodes' IPs | cross-node gateway ingress; Garage (`10.10.0.1`, `10.10.0.5`) and the Linode SSH target live here, **not** in `world` |
| `kube-apiserver` | the apiserver identity | attached to the **whole node IP** `10.10.0.2` because apiserver is host-networked — always port-scope it (see below) |
| `health` | cilium-health | inter-node health probes |
## Gotchas that cost time (all measured 2026-11-27)
1. **Cilium enforces at both ends.** An egress rule alone does not let a pod reach its own
Service: the destination pod's ingress policy must allow it too. Symptom: a probe pod in the
namespace gets `TimeoutError` on `own-service.<ns>.svc:5432` while the public route works fine
(that one enters as `ingress`). Add the same-namespace `fromEndpoints` ingress rule as well.
Confirmed by re-running the probe after adding it: `OPEN`.
2. **`toEntities: [kube-apiserver]` without `toPorts` opens the whole gateway node.** The apiserver
is host-networked on `10.10.0.2`, and Cilium attaches the `kube-apiserver` identity to that IP,
so an unscoped rule also allowed `:8085`, `:8081`, `:9100`, `:10250`. Measured, then fixed with
`toPorts: [6443, 443]` (443 = the service port the CNPG instance manager / `kubectl` dial;
6443 = the backend port). Re-probe: `apiserver OPEN`, `:8085/:8081/:9100/:10250 CLOSED`.
3. **`ipBlock`/`toCIDR` is inert for node IPs.** `10.10.0.1` (Garage on the Pi) resolves to
`reserved:remote-node`, and CIDR rules are only evaluated for `reserved:world`. Use
`toEntities: [remote-node]` + `toPorts`.
4. **`world` is not "the internet".** It is everything outside the cluster: public IPs **and** the
LAN (`192.168.1.0/24`) and VPN peers. Cluster pods and node IPs are *not* in `world`, which is
what makes `toEntities: [world]` a safe "internet only" rule.
5. **A deny shows up as `TimeoutError`, an empty Service as `ConnectionRefusedError`.** Useful when
reading probes: `pg.customer1.svc:5432` refusing proves the policy *permits* the path and the
namespace is simply parked at 0 replicas.
## Adding a dependency
1. Add the rule to that namespace's allow policy — DNS, same-namespace and the entity list are
already there; most additions are one `toEntities`/`toPorts` block.
2. Prove it both ways: the new path must go `OPEN`, and `forgejo:3000`, `metabase:3000`,
`grafana:80`, `kubernetes.default:443` (where not needed) and `10.10.0.2:8085` must stay
`CLOSED` from that namespace.
3. Watch the deny side while you test: `hubble observe --verdict DROPPED -o compact` on the
namespace you changed (`policy-verdict:...DENIED` lines name the exact port).
4. Push through a PR; Flux owns the objects. A `kubectl apply` is only for testing and will be
adopted by the next reconcile.