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

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

View file

@ -27,10 +27,10 @@ data:
# T480's root filesystem, the only local file is a ~3 MB copy in /tmp.
set -eu
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/python3 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}
@ -128,15 +128,22 @@ spec:
app: grafana-backup
spec:
restartPolicy: Never
# Pulled from the in-cluster Forgejo registry (which requires auth);
# monitoring had no registry pull secret before this job needed one.
imagePullSecrets:
- name: forgejo-pull
# The grafana PVC is local-path on siriussec; RWO still allows a
# second pod on the same node.
nodeSelector:
kubernetes.io/hostname: siriussec
containers:
- name: backup
# python3 alpine: the sqlite backup API is the only consistent
# way to copy a live database without a shell inside Grafana.
image: python:3.12-alpine
# python3.12-alpine + rsync + openssh-client, baked at build time
# and pinned by digest (images/backup/Dockerfile, CI workflow
# .forgejo/workflows/backup-image.yml). The sqlite backup API is
# the only consistent way to copy a live database without a shell
# inside Grafana. Nothing is installed at run time.
image: forgejo.siriusdevops.com/sirius/backup-tools@sha256:cc8dc1645111b3a80b7c4d5168f6bce3002cae7417b3725683c057976f6e379a
imagePullPolicy: IfNotPresent
command: ["/bin/sh", "/scripts/backup.sh"]
env:

View file

@ -17,6 +17,9 @@ resources:
- rosenpass.yaml
# Nightly consistent sqlite snapshot of Grafana's dashboards/alerts/users.
- grafana-backup.yaml
# Egress lockdown for that backup pod: DNS + the backup host only, so no
# run-time package fetch (card t_9d0428d8).
- grafana-backup-networkpolicy.yaml
- dashboards
# Secrets, SOPS/age-encrypted in git (decrypted by the `monitoring`
# Kustomization; key = flux-system/sops-age). See docs/secrets-sops.md.
@ -24,6 +27,10 @@ resources:
- secret-grafana-secret-key.sops.yaml
- secret-alertmanager-telegram.sops.yaml
- secret-cluster-backup-ssh.sops.yaml
# Registry pull credential for this namespace. Added because grafana-backup
# now runs an image from the in-cluster Forgejo registry instead of
# python:3.12-alpine from Docker Hub (card t_9d0428d8).
- secret-forgejo-pull.sops.yaml
configMapGenerator:
- name: kube-prometheus-stack-values

View file

@ -0,0 +1,23 @@
apiVersion: v1
data:
.dockerconfigjson: ENC[AES256_GCM,data:c7NwYAKS00RAzkEW3z1IA2XP24cdIJgQAaBjg7+WcsxLMEs2h42cg/fdtW6UYrrsQtq7X/T4wgfpzUjHq8aMI2lyiVhJa9vxHknpK32i2mP63YQ7o2axI2p5eGPQpB+uuLPr3e1A6I939co6LQCBrY1ueK9+9atCcSEflv/wJyXwrwvlV5EL20PTLTM/y8gGN9cXXfgk6aYV7F5mowQCcUIUDvCbj7cHIonumMfCANQgGjQHrACf0+2ko853nBwLQK1AtIP+U/NS1wDSbFmxqyO6OstF10Sq5t+8dY8baIt73RWN0BqB/7i08TsMpnNUXH4XJcP6WhP0FM+X3M5goJr80DNy2uG3fxTHwRSAeWGzIo2GuuK9qlMtIjjnU97K,iv:xPgSzx6+EEJRnTGYG+QZWJ7G3MUf6Ajd+CXpl8+XIxs=,tag:alsSmEFhXW46SeoVzdqyFA==,type:str]
kind: Secret
metadata:
name: forgejo-pull
namespace: monitoring
type: kubernetes.io/dockerconfigjson
sops:
age:
- enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA1eU8ydkR5SmF2UG9ZQWNY
TWdKTFJkdjFlWWtBSW4wdmFDWXA0akNSSFI4CmVpL3dMKy91b1JTUTRyV1QyRXlI
YnlQZVJhL0hNRENNdlM1cDZKZmRUN0kKLS0tIEZOVHBLOUsvbFp6VjJXbW1tVmhK
Y1M4a2VyL0Z2MDhLeGJZUCtHRnQ2cmMKU9Q4m7ZuZDYbNQgsvOXEAKBE1hW1pa7m
7/pmRAP43OjXfsjWUbnPmORcHSrVDtRrBxQZ2d1svVdwd6vMUPPjqw==
-----END AGE ENCRYPTED FILE-----
recipient: age12zdn7x72zrgu9cdv8wdj7xfx42nz09nrwpc2g09cwx5fwdm0ry6qp5h4jp
encrypted_regex: ^(data|stringData)$
lastmodified: "2026-12-04T05:16:30Z"
mac: ENC[AES256_GCM,data:yYt1AWNi+Ts4c/p3OwrknVVPMPf9PEeYvgz/LckFqsJweSq36b6gzinMcLxJGnenmCokftUA4RvMMF2f0Lcpo3+RqmpPGnCzpAVQ0ypuS2+n+bET7tF/tu9icuwZaTu0sNW+/j8VK5T5nlrrw+aLf3O9yIuP7XVLXyjodJqbH7c=,iv:jSMmP96DHN6qLmpHoisVQu1DYlMVehxdXNWkzh5GZwk=,tag:b98z963bBjpM5gGZnKHqBg==,type:str]
version: 3.13.3