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
Owner

Finding

Audit F3 / A5-1 (card t_fed52919): the cluster had no network isolation. A pod in any namespace
reached every other namespace's services, the API server, the internal WireGuard-only Gateway ports
on 10.10.0.2 and the internet. customer1 had no NetworkPolicy, no ResourceQuota and no
LimitRange.

What this PR does

  • default-deny in customer1, osint, sirius-growth, piedmont, siriusdevops, forgejo:
    a stock networking.k8s.io/v1 NetworkPolicy with podSelector: {} and
    policyTypes: [Ingress, Egress], no rules. Chosen over a CiliumClusterwideNetworkPolicy with
    endpointSelector: {} because a CCNP would also select kube-system, CoreDNS and Flux and would
    need dozens of allows before the cluster worked again.
  • <ns>-allow CiliumNetworkPolicy per namespace: gateway/kubelet/health entities,
    same-namespace pods, cluster DNS, then only the egress the workload uses —
    world (Telegram / news / Nominatim / inference API / LAN cameras), remote-node on :3900
    (Garage) and :22 (backup rsync), kube-apiserver on :6443/:443 for CNPG + cluster-backup.
    customer1 gets no internet and no API egress.
  • siriusdevops-site-egress (egress-only, one pod) is replaced by the namespace policy; its
    measurement notes about remote-node vs ipBlock are preserved in the new file.
  • customer1 quota.yaml: ResourceQuota + LimitRange sized from the declared 1-replica shape
    (35Gi already bound; 2 CPU / 4Gi requests, 4 CPU / 10Gi limits, 45Gi storage, 1 CPU / 2Gi per
    container). The sandbox stays parked — the card forbids scaling it up.
  • docs/network-isolation.md: the model, the per-namespace matrix, and the five gotchas that
    cost time while landing this (Cilium enforces at both ends; kube-apiserver identity covers the
    whole node IP so it must be port-scoped; ipBlock is inert for node IPs; world excludes nodes
    and pods; TimeoutError vs ConnectionRefusedError).

Evidence (live, 2026-11-27)

