infrastructure(garage): commit the config, prove WG-only, split keys, back it up, scrape it
Garage was the only piece of the platform in no git repository and reachable from more than WireGuard. This is a hardening/ownership pass, not a migration — the container stays on the Pi. - infrastructure/garage/: docker-compose.yml (pinned dxflrs/garage:v1.1.0, every publish on an explicit 10.10.0.1 / 127.0.0.1 address, no 0.0.0.0), garage.toml (rpc_secret moved to /etc/garage/garage.env, [s3_web]/3902 removed, admin API on 3903 for metrics), README (apply, state, restore, keys, backup, metrics) and an explicit note that Flux does not apply it. - host/garage-firewall.nft: PREROUTING priority -140 drop of 3900-3903 from anything but lo/wg0/wg-remote. Docker's DNAT bypasses ufw's INPUT chain, so ufw alone cannot stop a compose typo from publishing S3 on the LAN. Measured: a 0.0.0.0:3902 publish stayed unreachable from the LAN and the drop counter incremented. - backup/: garage-backup.sh meta|data + systemd timers (meta hourly, data nightly) rsyncing to [email protected]:/root/garage-backup over wg-remote. Nothing else backs up Forgejo or the PG PVCs; that stays uncovered. - monitoring/controllers/home/garage.yaml: Service + EndpointSlice + ServiceMonitor for 10.10.0.1:3903 and five alerts. Target is UP. - apps/base/siriusdevops/networkpolicy-site-egress.yaml: first policy in the namespace. CiliumNetworkPolicy, not a k8s NetworkPolicy: 10.10.0.1 is a cluster node (reserved:remote-node), so ipBlock 10.10.0.1/32 is inert. Egress whitelist = TCP 3900 to a node + cluster DNS; measured 403 on 3900, timeouts on 3900-adjacent 5000/3903, on 10.10.0.2:8080 and on the internet. Keys: ci-push (W only, siriusdevops-media) and site-fetch (R only, same bucket) replace the shared ci-key, which is deleted. The k8s Secret and the two Forgejo repo secrets were repointed. No key material is in this commit.
This commit is contained in:
parent
05864f3c2c
commit
d82e1b9f2a
15 changed files with 802 additions and 0 deletions
239
infrastructure/garage/README.md
Normal file
239
infrastructure/garage/README.md
Normal file
|
|
@ -0,0 +1,239 @@
|
|||
# Garage — the private object store (rpi, outside the cluster)
|
||||
|
||||
Garage is a single-node S3-compatible object store running as a Docker
|
||||
container on **`rpi`** (the WireGuard hub, `10.10.0.1`). It is deliberately
|
||||
**not** a Kubernetes workload: a storage service should not be a pod on a
|
||||
three-node homelab where rebooting the control plane is routine.
|
||||
|
||||
Its only network path is the WireGuard mesh. There is no public hostname, no
|
||||
Cloudflare tunnel, no DNS record, no website listener, and no public bucket.
|
||||
|
||||
## This directory is NOT applied by Flux
|
||||
|
||||
Flux watches `./clusters/homek8s` of `sirius/homek8s`. Nothing in that path
|
||||
references this directory, and that is intentional — Flux manages the cluster,
|
||||
not the Pi's host containers. **A push here changes nothing on the Pi.**
|
||||
|
||||
It is committed for one reason: reproducibility. A rebuilt Pi comes back from
|
||||
this directory plus one backup of `meta/` and `data/`. Before 2026-11-19 the
|
||||
Garage config existed only at `/home/sirius/websites/garage/garage.toml` on the
|
||||
host, in no git repository anywhere — the only piece of the platform that
|
||||
neither Flux nor a repo could rebuild.
|
||||
|
||||
## What runs
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| Container | `garage`, image `dxflrs/garage:v1.1.0` (pinned tag, never `:latest`) |
|
||||
| Compose file | `/etc/garage/docker-compose.yml` (installed from here) |
|
||||
| Config | `/etc/garage/garage.toml` (installed from `garage.toml` here) |
|
||||
| RPC secret | `/etc/garage/garage.env` → `GARAGE_RPC_SECRET`, `0600 root:root`, **not in git** |
|
||||
| State | `/home/sirius/websites/garage/meta/` (metadata) and `.../data/` (objects) |
|
||||
| Node | `d053db4dfc97bf78`, zone `dc1`, capacity 100 GB, `replication_factor = 1` |
|
||||
|
||||
State paths were kept at the historical locations on purpose, so switching to
|
||||
this compose file moved no data.
|
||||
|
||||
## Ports — every publish is an explicit address
|
||||
|
||||
| Host address | Port | Purpose |
|
||||
|---|---|---|
|
||||
| `10.10.0.1` | 3900 | S3 API — the only endpoint the cluster consumes |
|
||||
| `10.10.0.1` | 3903 | `/metrics` for Prometheus |
|
||||
| `127.0.0.1` | 3900 | host-local S3, for backup verification on the Pi |
|
||||
|
||||
There is **no `0.0.0.0` publish** and no `3901`/`3902` publish at all
|
||||
(see "Removed" below). Docker scopes a specific-IP publish to that destination,
|
||||
so `192.168.1.125:3900` and any public address are closed.
|
||||
|
||||
## Defence in depth (this is the load-bearing part)
|
||||
|
||||
`host/garage-firewall.nft` is an nftables table in **PREROUTING priority
|
||||
-140**, i.e. *before* Docker's DNAT (-100). ufw cannot do this job: Docker's
|
||||
port publishing bypasses ufw's INPUT chain entirely, so a compose typo that
|
||||
published `0.0.0.0:3900` would be reachable with ufw still reporting
|
||||
"default deny (incoming)". The nft table drops 3900-3903 from everything that
|
||||
is not `wg0`/`wg-remote`/`lo`, whatever address Docker asked for.
|
||||
|
||||
```bash
|
||||
sudo ./host/install-garage-firewall.sh # idempotent; loads + verifies
|
||||
nft list table inet garage_guard # counters prove traffic hit the guard
|
||||
```
|
||||
|
||||
The Pi's ufw stays as-is (default deny incoming). Do **not** fold this table
|
||||
into a general host firewall — the Pi's ufw owns that, and moving k8s/wgportal/
|
||||
DNS traffic here strands the cluster.
|
||||
|
||||
## Apply / re-apply
|
||||
|
||||
Files installed, then compose up:
|
||||
|
||||
```bash
|
||||
# on the Pi, from a checkout of sirius/homek8s
|
||||
cd infrastructure/garage
|
||||
sudo install -d -m 0755 /etc/garage
|
||||
sudo install -m 0644 garage.toml /etc/garage/garage.toml
|
||||
sudo install -m 0644 docker-compose.yml /etc/garage/docker-compose.yml
|
||||
|
||||
# one-time: the RPC secret is not in git
|
||||
printf 'GARAGE_RPC_SECRET=%s\n' "$(openssl rand -hex 32)" | sudo tee /etc/garage/garage.env
|
||||
sudo chmod 0600 /etc/garage/garage.env
|
||||
|
||||
cd /etc/garage && sudo docker compose up -d
|
||||
```
|
||||
|
||||
`docker compose up -d` recreates the container in place; `meta/` and `data/`
|
||||
are bind mounts, so the node identity and every bucket survive.
|
||||
|
||||
Verify (all three must hold):
|
||||
|
||||
```bash
|
||||
ss -ltnp | grep -E '390[0-3]' # only 10.10.0.1 + 127.0.0.1, never 0.0.0.0
|
||||
sudo docker exec garage /garage -c /etc/garage.toml status # same node ID, HEALTHY
|
||||
curl -s -o /dev/null -w '%{http_code}\n' http://10.10.0.1:3900/ # 403 (auth enforced)
|
||||
curl -s -o /dev/null -w '%{http_code}\n' http://10.10.0.1:3903/metrics # 200
|
||||
```
|
||||
|
||||
The RPC secret is safe to regenerate on a fresh host: with a single node there
|
||||
is no peer to authenticate against. If the node is ever joined to a second one,
|
||||
the secret must match on both and must come from the backup, not from git.
|
||||
|
||||
## Keys — one per consumer
|
||||
|
||||
Key material is never committed and never printed. Key **IDs** and scopes:
|
||||
|
||||
| Key ID | Name | Scope | Consumer |
|
||||
|---|---|---|---|
|
||||
| `GK751dab7d7d535f49d060adfb` | `ci-push` | **W** on `siriusdevops-media` | `sirius/siriusdevops` CI media upload (Forgejo secrets `GARAGE_ACCESS_KEY` / `GARAGE_SECRET_KEY`) |
|
||||
| `GK633f87c796ae91585cca2303` | `site-fetch` | **R** on `siriusdevops-media` | `siriusdevops-site` initContainer (Secret `siriusdevops/garage-media-s3`) |
|
||||
| `GK0e3b3c6f07813bc3002adb94` | `sirius-growth-blog` | RW `sirius-growth-blog-media` | blog pipeline |
|
||||
| `GK50cccc3f680384d1d8d2db50` | `sirius-growth-ci` | RWO `sirius-growth-photos`, RW `siriusdevops-media` | `sirius-growth` `deploy-site.yml` photo sync (Forgejo secrets, repointed 2026-11-19) |
|
||||
| `GKb7800d139463b4190b28bde8` | `sirius-growth-portal` | RW `sirius-growth-client-files` | portal client files |
|
||||
|
||||
The legacy shared key `ci-key` (`GKddc329c08c30d1332e109fd4`) was **deleted**
|
||||
2026-11-19, not rotated. It held RWO on `sirius-growth-photos`,
|
||||
RWO on `piedmont-photos` and RW on `siriusdevops-media`, and it was the key the
|
||||
site initContainer was reading media with. Rotating in place would have meant
|
||||
deleting and re-creating the same over-broad grant, and a fresh credential with
|
||||
no consumer is just a live secret nobody uses. Its media grant is replaced by
|
||||
`ci-push` / `site-fetch`, its photos grant by `sirius-growth-ci`; **no workflow
|
||||
in any repo still references `piedmont-photos`**, so that grant was dropped
|
||||
rather than preserved. If something does turn out to need `piedmont-photos`,
|
||||
mint a scoped key (`key create` + `bucket allow --read|--write`) instead of
|
||||
resurrecting a shared one.
|
||||
|
||||
`ci-push` is `W` only, which is why the site repo's media step is
|
||||
`aws s3 cp --recursive`, **not** `aws s3 sync`: `sync` calls `ListObjectsV2`
|
||||
and Garage answers `403 Forbidden: Operation is not allowed for this key`
|
||||
without `R`. A write-only key that can secretly read is not write-only.
|
||||
|
||||
Create a key and grant exactly one bucket:
|
||||
|
||||
```bash
|
||||
sudo docker exec garage /garage -c /etc/garage.toml key create site-fetch --yes
|
||||
sudo docker exec garage /garage -c /etc/garage.toml bucket allow --read siriusdevops-media --key site-fetch
|
||||
sudo docker exec garage /garage -c /etc/garage.toml key info site-fetch # confirm scope
|
||||
```
|
||||
|
||||
## Removed: what and why
|
||||
|
||||
- **`[s3_web]` / port 3902 (static website mode)** — removed 2026-11-19. It was
|
||||
published on `127.0.0.1` only, so a pod could never reach it (a pod's
|
||||
`127.0.0.1` is its own netns); public site serving is the Cilium Gateway on
|
||||
siriussec. Its only remaining effect was to tempt bucket publicity, which is
|
||||
what pushed `sirius-growth` to bake photos into the image. The initContainer
|
||||
sync replaced that need. Re-adding it means publishing a port and re-deciding
|
||||
bucket publicity — don't do that casually.
|
||||
- **port 3901 (RPC) publish** — removed. Single node: nothing outside the
|
||||
container speaks RPC. Garage's own CLI still uses loopback *inside* the
|
||||
container namespace.
|
||||
- **`rpc_secret` in the config file** — moved to `GARAGE_RPC_SECRET` in
|
||||
`/etc/garage/garage.env` so the committed config carries no credential.
|
||||
|
||||
## Backup — nightly off the Pi
|
||||
|
||||
`backup/garage-backup.sh meta|data`, driven by two systemd timers:
|
||||
|
||||
| Unit | Schedule | What |
|
||||
|---|---|---|
|
||||
| `garage-meta-backup.{service,timer}` | hourly (+≤5 min jitter) | `garage meta snapshot` (consistent copy of `db.sqlite` while running) + `cluster_layout`, `data_layout`, `node_key`, `garage.toml`, `garage.env` |
|
||||
| `garage-data-backup.{service,timer}` | nightly 03:30 (+≤10 min jitter) | `rsync -a --delete` of `data/` |
|
||||
|
||||
Destination is **`[email protected]:/root/garage-backup/`** — the Linode VPS,
|
||||
reached over the `wg-remote` tunnel with the Pi's `~/.ssh/linode_admin` key.
|
||||
It is off the Pi, in another power and internet domain. A bucket that backs up
|
||||
into itself is not a backup.
|
||||
|
||||
```bash
|
||||
sudo install -m 0755 backup/garage-backup.sh /usr/local/sbin/garage-backup.sh
|
||||
sudo install -m 0644 backup/garage-meta-backup.service backup/garage-meta-backup.timer \
|
||||
backup/garage-data-backup.service backup/garage-data-backup.timer \
|
||||
/etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now garage-meta-backup.timer garage-data-backup.timer
|
||||
sudo systemctl start garage-meta-backup.service # prove it once by hand
|
||||
journalctl -u garage-meta-backup.service -n 30 --no-pager
|
||||
```
|
||||
|
||||
**What is *not* covered by any other job:** nothing in this cluster backs up
|
||||
Forgejo or the Postgres PVCs today — there is no backup CronJob in
|
||||
`apps/base/forgejo/`, only the nightly *prune*. So Garage's backup is not
|
||||
"added to" an existing one; it is the first backup job the platform has, and
|
||||
Forgejo/PG remain uncovered (a separate card).
|
||||
|
||||
## Restore
|
||||
|
||||
Rebuilding the Pi, or recovering from a lost `meta/`:
|
||||
|
||||
```bash
|
||||
# 1. get the tree back
|
||||
sudo install -d -m 0755 /etc/garage
|
||||
sudo install -d /home/sirius/websites/garage/{meta,data}
|
||||
sudo rsync -a root@10.20.0.1:/root/garage-backup/meta/ /home/sirius/websites/garage/meta/
|
||||
sudo rsync -a root@10.20.0.1:/root/garage-backup/data/ /home/sirius/websites/garage/data/
|
||||
|
||||
# 2. newest consistent metadata snapshot becomes the live db
|
||||
sudo cp /home/sirius/websites/garage/meta/snapshots/<newest>/db.sqlite \
|
||||
/home/sirius/websites/garage/meta/db.sqlite
|
||||
sudo rm -f /home/sirius/websites/garage/meta/db.sqlite-shm \
|
||||
/home/sirius/websites/garage/meta/db.sqlite-wal
|
||||
sudo chown -R root:root /home/sirius/websites/garage/meta
|
||||
|
||||
# 3. restore config + secret (both are in the backup)
|
||||
sudo install -m 0644 /root/garage-backup/meta/garage.toml /etc/garage/garage.toml
|
||||
sudo install -m 0600 /root/garage-backup/meta/garage.env /etc/garage/garage.env
|
||||
sudo install -m 0644 docker-compose.yml /etc/garage/docker-compose.yml
|
||||
|
||||
# 4. bring it up and verify
|
||||
cd /etc/garage && sudo docker compose up -d
|
||||
sudo docker exec garage /garage -c /etc/garage.toml status # node ID must match d053db4dfc97bf78
|
||||
sudo docker exec garage /garage -c /etc/garage.toml bucket list
|
||||
```
|
||||
|
||||
`meta/` is the piece that orphans `data/`: the object bytes are useless without
|
||||
the metadata DB that maps keys to block refs. Losing `data/` alone loses objects
|
||||
but leaves a consistent store. `node_key` must be restored with `meta/` or the
|
||||
node comes back with a new identity and the layout no longer matches.
|
||||
|
||||
**Key material is not in the backup.** S3 keys live only in Garage's metadata
|
||||
(`meta/`), so a restore that keeps `meta/` keeps the existing keys — no secret
|
||||
re-issue needed. A restore that rebuilds `meta/` from scratch must recreate
|
||||
`ci-push` / `site-fetch` and update the k8s Secret and the Forgejo secrets.
|
||||
|
||||
## Metrics
|
||||
|
||||
`/metrics` is served by the admin API and published on `10.10.0.1:3903` only
|
||||
(no `metrics_token` — the port does not leave the mesh). Scrape config, the
|
||||
`garage` Service/EndpointSlice and the alert rules live in
|
||||
`monitoring/controllers/home/garage.yaml` (that one **is** GitOps, via Flux).
|
||||
|
||||
Alerts: `GarageDown`, `GarageClusterUnhealthy`, `GarageDiskFillingUp` (>80%),
|
||||
`GarageMetadataGcBacklog`, `GarageResyncErroredBlocks`. There is no Alertmanager
|
||||
in this stack — they surface in Prometheus → `/alerts` and Grafana → Alerting.
|
||||
|
||||
## Guardrails
|
||||
|
||||
- Never make a bucket public. Never add a Cloudflare tunnel or DNS record.
|
||||
- Never publish the website listener.
|
||||
- Never publish a port on `0.0.0.0` "because it's only temporary".
|
||||
- Do not migrate Garage into Kubernetes on a hardening pass — see the top.
|
||||
88
infrastructure/garage/backup/garage-backup.sh
Normal file
88
infrastructure/garage/backup/garage-backup.sh
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/env bash
|
||||
# Garage backup — meta (frequent) and data (nightly), copied OFF the Pi.
|
||||
#
|
||||
# garage-backup.sh meta # consistent metadata snapshot + layout + rpc env
|
||||
# garage-backup.sh data # object data tree
|
||||
#
|
||||
# Destination is the Linode VPS (10.20.0.1) over the wg-remote tunnel, NOT the
|
||||
# Pi and NOT a bucket in Garage. A bucket that backs up into itself is not a
|
||||
# backup: losing meta/ or the disk loses the "backup" with it.
|
||||
#
|
||||
# Run as root (systemd unit does): node_key is 0600 root:root, and rsync needs
|
||||
# to read the whole meta tree. The SSH key is the sirius user's linode_admin,
|
||||
# readable by root.
|
||||
#
|
||||
# Restore procedure: see ../README.md. Exit code is the truth — the units are
|
||||
# oneshot and `systemctl status garage-*-backup.service` shows the last result.
|
||||
set -euo pipefail
|
||||
|
||||
mode=${1:-}
|
||||
case "$mode" in
|
||||
meta|data) ;;
|
||||
*) echo "usage: $0 meta|data" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
GARAGE_DIR=/home/sirius/websites/garage
|
||||
KEY=/home/sirius/.ssh/linode_admin
|
||||
REMOTE=[email protected]
|
||||
DEST=/root/garage-backup
|
||||
KEEP_LOCAL_SNAPSHOTS=14
|
||||
|
||||
# Host key: the Pi's root has no known_hosts entry for the VPN peer, and a
|
||||
# rebuilt Pi would not have one either. accept-new pins it on first contact and
|
||||
# still fails loudly if the key later changes. The transport is the WireGuard
|
||||
# tunnel, so first contact is already authenticated at the network layer.
|
||||
export RSYNC_RSH="ssh -i $KEY -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o ConnectTimeout=20"
|
||||
|
||||
log() { printf '%s %s\n' "$(date -u +%FT%TZ)" "$*"; }
|
||||
|
||||
# Fail loudly and early if the tunnel/target is not there. A silent "backup ok"
|
||||
# with the VPS unreachable is the failure mode this whole file exists to avoid.
|
||||
log "target check: $(ssh -i "$KEY" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o ConnectTimeout=20 "$REMOTE" 'hostname; df -h / | tail -1')"
|
||||
|
||||
# rsync will not create the parent of a --delete target, so make the tree first.
|
||||
ssh -i "$KEY" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=accept-new "$REMOTE" \
|
||||
"install -d -m 0700 $DEST $DEST/meta $DEST/meta/snapshots $DEST/data"
|
||||
|
||||
case "$mode" in
|
||||
meta)
|
||||
# `meta snapshot` is Garage's supported consistent copy of db.sqlite while
|
||||
# the server keeps running. Never rsync a live db.sqlite+wal by hand.
|
||||
log "taking metadata snapshot"
|
||||
docker exec garage /garage -c /etc/garage.toml meta snapshot --all
|
||||
|
||||
# Prune local snapshots so /home does not fill with dailies.
|
||||
mapfile -t snaps < <(find "$GARAGE_DIR/meta/snapshots" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %p\n' \
|
||||
| sort -rn | awk '{print $2}')
|
||||
if (( ${#snaps[@]} > KEEP_LOCAL_SNAPSHOTS )); then
|
||||
log "pruning $(( ${#snaps[@]} - KEEP_LOCAL_SNAPSHOTS )) old local snapshot(s)"
|
||||
printf '%s\0' "${snaps[@]:$KEEP_LOCAL_SNAPSHOTS}" | xargs -0 -r rm -rf
|
||||
fi
|
||||
|
||||
log "syncing metadata to $REMOTE:$DEST/meta"
|
||||
rsync -a --delete "$GARAGE_DIR/meta/snapshots/" "$REMOTE:$DEST/meta/snapshots/"
|
||||
# Layout + node identity + the RPC secret. Without node_key the restored
|
||||
# node gets a new identity and meta/data no longer agree.
|
||||
rsync -a "$GARAGE_DIR/meta/cluster_layout" \
|
||||
"$GARAGE_DIR/meta/data_layout" \
|
||||
"$GARAGE_DIR/meta/node_key" \
|
||||
"$REMOTE:$DEST/meta/"
|
||||
install -d -m 0700 /etc/garage
|
||||
rsync -a /etc/garage/garage.toml /etc/garage/garage.env "$REMOTE:$DEST/meta/"
|
||||
ssh -i "$KEY" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=accept-new "$REMOTE" \
|
||||
"chmod 600 $DEST/meta/garage.env $DEST/meta/node_key"
|
||||
;;
|
||||
|
||||
data)
|
||||
log "syncing object data to $REMOTE:$DEST/data"
|
||||
# --delete keeps the remote an exact mirror (deleted objects stay deleted).
|
||||
# multipart/ is in-flight upload scratch and is deliberately not mirrored.
|
||||
rsync -a --delete --exclude '/multipart/' \
|
||||
"$GARAGE_DIR/data/" "$REMOTE:$DEST/data/"
|
||||
;;
|
||||
esac
|
||||
|
||||
log "remote state after $mode backup:"
|
||||
ssh -i "$KEY" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=accept-new "$REMOTE" \
|
||||
"du -sh $DEST/* 2>/dev/null; echo '--- newest meta snapshot ---'; ls -1dt $DEST/meta/snapshots/*/ 2>/dev/null | head -3"
|
||||
log "OK"
|
||||
17
infrastructure/garage/backup/garage-data-backup.service
Normal file
17
infrastructure/garage/backup/garage-data-backup.service
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# /etc/systemd/system/garage-data-backup.service (rpi)
|
||||
#
|
||||
# Object data is 36 MB today; a nightly full rsync costs seconds. If that ever
|
||||
# stops being true, switch to `rsync -a --delete` with a bandwidth cap rather
|
||||
# than moving to incremental tooling — the tree is content-addressed and rsync
|
||||
# already only transfers changed blocks.
|
||||
[Unit]
|
||||
Description=Garage object data -> Linode VPS (off the Pi)
|
||||
After=docker.service network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/sbin/garage-backup.sh data
|
||||
TimeoutStartSec=2h
|
||||
Nice=15
|
||||
IOSchedulingClass=idle
|
||||
12
infrastructure/garage/backup/garage-data-backup.timer
Normal file
12
infrastructure/garage/backup/garage-data-backup.timer
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# /etc/systemd/system/garage-data-backup.timer (rpi)
|
||||
[Unit]
|
||||
Description=Nightly Garage object-data backup
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 03:30:00
|
||||
RandomizedDelaySec=600
|
||||
Persistent=true
|
||||
Unit=garage-data-backup.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
15
infrastructure/garage/backup/garage-meta-backup.service
Normal file
15
infrastructure/garage/backup/garage-meta-backup.service
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# /etc/systemd/system/garage-meta-backup.service (rpi)
|
||||
#
|
||||
# Metadata is the piece that orphans data/ if lost, and it changes on every
|
||||
# upload/key/bucket change — hence hourly, not nightly.
|
||||
[Unit]
|
||||
Description=Garage metadata snapshot -> Linode VPS (off the Pi)
|
||||
After=docker.service network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/sbin/garage-backup.sh meta
|
||||
# Slow tunnel is not a reason to retry a 5-minute job forever.
|
||||
TimeoutStartSec=15min
|
||||
Nice=10
|
||||
13
infrastructure/garage/backup/garage-meta-backup.timer
Normal file
13
infrastructure/garage/backup/garage-meta-backup.timer
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# /etc/systemd/system/garage-meta-backup.timer (rpi)
|
||||
[Unit]
|
||||
Description=Hourly Garage metadata backup
|
||||
|
||||
[Timer]
|
||||
OnCalendar=hourly
|
||||
# Spread off the hour so it does not race the Forgejo/registry work on the same box.
|
||||
RandomizedDelaySec=300
|
||||
Persistent=true
|
||||
Unit=garage-meta-backup.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
53
infrastructure/garage/docker-compose.yml
Normal file
53
infrastructure/garage/docker-compose.yml
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# Garage — private object store on the Pi
|
||||
#
|
||||
# NOT Flux-managed. Flux watches ./clusters/homek8s and none of it references
|
||||
# this directory; the container is applied on rpi by hand (see README.md).
|
||||
# The point of committing it is reproducibility: a rebuilt Pi comes back from
|
||||
# this directory plus a backup.
|
||||
#
|
||||
# Installed to /etc/garage/docker-compose.yml (root:root 0644). State stays on
|
||||
# the existing bind mounts under /home/sirius/websites/garage/ so this file can
|
||||
# replace the old in-place definition without moving a byte of data.
|
||||
#
|
||||
# Exposure rule: every port is published on an EXPLICIT address. There is no
|
||||
# 0.0.0.0 publish anywhere. 10.10.0.1 is the WireGuard hub address (the mesh),
|
||||
# 127.0.0.1 is the Pi itself. Docker scopes a specific-IP publish to that
|
||||
# destination only, so the LAN (192.168.1.125) and anything public stay closed
|
||||
# even before the host firewall in host/garage-firewall.nft is considered.
|
||||
|
||||
name: garage
|
||||
|
||||
services:
|
||||
garage:
|
||||
image: dxflrs/garage:v1.1.0
|
||||
container_name: garage
|
||||
restart: unless-stopped
|
||||
|
||||
# GARAGE_RPC_SECRET. 0640 root:root, never in git. Single node: the value
|
||||
# only authenticates RPC between Garage nodes, and there are none — a fresh
|
||||
# `openssl rand -hex 32` is a valid restore value.
|
||||
env_file:
|
||||
- /etc/garage/garage.env
|
||||
|
||||
command: ["/garage", "-c", "/etc/garage.toml", "server"]
|
||||
|
||||
ports:
|
||||
# S3 API over the WireGuard mesh. This is the only endpoint anything in
|
||||
# the cluster uses (site media sync in, CI sync out).
|
||||
- "10.10.0.1:3900:3900"
|
||||
# Prometheus /metrics over the mesh (see monitoring/controllers/home/garage.yaml).
|
||||
- "10.10.0.1:3903:3903"
|
||||
# Host-local S3 for backup verification / manual `garage` CLI work on the
|
||||
# Pi itself. Loopback only.
|
||||
- "127.0.0.1:3900:3900"
|
||||
|
||||
volumes:
|
||||
- /etc/garage/garage.toml:/etc/garage.toml:ro
|
||||
- /home/sirius/websites/garage/meta:/data/meta
|
||||
- /home/sirius/websites/garage/data:/data/data
|
||||
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
42
infrastructure/garage/garage.toml
Normal file
42
infrastructure/garage/garage.toml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# Garage v1.1.0 configuration — single node, rpi (10.10.0.1 on the WG mesh).
|
||||
#
|
||||
# Installed to /etc/garage/garage.toml (root:root 0644).
|
||||
#
|
||||
# Addresses here are INSIDE the container network namespace. What the host
|
||||
# actually exposes is decided by docker-compose.yml (explicit 10.10.0.1 / 127.0.0.1
|
||||
# publishes), and enforced a second time by host/garage-firewall.nft. A 0.0.0.0
|
||||
# listener in this file is therefore not a public exposure.
|
||||
#
|
||||
# rpc_secret is NOT in this file: it is supplied as GARAGE_RPC_SECRET from
|
||||
# /etc/garage/garage.env (0600, out of git). Verified on Garage v1.1.0 —
|
||||
# the env var overrides the missing config key and the node starts normally.
|
||||
|
||||
metadata_dir = "/data/meta"
|
||||
data_dir = "/data/data"
|
||||
db_engine = "sqlite"
|
||||
replication_factor = 1
|
||||
|
||||
# RPC. Single node: nothing connects from outside the container, so the host
|
||||
# publishes nothing for 3901. Garage still needs the listener for its own
|
||||
# CLI-over-loopback calls (`garage status`, `garage key ...`).
|
||||
rpc_bind_addr = "0.0.0.0:3901"
|
||||
rpc_public_addr = "127.0.0.1:3901"
|
||||
|
||||
[s3_api]
|
||||
s3_region = "garage"
|
||||
api_bind_addr = "0.0.0.0:3900"
|
||||
|
||||
# Admin API + Prometheus metrics. Published on 10.10.0.1:3903 only.
|
||||
# No metrics_token: the listener is WireGuard-only, and Prometheus runs in the
|
||||
# cluster on the far side of the mesh. Add `metrics_token` here (and a matching
|
||||
# bearer token in the ServiceMonitor) if 3903 ever leaves the mesh.
|
||||
[admin]
|
||||
api_bind_addr = "0.0.0.0:3903"
|
||||
|
||||
# [s3_web] REMOVED 2026-11-19 (port 3902, static website mode).
|
||||
# Nothing consumed it: a pod's 127.0.0.1 is its own netns, so 127.0.0.1:3902 was
|
||||
# unreachable from the cluster, and public website serving is Cilium Gateway on
|
||||
# siriussec (10.10.0.2:8080). The site now pulls media from the private bucket
|
||||
# with an initContainer (`aws s3 sync` -> /media), so the web listener had no
|
||||
# remaining consumer. Re-adding it means publishing a port and re-deciding
|
||||
# bucket publicity — do not do that casually.
|
||||
41
infrastructure/garage/host/garage-firewall.nft
Normal file
41
infrastructure/garage/host/garage-firewall.nft
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/sbin/nft -f
|
||||
# Garage inbound guard — defence in depth for the S3/metrics listeners.
|
||||
#
|
||||
# WHY THIS EXISTS AND WHY IT IS NOT JUST ufw:
|
||||
# Docker publishes container ports through a DNAT rule in the `nat`
|
||||
# PREROUTING chain. That traversal never reaches ufw's INPUT chain, so a
|
||||
# compose typo that publishes `0.0.0.0:3900:3900` would be reachable from the
|
||||
# LAN and (worse) from anywhere the router forwards, with ufw still reporting
|
||||
# "default deny (incoming)". This table sits in PREROUTING at priority -140 —
|
||||
# after mangle (-150), before DNAT (-100) — so it drops the packet BEFORE
|
||||
# Docker can rewrite it, whatever address compose asked for.
|
||||
#
|
||||
# Effective policy for 3900-3903: accept from WireGuard (wg0, the remote hub
|
||||
# link wg-remote) and loopback, drop everything else (LAN eth0/wlan0, tailscale,
|
||||
# public). DROP rather than REJECT so an off-mesh scan sees a filtered port and
|
||||
# learns nothing.
|
||||
#
|
||||
# Scope is deliberately narrow: only Garage's ports. Do not widen this table
|
||||
# into a general host firewall — the Pi's ufw already owns that, and moving
|
||||
# k8s/wgportal/DNS traffic here would strand the cluster.
|
||||
#
|
||||
# Loaded by garage-firewall.service. `destroy` (not `delete`) so re-running the
|
||||
# unit replaces the table instead of appending a duplicate copy, and does not
|
||||
# fail on first install.
|
||||
#
|
||||
# Changing Garage's ports means changing this set AND docker-compose.yml AND
|
||||
# the rpi ufw rules in one go; a port in one place only is how you get a
|
||||
# listener that answers on the LAN.
|
||||
destroy table inet garage_guard
|
||||
table inet garage_guard {
|
||||
chain prerouting {
|
||||
type filter hook prerouting priority -140; policy accept;
|
||||
|
||||
# WireGuard only: the mesh hub link and loopback.
|
||||
iifname { "lo", "wg0", "wg-remote" } tcp dport { 3900, 3901, 3902, 3903 } counter accept
|
||||
|
||||
# Anything else — LAN, tailscale, public, or a future interface that
|
||||
# nobody remembered to add above.
|
||||
tcp dport { 3900, 3901, 3902, 3903 } counter drop
|
||||
}
|
||||
}
|
||||
25
infrastructure/garage/host/garage-firewall.service
Normal file
25
infrastructure/garage/host/garage-firewall.service
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# /etc/systemd/system/garage-firewall.service (rpi)
|
||||
#
|
||||
# Host unit, installed by hand (not Flux-managed) — the file lives in git at
|
||||
# infrastructure/garage/host/. Same shape as k8s-api-firewall.service and
|
||||
# internal-gw-firewall.service on siriussec.
|
||||
#
|
||||
# Ordering note: no Requires= on wg-quick@wg0. The Pi's wg0 is normally brought
|
||||
# up by hand / by wgportal and the template unit can be inactive; a hard
|
||||
# dependency would make this unit fail outright and silently leave Garage
|
||||
# unguarded. Ordering against docker is deliberately absent: this table sits at
|
||||
# PREROUTING priority -140 so it is evaluated before Docker's DNAT (-100)
|
||||
# regardless of which of the two loaded first — and `After=docker.service`
|
||||
# together with a `Before=` on the same unit would be an ordering cycle.
|
||||
[Unit]
|
||||
Description=Drop off-WireGuard inbound to Garage (3900-3903) before Docker DNAT
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/sbin/nft -f /etc/nftables.d/garage_guard.nft
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
22
infrastructure/garage/host/install-garage-firewall.sh
Normal file
22
infrastructure/garage/host/install-garage-firewall.sh
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
# Install the Garage inbound guard on rpi. Idempotent; safe to re-run.
|
||||
#
|
||||
# sudo ./install-garage-firewall.sh
|
||||
#
|
||||
# Verifies the table afterwards instead of trusting `systemctl start`'s exit 0.
|
||||
set -euo pipefail
|
||||
|
||||
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
install -D -m 0644 "$here/garage-firewall.nft" /etc/nftables.d/garage_guard.nft
|
||||
install -D -m 0644 "$here/garage-firewall.service" /etc/systemd/system/garage-firewall.service
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now garage-firewall.service
|
||||
|
||||
# Prove it loaded rather than assuming: the table must exist and carry both the
|
||||
# accept and the drop rule.
|
||||
nft list table inet garage_guard >/dev/null
|
||||
nft list table inet garage_guard | grep -q 'dport { 3900, 3901, 3902, 3903 }'
|
||||
echo "OK: garage_guard loaded"
|
||||
nft list table inet garage_guard
|
||||
Loading…
Reference in a new issue