# 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), and the # CNPG operator in `cnpg-system` on 8000 only — the instance # manager's HTTPS status endpoint the operator reads to derive the # system ID and drive failover (card t_4210edec). # 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 # root@10.10.0.5; 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 # The CNPG operator (`cnpg-system`) reads the instance manager's HTTPS # status endpoint to derive the system ID and drive switchover/promotion. # Without it the Cluster reports `Instance Status Extraction Error` and # Ready=False while the pods serve traffic, and automated failover is dead # (card t_4210edec). Scoped to 8000: not 5432, not the whole namespace. - fromEndpoints: - matchLabels: io.kubernetes.pod.namespace: cnpg-system app.kubernetes.io/name: cloudnative-pg toPorts: - ports: - port: "8000" protocol: TCP # 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 root@10.10.0.5 (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