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:
parent
e5a0460e53
commit
69b003705c
15 changed files with 701 additions and 71 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
88
apps/base/siriusdevops/networkpolicy.yaml
Normal file
88
apps/base/siriusdevops/networkpolicy.yaml
Normal 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
|
||||
Loading…
Reference in a new issue