homek8s/monitoring/controllers/home/grafana-backup-networkpolicy.yaml
devops 0acc089dc3 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.
2026-12-04 00:20:34 -05:00

54 lines
2 KiB
YAML

# Egress lockdown for the nightly Grafana sqlite snapshot (card t_9d0428d8).
#
# Why: grafana-backup used to run `apk add --no-cache rsync openssh-client` at
# container start, so every night it dialled the Alpine CDN
# (dl-cdn.alpinelinux.org -> Fastly 151.101.x.132:443) and kept firing the
# `egress-new-dst` flow alert whenever that anycast address rotated. The
# toolchain is now baked into the image (images/backup/Dockerfile) and this
# policy makes any future runtime fetch fail loudly instead of silently
# reaching the internet.
#
# `monitoring` has no namespace-wide default-deny, so selecting the backup pod
# here isolates it on its own: the rules below are the complete egress allow
# list and everything else (including `world`) is dropped. `egressDeny` is
# stated explicitly so the intent survives a future namespace-wide allow being
# added — Cilium deny always beats allow.
#
# Needs: cluster DNS (the script resolves nothing itself, but the image and any
# `ssh` target lookup would), and [email protected]:22 — that is the Linode node's
# InternalIP, so Cilium classifies it `remote-node`, not `world`. The registry
# pull and the Grafana PVC access are not pod traffic and are unaffected.
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: grafana-backup-egress
namespace: monitoring
labels:
app: grafana-backup
spec:
description: >-
grafana-backup pod: cluster DNS + SSH to the backup host (10.10.0.5:22)
only; no internet egress at run time.
endpointSelector:
matchLabels:
app: grafana-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