Before, from an osint pod (the audit's probe) and from a customer1 probe pod — every target OPEN:

  OPEN   cross-ns-forgejo       forgejo.forgejo.svc.cluster.local:3000
  OPEN   cross-ns-metabase      metabase.metabase.svc.cluster.local:3000
  OPEN   same-ns-db             osint-db:5432
  OPEN   cross-ns-grafana       kube-prometheus-stack-grafana.monitoring.svc.cluster.local:80
  OPEN   apiserver              kubernetes.default.svc:443
  OPEN   internal-gw-8085       10.10.0.2:8085
  OPEN   internet               1.1.1.1:443

After, from a customer1 pod:

  CLOSED cross-ns-forgejo       forgejo.forgejo.svc.cluster.local:3000   (TimeoutError)
  CLOSED cross-ns-metabase      metabase.metabase.svc.cluster.local:3000 (TimeoutError)
  CLOSED same-ns-pg             pg.customer1.svc.cluster.local:5432      (ConnectionRefusedError)
  CLOSED cross-ns-grafana       kube-prometheus-stack-grafana.monitoring.svc.cluster.local:80 (TimeoutError)
  CLOSED apiserver              kubernetes.default.svc:443              (TimeoutError)
  CLOSED internal-gw-8085       10.10.0.2:8085                          (TimeoutError)
  CLOSED internet               1.1.1.1:443                             (TimeoutError)
  OPEN   cluster-dns-tcp        kube-dns.kube-system.svc.cluster.local:53

same-ns-pg refuses rather than times out because the policy permits the path and the tenant is
parked at 0 replicas; proven separately with a listener pod + client pod in customer1
(OPEN same-ns-pod-to-pod 10.244.0.119:5432 payload=b'ok').

Per-namespace probes (piedmont, osint, sirius-growth, siriusdevops, forgejo) confirm own-namespace
pods are OPEN, cross-namespace forgejo:3000 / grafana:80 / metabase:3000 are CLOSED, the
internal Gateway ports are CLOSED, and only the needed egress is OPEN:

  • osint: internet OPEN, Garage/SSH/API CLOSED.
  • sirius-growth: Garage 10.10.0.1:3900 + 10.10.0.5:3900, SSH 10.10.0.5:22, API OPEN; 8085/8081/
    9100/10250 CLOSED.
  • forgejo: own pg + API + SSH + internet OPEN; 8085/8081/9100/10250 CLOSED.
  • siriusdevops: Garage 3900 OPEN; everything cross-namespace CLOSED.
  • piedmont: Telegram OPEN; Garage/SSH CLOSED.

Public routes all still serve (curl from the laptop): siriusdevops.com 200 / www 200 /
/api/contact 405, siriusgrowthsolutions.com 200 / www 301 / /api/contact 405,
piedmonthomesvc.com 200 / www 200 / /api/contact 405, forgejo.siriusdevops.com 200,
osint.siriusdevops.com 200 — identical to the pre-change codes.

No pod restarted after the change; Prometheus still scrapes both CNPG instances
(up{namespace="forgejo"} = 1, cnpg_collector_up 20s fresh); the deploy runner re-declared over
the public URL at 07:15:52Z.

Quota enforcement (server dry-run): maximum memory usage per Container is 2Gi, but limit is 4Gi
and exceeded quota: customer1-quota, requested: requests.cpu=3, used: requests.cpu=0, limited: requests.cpu=2.

Out of scope (next tier): metabase, monitoring, logging, kube-system, ci-runners,
netsec, secops are still unrestricted.

## Finding Audit F3 / A5-1 (card `t_fed52919`): the cluster had no network isolation. A pod in any namespace reached every other namespace's services, the API server, the internal WireGuard-only Gateway ports on `10.10.0.2` and the internet. `customer1` had no NetworkPolicy, no ResourceQuota and no LimitRange. ## What this PR does * **`default-deny`** in `customer1`, `osint`, `sirius-growth`, `piedmont`, `siriusdevops`, `forgejo`: a stock `networking.k8s.io/v1 NetworkPolicy` with `podSelector: {}` and `policyTypes: [Ingress, Egress]`, no rules. Chosen over a CiliumClusterwideNetworkPolicy with `endpointSelector: {}` because a CCNP would also select `kube-system`, CoreDNS and Flux and would need dozens of allows before the cluster worked again. * **`<ns>-allow`** CiliumNetworkPolicy per namespace: gateway/kubelet/health entities, same-namespace pods, cluster DNS, then only the egress the workload uses — `world` (Telegram / news / Nominatim / inference API / LAN cameras), `remote-node` on `:3900` (Garage) and `:22` (backup rsync), `kube-apiserver` on `:6443/:443` for CNPG + `cluster-backup`. `customer1` gets **no** internet and **no** API egress. * **`siriusdevops-site-egress`** (egress-only, one pod) is replaced by the namespace policy; its measurement notes about `remote-node` vs `ipBlock` are preserved in the new file. * **`customer1` quota.yaml**: ResourceQuota + LimitRange sized from the declared 1-replica shape (35Gi already bound; 2 CPU / 4Gi requests, 4 CPU / 10Gi limits, 45Gi storage, 1 CPU / 2Gi per container). The sandbox stays parked — the card forbids scaling it up. * **`docs/network-isolation.md`**: the model, the per-namespace matrix, and the five gotchas that cost time while landing this (Cilium enforces at both ends; `kube-apiserver` identity covers the whole node IP so it must be port-scoped; `ipBlock` is inert for node IPs; `world` excludes nodes and pods; TimeoutError vs ConnectionRefusedError). ## Evidence (live, 2026-11-27) Before, from an `osint` pod (the audit's probe) and from a `customer1` probe pod — every target OPEN: ``` OPEN cross-ns-forgejo forgejo.forgejo.svc.cluster.local:3000 OPEN cross-ns-metabase metabase.metabase.svc.cluster.local:3000 OPEN same-ns-db osint-db:5432 OPEN cross-ns-grafana kube-prometheus-stack-grafana.monitoring.svc.cluster.local:80 OPEN apiserver kubernetes.default.svc:443 OPEN internal-gw-8085 10.10.0.2:8085 OPEN internet 1.1.1.1:443 ``` After, from a `customer1` pod: ``` CLOSED cross-ns-forgejo forgejo.forgejo.svc.cluster.local:3000 (TimeoutError) CLOSED cross-ns-metabase metabase.metabase.svc.cluster.local:3000 (TimeoutError) CLOSED same-ns-pg pg.customer1.svc.cluster.local:5432 (ConnectionRefusedError) CLOSED cross-ns-grafana kube-prometheus-stack-grafana.monitoring.svc.cluster.local:80 (TimeoutError) CLOSED apiserver kubernetes.default.svc:443 (TimeoutError) CLOSED internal-gw-8085 10.10.0.2:8085 (TimeoutError) CLOSED internet 1.1.1.1:443 (TimeoutError) OPEN cluster-dns-tcp kube-dns.kube-system.svc.cluster.local:53 ``` `same-ns-pg` refuses rather than times out because the policy permits the path and the tenant is parked at 0 replicas; proven separately with a listener pod + client pod in `customer1` (`OPEN same-ns-pod-to-pod 10.244.0.119:5432 payload=b'ok'`). Per-namespace probes (piedmont, osint, sirius-growth, siriusdevops, forgejo) confirm own-namespace pods are `OPEN`, cross-namespace `forgejo:3000` / `grafana:80` / `metabase:3000` are `CLOSED`, the internal Gateway ports are `CLOSED`, and only the needed egress is `OPEN`: * `osint`: internet OPEN, Garage/SSH/API CLOSED. * `sirius-growth`: Garage `10.10.0.1:3900` + `10.10.0.5:3900`, SSH `10.10.0.5:22`, API OPEN; 8085/8081/ 9100/10250 CLOSED. * `forgejo`: own pg + API + SSH + internet OPEN; 8085/8081/9100/10250 CLOSED. * `siriusdevops`: Garage 3900 OPEN; everything cross-namespace CLOSED. * `piedmont`: Telegram OPEN; Garage/SSH CLOSED. Public routes all still serve (`curl` from the laptop): siriusdevops.com 200 / www 200 / `/api/contact` 405, siriusgrowthsolutions.com 200 / www 301 / `/api/contact` 405, piedmonthomesvc.com 200 / www 200 / `/api/contact` 405, forgejo.siriusdevops.com 200, osint.siriusdevops.com 200 — identical to the pre-change codes. No pod restarted after the change; Prometheus still scrapes both CNPG instances (`up{namespace="forgejo"} = 1`, `cnpg_collector_up` 20s fresh); the deploy runner re-declared over the public URL at 07:15:52Z. Quota enforcement (server dry-run): `maximum memory usage per Container is 2Gi, but limit is 4Gi` and `exceeded quota: customer1-quota, requested: requests.cpu=3, used: requests.cpu=0, limited: requests.cpu=2`. Out of scope (next tier): `metabase`, `monitoring`, `logging`, `kube-system`, `ci-runners`, `netsec`, `secops` are still unrestricted.
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)
sirius merged commit d7857f10ab into master 2026-11-27 07:19:43 +00:00
sirius deleted branch wt/t_fed52919 2026-11-27 07:19:43 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/homek8s!82
No description provided.