`forgejo-allow` claimed no cross-namespace rule was needed because the CI runners in `ci-runners` "register/poll over the public URL and therefore arrive as reserved:ingress". That holds for registration only. Every image-building workflow pushes to the in-cluster ClusterIP (`PUSH_REGISTRY: forgejo.forgejo.svc.cluster.local:3000`) from the dind sidecar of the runner pod — pod->pod, which `default-deny` dropped, so every build since the policy landed (2026-11-27 07:13Z) died at `Get "http://forgejo.forgejo.svc.cluster.local:3000/v2/": request canceled ... Client.Timeout exceeded`. Add one port-scoped ingress rule: fromEndpoints `io.kubernetes.pod.namespace: ci-runners` -> 3000/TCP (runner container and its dind sidecar share the pod identity, so a single namespace selector covers both). Nothing else in `forgejo` is widened. Rewrite the stale comment paragraph so the next isolation audit does not re-remove it.
143 lines
6.1 KiB
YAML
143 lines
6.1 KiB
YAML
# 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 in
|
|
# `ci-runners` on 3000 only (they register/poll over the PUBLIC URL,
|
|
# so THAT traffic arrives as `reserved:ingress` — but their image
|
|
# pushes go pod->pod to the internal ClusterIP
|
|
# `forgejo.forgejo.svc.cluster.local:3000`
|
|
# (`PUSH_REGISTRY` in each repo's `.forgejo/workflows/build.yml`,
|
|
# docker daemon in the dind sidecar of the runner pod). Pod->pod is
|
|
# not `reserved:ingress`, so `default-deny` dropped it and every
|
|
# image build failed 2026-11-27 .. 2026-12-05 with
|
|
# `Get "http://forgejo.forgejo.svc.cluster.local:3000/v2/": request
|
|
# canceled ... Client.Timeout exceeded` — the cross-namespace rule IS
|
|
# required; do not delete it as redundant. 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
|
|
# [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`); `forgejo-allow` only grants them
|
|
# forgejo:3000, which is the registry push path the builds depend on.
|
|
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 + ci-runners registry-push 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
|
|
# CI runners (`ci-runners`) push images to the in-cluster registry at
|
|
# forgejo.forgejo.svc.cluster.local:3000 (PUSH_REGISTRY in each repo's
|
|
# build workflow; the docker daemon lives in the dind sidecar of the same
|
|
# pod, so one namespace selector covers runner + sidecar). Registration and
|
|
# polling use the public URL and arrive as `reserved:ingress`, but the push
|
|
# is pod -> pod and default-deny drops it without this rule. Port-scoped on
|
|
# purpose: the registry API only, nothing else in the namespace.
|
|
- fromEndpoints:
|
|
- matchLabels:
|
|
io.kubernetes.pod.namespace: ci-runners
|
|
toPorts:
|
|
- ports:
|
|
- port: "3000"
|
|
protocol: TCP
|
|
# 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 [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
|