homek8s/apps/base/forgejo/networkpolicy-backup.yaml

64 lines
2.2 KiB
YAML
Raw Normal View History

# Egress lockdown for the nightly cluster-backup CronJob (card t_9d0428d8).
#
# Why: the job used to `apk add --no-cache rsync openssh-client` at container
# start, so each run depended on the Alpine CDN (Fastly 151.101.x.132:443) and
# tripped `egress-new-dst` whenever that anycast address rotated. rsync/ssh/
# bash/kubectl are baked into images/backup/Dockerfile now.
#
# `forgejo-allow` (networkpolicy.yaml) selects every pod in this namespace and
# allows `world`, so a pod-scoped allow list alone would NOT restrict the job —
# Cilium unions multiple policies. The `egressDeny` for `world` below is what
# actually closes it (deny always beats allow), and it is scoped to this pod by
# the endpointSelector, so Forgejo's own webhooks/mirror/avatar egress is
# untouched.
#
# Allow list, and nothing else:
# * cluster DNS;
# * [email protected]:22 — the Linode node's InternalIP, so `remote-node`, not
# `world` (the rsync target and every ssh_r call);
# * kube-apiserver on 6443/443 — `kubectl get cluster` for the CNPG primary
# and `kubectl exec ... pg_dump` for both CNPG and the plain Postgres
# Deployment. Port-scoped on purpose: the apiserver shares its host IP with
# the internal Gateway listeners on 8081/8084-8087.
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: cluster-backup-egress
namespace: forgejo
labels:
app: cluster-backup
spec:
description: >-
cluster-backup pod: cluster DNS, SSH to the backup host (10.10.0.5:22) and
the API (6443/443) only; no internet egress at run time.
endpointSelector:
matchLabels:
app: cluster-backup
egress:
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: kube-system
k8s-app: kube-dns
toPorts:
- ports:
- port: "53"
protocol: UDP
- port: "53"
protocol: TCP
- toEntities:
- remote-node
toPorts:
- ports:
- port: "22"
protocol: TCP
- toEntities:
- kube-apiserver
toPorts:
- ports:
- port: "6443"
protocol: TCP
- port: "443"
protocol: TCP
egressDeny:
- toEntities:
- world