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:
parent
d44ca50dd1
commit
0acc089dc3
10 changed files with 242 additions and 22 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
64
apps/base/forgejo/networkpolicy-backup.yaml
Normal file
64
apps/base/forgejo/networkpolicy-backup.yaml
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
49
apps/base/sirius-growth/networkpolicy-backup.yaml
Normal file
49
apps/base/sirius-growth/networkpolicy-backup.yaml
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
23
monitoring/controllers/home/secret-forgejo-pull.sops.yaml
Normal file
23
monitoring/controllers/home/secret-forgejo-pull.sops.yaml
Normal 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
|
||||
Loading…
Reference in a new issue