Redirect /gitea/ to git.DOMAIN instead of proxying Gitea
Gitea's ROOT_URL is now https://git.DOMAIN/, served by the Gitea LXC's own tunnel, so Caddy stops proxying /gitea/ and 301s every /gitea/* URL there with the prefix dropped and the query kept (CV links, HTTPS clones, bookmarks). The admin gate on Gitea's commit-history views goes with the proxy; on git.DOMAIN they are public by choice. The registry at the apex's /v2/ is still proxied. edge_test.sh checks the redirects instead of the gate, and the docs and architecture diagrams follow. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -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 <zone> <events> <window>`) 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 <zone> <events> <window>`) 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.<DOMAIN>` (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
|
||||
|
||||
|
||||
+8
-7
@@ -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.<DOMAIN>/` (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.<DOMAIN>`) | **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.<DOMAIN>` 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
|
||||
|
||||
+6
-5
@@ -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 <script>
|
||||
# blocks its own templates generate, so a shared script-src would need
|
||||
# 'unsafe-inline', which voids almost all of CSP's value. If a real CSP
|
||||
# matters again, give the SPA document its own, separate from Gitea.
|
||||
# No site-wide CSP here. It was left out because Gitea, proxied at /gitea/
|
||||
# until 2026-11-24, relies on inline <script> blocks its own templates
|
||||
# generate, so a shared script-src would need 'unsafe-inline', which voids
|
||||
# almost all of CSP's value. Gitea now lives on git.DOMAIN and /gitea/ only
|
||||
# redirects, so that reason is gone; a real CSP for the SPA is now possible.
|
||||
(security_headers) {
|
||||
header {
|
||||
X-Frame-Options "SAMEORIGIN"
|
||||
|
||||
+12
-8
@@ -148,9 +148,6 @@ echo "# admin gate, signed out: must redirect to the login, with the original UR
|
||||
for p in \
|
||||
/sb/ /sb/index.html /jobs/ /jobs/api/graphql /tracker/ /tracker/dashboard \
|
||||
/dozzle/ /garage/ /radio/admin/stats.xsl /uploads/private/x.png \
|
||||
/gitea/adamf/web_server/commit/0000000 /gitea/adamf/web_server/src/commit/0000000/README.md \
|
||||
/gitea/adamf/web_server/archive/main.tar.gz /gitea/adamf/web_server/compare/main...x \
|
||||
/gitea/adamf/web_server/blame/commit/0000000/README.md \
|
||||
"/jobs/leads?x=1"; do
|
||||
must 302 "$LOGIN$p" gate "$p"
|
||||
done
|
||||
@@ -161,21 +158,29 @@ must 302 "${LOGIN}/receipt/" permission /receipt/
|
||||
if [ -n "${EDGE_COOKIE:-}" ]; then
|
||||
echo "# admin gate, signed in: must be let through"
|
||||
for p in /sb/ /jobs/ /tracker/ /dozzle/ /garage/ /radio/admin/stats.xsl \
|
||||
/gitea/adamf/web_server/commit/0000000 /receipt/; do
|
||||
/receipt/; do
|
||||
not_login gate "$p" -H "Cookie: $EDGE_COOKIE"
|
||||
done
|
||||
fi
|
||||
|
||||
echo "# carve-outs and public routes (status depends on the upstream)"
|
||||
for p in /jobs/api/capture /jobs/job-capture.user.js /tracker/api/v1/events \
|
||||
/tracker/tracker.user.js /tracker/readyz /usaco/ /notes/ /gitea/ \
|
||||
/gitea/adamf/web_server/src/branch/main/README.md /radio/status.xsl \
|
||||
/tracker/tracker.user.js /tracker/readyz /usaco/ /notes/ /radio/status.xsl \
|
||||
/py/ /py/docs /api/ /api/me /; do
|
||||
show public "$BASE$p"
|
||||
done
|
||||
|
||||
echo "# Gitea moved to git.<domain>: every /gitea/ URL must 301 there, prefix dropped"
|
||||
GIT_HOST=${BASE#*://}
|
||||
GIT="https://git.${GIT_HOST#www.}"
|
||||
must 301 "$GIT/" gitea /gitea
|
||||
must 301 "$GIT/" gitea /gitea/
|
||||
must 301 "$GIT/adamf/web_server/src/branch/main/README.md" gitea /gitea/adamf/web_server/src/branch/main/README.md
|
||||
must 301 "$GIT/adamf/web_server.git/info/refs?service=git-upload-pack" gitea "/gitea/adamf/web_server.git/info/refs?service=git-upload-pack"
|
||||
must 301 "$GIT/adamf/web_server/commit/0000000" gitea /gitea/adamf/web_server/commit/0000000
|
||||
|
||||
echo "# bare prefixes and moved URLs"
|
||||
for p in /api /radio /dozzle /garage /gitea /notes /sb /py /jobs /usaco \
|
||||
for p in /api /radio /dozzle /garage /notes /sb /py /jobs /usaco \
|
||||
/tracker /receipt /cv/jobs /cv/leads /job-capture.user.js "/gitea?x=1"; do
|
||||
show redirect "$BASE$p"
|
||||
done
|
||||
@@ -187,7 +192,6 @@ done
|
||||
hdr "$BASE/" Content-Type Strict-Transport-Security X-Frame-Options \
|
||||
X-Content-Type-Options Referrer-Policy Content-Security-Policy Server
|
||||
hdr "$BASE/api/" Strict-Transport-Security X-Frame-Options Server
|
||||
hdr "$BASE/gitea/" Strict-Transport-Security X-Frame-Options Server
|
||||
hdr "$BASE/assets/does-not-exist.js" Cache-Control
|
||||
hdr "$BASE/img/stamps/mine.gif" Access-Control-Allow-Origin Cache-Control
|
||||
|
||||
|
||||
+11
-23
@@ -111,7 +111,7 @@ redir {$BACKEND_ENDPOINT} {$BACKEND_ENDPOINT}/ 301
|
||||
redir /radio /radio/ 301
|
||||
redir /dozzle /dozzle/ 301
|
||||
redir /garage /garage/ 301
|
||||
redir /gitea /gitea/ 301
|
||||
redir /gitea https://git.{$DOMAIN}/ 301
|
||||
redir /notes /notes/ 301
|
||||
redir /sb /sb/ 301
|
||||
redir /py /py/ 301
|
||||
@@ -215,23 +215,6 @@ handle /radio/admin/* {
|
||||
}
|
||||
}
|
||||
|
||||
# Gitea's history views and archives. A crawler swarm (129k requests from
|
||||
# 103k IPs over 2026-10-18/19, so per-IP rate limits are useless) walks every
|
||||
# file at every commit, and those pages are the expensive ones: diffs, blame,
|
||||
# tarballs. 89% of its requests were these shapes. People browsing the code
|
||||
# use the branch views (src/branch/..., commits/branch/...), which stay
|
||||
# public, so the CV's repo links still work. Gitea's own
|
||||
# REQUIRE_SIGNIN_VIEW=expensive would also block src/branch, hence doing it
|
||||
# here. Ahead of /gitea/*.
|
||||
@gitea_history path_regexp ^/gitea/[^/]+/[^/]+/((src|raw|blame|commits|media)/commit/|commit/|archive/|compare/)
|
||||
handle @gitea_history {
|
||||
import admin_gate
|
||||
uri strip_prefix /gitea
|
||||
reverse_proxy {$GITEA_HOST}:{$GITEA_PORT} {
|
||||
import proxy
|
||||
}
|
||||
}
|
||||
|
||||
# SilverBullet: the admin-only EDITOR for the vault /notes/ publishes. NO
|
||||
# prefix strip: it is a PWA told its own base path via SB_URL_PREFIX=/sb, and
|
||||
# builds its service-worker scope and asset URLs from it. Strip the prefix and
|
||||
@@ -252,11 +235,16 @@ handle /radio/* {
|
||||
}
|
||||
}
|
||||
|
||||
handle /gitea/* {
|
||||
uri strip_prefix /gitea
|
||||
reverse_proxy {$GITEA_HOST}:{$GITEA_PORT} {
|
||||
import proxy
|
||||
}
|
||||
# Gitea moved to its own address on 2026-11-24: git.DOMAIN, served by the
|
||||
# Gitea LXC's own Cloudflare tunnel (the adamf/stpgit repo), and its ROOT_URL.
|
||||
# Every old link (the CV's, HTTPS clone URLs, bookmarks) is sent there with the
|
||||
# prefix dropped and the query kept; git follows the redirect on a clone. This
|
||||
# edge no longer proxies Gitea's pages, so the admin gate that used to sit on
|
||||
# its commit-history views and archives (a crawler swarm walked them in
|
||||
# 2026-10) went with it: on git.DOMAIN they are public by choice. The registry
|
||||
# at the apex's /v2/ (sites/prod.caddy) is still proxied from here.
|
||||
handle_path /gitea/* {
|
||||
redir https://git.{$DOMAIN}{uri} 301
|
||||
}
|
||||
|
||||
# The public notes viewer, behind the denials at the top of this file. No
|
||||
|
||||
@@ -57,14 +57,9 @@
|
||||
<rect class="dg-box" x="800" y="285" width="280" height="68" rx="3" />
|
||||
<text class="dg-code" x="812" y="323" style="fill: var(--color-primary)">gitea:3000</text>
|
||||
<text class="dg-small" x="1070" y="323" text-anchor="end">git server</text>
|
||||
<circle class="dg-dot dg-dot--pink" cx="24" cy="297" r="4" />
|
||||
<text class="dg-code" x="36" y="301" style="fill: var(--color-secondary)">~ /gitea/<o>/<r>/(…commit/|archive/|compare/)</text>
|
||||
<text class="dg-small" x="390" y="301">strip /gitea · auth_request</text>
|
||||
<path class="dg-edge dg-edge--pink" d="M712,297 H796" />
|
||||
<circle class="dg-dot" cx="24" cy="319" r="4" />
|
||||
<text class="dg-code" x="36" y="323" style="fill: var(--color-secondary)">/gitea/</text>
|
||||
<text class="dg-small" x="390" y="323">strip /gitea</text>
|
||||
<path class="dg-edge" d="M712,319 H796" />
|
||||
<text class="dg-code" x="36" y="323" style="fill: var(--color-secondary)">/gitea/*</text>
|
||||
<text class="dg-small" x="390" y="323">301 → git.DOMAIN (its own tunnel)</text>
|
||||
<circle class="dg-dot" cx="24" cy="341" r="4" />
|
||||
<text class="dg-code" x="36" y="345" style="fill: var(--color-secondary)">/v2/ (apex server block only)</text>
|
||||
<text class="dg-small" x="390" y="345">registry · no body limit · 900s</text>
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
<text class="dg-code" x="570" y="451" text-anchor="middle">:3000 http · :2222 ssh</text>
|
||||
<text class="dg-small" x="570" y="465" text-anchor="middle" style="fill: var(--color-tertiary)">both published</text>
|
||||
<path class="dg-edge" d="M400,437 H476" />
|
||||
<text class="dg-edge-label dg-edge-label--mint" x="440" y="430" text-anchor="middle">/gitea/</text>
|
||||
<text class="dg-edge-label dg-edge-label--mint" x="440" y="430" text-anchor="middle">/v2/</text>
|
||||
<path class="dg-edge dg-edge--green dg-edge--both-green" d="M520,392 V410" />
|
||||
<text class="dg-edge-label" x="528" y="405">clone · push webhook</text>
|
||||
</g>
|
||||
|
||||
Reference in New Issue
Block a user