feat(backup): run the three nightly backups from a pinned image with an egress allow list

monitoring/grafana-backup, forgejo/cluster-backup and sirius-growth/leadgen-backup
all ran `apk add --no-cache rsync openssh-client` at container start. Every night
that dialled dl-cdn.alpinelinux.org (Fastly anycast 151.101.x.132:443), which is
what `egress-new-dst` kept reporting, and made the backups depend on the public
internet at 03:00 UTC.

- image: forgejo.siriusdevops.com/sirius/backup-tools, built in CI from
  python:3.12-alpine (pinned by digest) + rsync + openssh-client + bash +
  kubectl v1.36.4 (release sha256 verified at build). Pinned by digest in all
  three CronJobs, no apk in any backup path.
- egress: CiliumNetworkPolicy per backup pod — cluster DNS and 10.10.0.5:22 for
  all three, plus kube-apiserver 6443/443 for cluster-backup only, with an
  explicit deny for `world` (Cilium unions namespace policies, so the allow list
  alone would not restrict a pod inside `forgejo`/`sirius-growth`).
- monitoring gains the registry pull secret it never needed before; the job now
  keeps imagePullSecrets: forgejo-pull (SOPS-encrypted in git).

Schedules, retention, destination paths, entrypoints and RBAC are unchanged.
This commit is contained in:
devops 2026-12-04 00:20:34 -05:00
commit 0acc089dc3
10 changed files with 242 additions and 22 deletions

View file

@ -87,12 +87,10 @@ data:
# (the node runs close to DiskPressure and `local-path` lives on it).
set -euo pipefail
# alpine/k8s ships kubectl/bash but not rsync/ssh; install them per run
# (~2 s). Nothing else is needed: the DB dumps run inside the CNPG pod.
if ! command -v rsync >/dev/null || ! command -v ssh >/dev/null; then
echo "== installing rsync + openssh-client"
apk add --no-cache rsync openssh-client >/dev/null
fi
# No package install here on purpose: rsync/openssh-client/bash/kubectl are
# baked into the pinned image (images/backup/Dockerfile) and this pod's
# egress policy admits DNS, 10.10.0.5:22 and the API only, so a runtime
# fetch would fail rather than silently dial the Alpine CDN (t_9d0428d8).
BACKUP_HOST=${BACKUP_HOST:[email protected]}
BACKUP_DIR=${BACKUP_DIR:-/root/cluster-backup}
@ -246,16 +244,20 @@ spec:
spec:
restartPolicy: Never
serviceAccountName: cluster-backup
# Pulled from the in-cluster Forgejo registry (which requires auth).
imagePullSecrets:
- name: forgejo-pull
# The forgejo-data PVC is local-path on siriussec; the pod must run
# where the volume is.
nodeSelector:
kubernetes.io/hostname: siriussec
containers:
- name: backup
# alpine/k8s carries kubectl 1.36.4 (== cluster version) so the
# CNPG dumps can be taken through the exec API; rsync + openssh
# are added at start (the pod has normal egress).
image: alpine/k8s:1.36.4
# python3.12-alpine + rsync + openssh-client + bash + kubectl
# v1.36.4 (== cluster version, so the CNPG dumps can be taken
# through the exec API), all baked at build time and pinned by
# digest. Nothing is installed at run time.
image: forgejo.siriusdevops.com/sirius/backup-tools@sha256:cc8dc1645111b3a80b7c4d5168f6bce3002cae7417b3725683c057976f6e379a
imagePullPolicy: IfNotPresent
command: ["/bin/bash", "/scripts/backup.sh"]
env:

View file

@ -8,6 +8,10 @@ resources:
- httproute.yaml
# Default-deny ingress+egress + the namespace allow list (audit F3 / t_fed52919).
- networkpolicy.yaml
# Egress lockdown for the cluster-backup pod: DNS + 10.10.0.5:22 + the API
# only. The allow list above cannot be narrowed per pod, so the deny for
# `world` in this policy is what applies to the job (card t_9d0428d8).
- networkpolicy-backup.yaml
- pvc.yaml
- cluster.yaml
- podmonitor.yaml

View file

@ -0,0 +1,64 @@
# 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

View file

@ -16,6 +16,10 @@ resources:
- httproute.yaml
# Default-deny ingress+egress + the namespace allow list (audit F3 / t_fed52919).
- networkpolicy.yaml
# Egress lockdown for the leadgen-backup pod: DNS + 10.10.0.5:22 only. The
# allow list above cannot be narrowed per pod, so the deny for `world` in
# this policy is what applies to the job (card t_9d0428d8).
- networkpolicy-backup.yaml
# The WAL archive store must exist before the Cluster references it.
- objectstore-portal-wal.yaml
- cluster.yaml

View file

@ -20,10 +20,10 @@ data:
# Snapshot mirror of /src -> $BACKUP_DIR/leadgen-data/<stamp>/ + `latest`.
set -euo pipefail
if ! command -v rsync >/dev/null || ! command -v ssh >/dev/null; then
echo "== installing rsync + openssh-client"
apk add --no-cache rsync openssh-client >/dev/null
fi
# No package install here on purpose: rsync/openssh-client/bash are baked
# into the pinned image (images/backup/Dockerfile) and this pod's egress
# policy admits DNS + 10.10.0.5:22 only, so a runtime fetch would fail
# rather than silently dial the Alpine CDN (card t_9d0428d8).
BACKUP_HOST=${BACKUP_HOST:[email protected]}
BACKUP_DIR=${BACKUP_DIR:-/root/cluster-backup}
@ -102,12 +102,18 @@ spec:
app: leadgen-backup
spec:
restartPolicy: Never
# Pulled from the in-cluster Forgejo registry (which requires auth).
imagePullSecrets:
- name: forgejo-pull
# The PVC is local-path on siriussec.
nodeSelector:
kubernetes.io/hostname: siriussec
containers:
- name: backup
image: alpine/k8s:1.36.4
# rsync + openssh-client + bash baked at build time, pinned by
# digest (images/backup/Dockerfile). Nothing is installed at run
# time.
image: forgejo.siriusdevops.com/sirius/backup-tools@sha256:cc8dc1645111b3a80b7c4d5168f6bce3002cae7417b3725683c057976f6e379a
imagePullPolicy: IfNotPresent
command: ["/bin/bash", "/scripts/backup.sh"]
env:

View file

@ -0,0 +1,49 @@
# Egress lockdown for the nightly leadgen-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).
# rsync/ssh/bash (+kubectl, unused here) are baked into
# images/backup/Dockerfile now.
#
# `sirius-growth-allow` (networkpolicy.yaml) selects every pod in this
# namespace and allows `world` (Telegram Bot API, the leadgen crawlers), so a
# pod-scoped allow list alone would NOT restrict this job — Cilium unions
# policies. The `egressDeny` for `world` closes it for this pod only; the app
# pods keep their internet access.
#
# Allow list, and nothing else: cluster DNS, and [email protected]:22 (the Linode
# node's InternalIP — `remote-node`, not `world`) for the rsync mirror.
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: leadgen-backup-egress
namespace: sirius-growth
labels:
app: leadgen-backup
spec:
description: >-
leadgen-backup pod: cluster DNS + SSH to the backup host (10.10.0.5:22)
only; no internet egress at run time.
endpointSelector:
matchLabels:
app: leadgen-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
egressDeny:
- toEntities:
- world