diff --git a/CLAUDE.md b/CLAUDE.md index a333298..4b636d8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -67,7 +67,7 @@ Dockerized multi-service personal website self-hosted on `stpvm` (an x86-64 Ubun **Uploads / Garage** (`garage/`): every stored file goes through one path. Frontend: `vue/src/uploads.js` (`uploadFile(file)` → URL, plus `ACCEPT` for pickers, `kindOf`, `isUploadUrl`, `tagFor`). Backend: `POST /api/uploads` (`handlers/handle_upload.go`), a thin wrapper over `services.Uploads.Save` (`services/uploads.go`), which owns the type table (`UploadTypes`), the 10MB limit, random naming and storage. A new feature that takes a file calls those, never its own endpoint. `GET /api/uploads` (admin only, `Uploads.List`, `listUploads()`) lists what is stored, bucket and disk merged, for `components/util/UploadPicker.vue`, the "choose an existing upload" modal used by the canvas's Background panel, Box editor and admin bar. Public files go to a bucket in a self-hosted Garage container (the `uploads` volume when `S3_ENDPOINT` is unset, or when Garage refuses a write). Caddy serves `/uploads/` from Garage's anonymous website endpoint first and the volume second, so the bucket is the source of truth and a Garage outage only affects bucket-only files. Private attachments (`/uploads/private/`) always stay on disk. `garage-webui` at `/garage/` (admin-gated) manages the bucket. First run on a fresh volume needs `garage/bootstrap.sh`; the full runbook is "Garage" in `DEPLOYMENT.md` §7. -**Caddy** (`caddy/`): the public edge since 2026-11-17 — TLS, the SPA and the reverse proxy in front of every service. It obtains and renews its own certificates (DNS-01 through the Cloudflare API, into `./caddy/data`), so there is no certbot. `caddy/Caddyfile` holds the global options and the shared snippets (`proxy`, `limit`, `admin_gate`, `permission_gate`, the upload headers, logging); `caddy/routes.caddy` is the one route table both modes use — add a new route there, in the right place, because inside its `route` block the first matching `handle` wins; `caddy/sites/prod.caddy` and `sites/dev.caddy` hold what differs (TLS, security headers, the apex, static caching, `/`), picked by `CADDY_SITE`. Every variable the config reads goes through the caddy service's explicit `environment:` list. The image build runs `caddy validate`, so `make check-caddy` (or a failed deploy build) catches a bad config before any container is replaced; the first build on a host compiles Caddy with its two plugins (rate limiting, the Cloudflare DNS provider) and is slow, later ones are cached. Rate limits (`import limit `) are sliding windows keyed on the real client IP, and a refused request gets 503; a zone name shared by several routes shares one bucket, so it must always carry the same numbers. Every request is also logged as a JSON line, body included (redacted if it mentions a password, token or secret), to `logs/caddy/payloads.log`. The `traffic` container tails that file so it shows up in Dozzle, which is served at `/dozzle/` behind the admin login; the admin panel no longer has a log view. Caddy has a healthcheck (`http://127.0.0.1/caddy-health`); the `autoheal` container restarts it when that fails, since Docker never restarts an unhealthy container itself. Gitea's commit-pinned history views and archives are admin-gated at the edge because a crawler swarm hammers them; the branch views stay public. `caddy/edge_test.sh` checks the privacy denials and every gate against a running edge. The pre-cutover nginx and certbot configs are in `.deprecated/nginx/` and `.deprecated/certbot/`, kept for the rollback in `DEPLOYMENT.md` §7. +**Caddy** (`caddy/`): the public edge since 2026-11-17 — TLS, the SPA and the reverse proxy in front of every service. It obtains and renews its own certificates (DNS-01 through the Cloudflare API, into `./caddy/data`), so there is no certbot. `caddy/Caddyfile` holds the global options and the shared snippets (`proxy`, `limit`, `admin_gate`, `permission_gate`, the upload headers, logging); `caddy/routes.caddy` is the one route table both modes use — add a new route there, in the right place, because inside its `route` block the first matching `handle` wins; `caddy/sites/prod.caddy` and `sites/dev.caddy` hold what differs (TLS, security headers, the apex, static caching, `/`), picked by `CADDY_SITE`. Every variable the config reads goes through the caddy service's explicit `environment:` list. The image build runs `caddy validate`, so `make check-caddy` (or a failed deploy build) catches a bad config before any container is replaced; the first build on a host compiles Caddy with its two plugins (rate limiting, the Cloudflare DNS provider) and is slow, later ones are cached. Rate limits (`import limit `) are sliding windows keyed on the real client IP, and a refused request gets 503; a zone name shared by several routes shares one bucket, so it must always carry the same numbers. Every request is also logged as a JSON line, body included (redacted if it mentions a password, token or secret), to `logs/caddy/payloads.log`. The `traffic` container tails that file so it shows up in Dozzle, which is served at `/dozzle/` behind the admin login; the admin panel no longer has a log view. Caddy has a healthcheck (`http://127.0.0.1/caddy-health`); the `autoheal` container restarts it when that fails, since Docker never restarts an unhealthy container itself. Gitea is not proxied any more: it lives at `git.` (its own tunnel, from the stpgit repo) and `/gitea/*` 301s there; only the registry at the apex's `/v2/` still goes through Caddy. `caddy/edge_test.sh` checks the privacy denials and every gate against a running edge. The pre-cutover nginx and certbot configs are in `.deprecated/nginx/` and `.deprecated/certbot/`, kept for the rollback in `DEPLOYMENT.md` §7. ## Backend Structure diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index e3ac93a..f0a2cb3 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -34,7 +34,7 @@ dials out and publishes no port; see "Cloudflare Tunnel" in §3. --------------------------------------------- (same container | | | | | | as icecast2) v v v v v v | -/api/ /radio/ /gitea/ /sb/ /notes/ /py/ | +/api/ /radio/ /v2/ /sb/ /notes/ /py/ | backend icecast2 gitea sb sb-pub python | | ^ | | | | @@ -60,7 +60,7 @@ everything that reached Gitea on stpvm still does at the same address: ``` stpvm Gitea LXC (LAN IP) - caddy /gitea/, /v2/ --+ +------------------+ + caddy /v2/ (apex) ----+ +------------------+ backend feed ----------+--> gitea:3000 (haproxy) ---> | gitea :3000 | usaco pulls -----------+ :2222 ------------> | :2222 | runner, Renovate localhost:3000 | gitea-db | @@ -69,6 +69,9 @@ everything that reached Gitea on stpvm still does at the same address: over the LAN) ``` +Gitea's public address is `https://git./` (its `ROOT_URL`), served by +the LXC's own Cloudflare tunnel, not by this edge; Caddy only 301s the old +`/gitea/*` URLs there and still proxies the registry at the apex's `/v2/`. The LXC is also on the tailnet, so a laptop can use its own name directly. Deploys of this stack never restart Gitea; recreating the forwarder only drops connections in flight. @@ -87,7 +90,7 @@ drops connections in flight. | jobs (job tracker, published image) | `jobs` | 8080 | `/jobs/` (admin-gated by Caddy `forward_auth`; capture API and userscript public, bearer-token) | no | | activity-tracker (published image, adamf/ccp) | `activity-tracker` | 8080 | `/tracker/`, prefix stripped (pages admin-gated by Caddy `forward_auth`; `/api/v1/` bearer/app-checked) | no | | icecast2 + liquidsoap | `${ICECAST_HOST}` | `${ICECAST_PORT}` | `/radio/` | **harbor port only** | -| gitea (haproxy forwarder to the Gitea LXC) | `${GITEA_HOST}` | 3000, 2222 | `/gitea/`, and the registry at the apex `/v2/` | **3000, 2222** | +| gitea (haproxy forwarder to the Gitea LXC) | `${GITEA_HOST}` | 3000, 2222 | the registry at the apex `/v2/` (`/gitea/*` 301s to `git.`) | **3000, 2222** | | vue | `vue` | 5173 (dev only) | `/` (dev only) | no | | cloudflared | `cloudflared` | — (fixed IP `172.28.255.250`) | all of Caddy, via Cloudflare | no (outbound only) | | dozzle (log viewer) | `dozzle` | 8080 | `/dozzle/` (admin-gated by Caddy `forward_auth`; reads the Docker socket) | no | @@ -123,9 +126,7 @@ The config is `caddy/Caddyfile` (global options and snippets), `caddy/routes.cad it, so stripping the prefix serves a blank page with nothing in the log). - **Upstreams resolve when dialled.** Caddy starts with any upstream container missing and answers 502 until it appears; it never refuses to start over one. -- **Admin gate.** `/sb/`, `/jobs/`, `/tracker/`, `/dozzle/`, `/garage/`, `/radio/admin/`, `/uploads/private/` and - Gitea's history views and archives (`…/commit/`, `…/src/commit/`, `…/blame/commit/`, `…/archive/`, `…/compare/`; the - branch views stay public) are +- **Admin gate.** `/sb/`, `/jobs/`, `/tracker/`, `/dozzle/`, `/garage/`, `/radio/admin/` and `/uploads/private/` are protected by `forward_auth` to the backend's `/auth/validate-admin` (the `admin_gate` snippet); a 401/403 redirects to the SPA login. Most of these services have no auth of their own at that path; the job and activity trackers also check the session themselves. Their carve-outs, which a session @@ -701,7 +702,7 @@ nothing, so pull and `up -d` there afterwards. - *Backups.* A Proxmox `vzdump` of the whole LXC covers the git data and the database together. `data/` alone is not a backup: the issues, PRs, users and registry index are in `gitea_db`. -- *If it is down,* `/gitea/` and the registry are 502, CI does not run, and +- *If it is down,* `git.` is a Cloudflare error, the registry is 502, CI does not run, and image pulls fail; the site itself keeps serving. - *Moving it again* (or the first move, from stpvm): stop Gitea, `pg_dump -Fc` its database and restore it with `pg_restore --no-owner --role=gitea` into diff --git a/caddy/Caddyfile b/caddy/Caddyfile index 5ce38c5..e2602d7 100644 --- a/caddy/Caddyfile +++ b/caddy/Caddyfile @@ -177,7 +177,7 @@ } # ---- Admin gate (/sb/, /jobs/, /tracker/, /dozzle/, /garage/, /radio/admin/, -# Gitea's history views, /uploads/private/) ---- +# /uploads/private/) ---- # forward_auth sends a GET carrying the original request's headers, cookie # included, to the backend's /auth/validate-admin before the request goes # anywhere. 2xx lets it through; 401/403 become a redirect to the SPA login. @@ -231,10 +231,11 @@ # Production only (sites/prod.caddy); HSTS on localhost would poison the # browser for every other localhost project on the machine. # -# No site-wide CSP here. Gitea (proxied at /gitea/) relies on inline