Trim comments to the non-obvious why
Drop narration, history and restated-code comments across the repo, keep short ones for security boundaries, upstream quirks and ordering constraints, and record the convention in CLAUDE.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+41
-185
@@ -1,55 +1,10 @@
|
||||
# =============================================================================
|
||||
# routes.caddy — the PROXY ROUTE TABLE shared by production and dev. Add a new
|
||||
# proxied route HERE, once.
|
||||
#
|
||||
# WHO IMPORTS IT
|
||||
# sites/prod.caddy (the www site) and sites/dev.caddy, each inside a
|
||||
# `route { ... }` block, followed by that site's own `/` handler (the built
|
||||
# SPA in production, the Vite dev server in dev). Everything else that
|
||||
# differs between the two (TLS, security headers, static-asset caching, the
|
||||
# apex) is in the site files.
|
||||
#
|
||||
# ORDER IS LITERAL: THE FIRST MATCHING handle WINS
|
||||
# Inside `route`, Caddy keeps directives in the order written, and `handle`
|
||||
# blocks are mutually exclusive. So this file is read top to bottom like a
|
||||
# firewall list: denials first, then the specific routes, each carve-out
|
||||
# ahead of the gated prefix it is carved out of, then the catch-alls.
|
||||
# (nginx's longest-prefix / regex-in-file-order / ^~ rules are gone.)
|
||||
#
|
||||
# HOW PATHS ARE MATCHED
|
||||
# `path` matchers are case-insensitive and see the decoded, cleaned path
|
||||
# (`..` resolved, `//` merged), so /SB/, /notes/a/../private/x or
|
||||
# /uploads/%70rivate/x cannot slip past a rule. `path_regexp` sees the
|
||||
# decoded, cleaned path too but is case-sensitive, hence `(?i)` where case
|
||||
# matters. caddy/edge_test.sh checks these against the live edge.
|
||||
#
|
||||
# PATTERNS THAT REPEAT BELOW
|
||||
# - `uri strip_prefix /x`: the public URL carries a prefix (/api, /radio,
|
||||
# /gitea, /py, /tracker, /receipt) but the upstream serves from /. Apps
|
||||
# told their own base path (SilverBullet, the job tracker, usaco, Dozzle,
|
||||
# garage-webui) keep it.
|
||||
# - `import proxy` in every reverse_proxy: the forwarding headers (see the
|
||||
# snippet in Caddyfile).
|
||||
# - `import limit <zone> ...`: see the snippet; DEPLOYMENT.md §6 for the
|
||||
# numbers.
|
||||
# - `import admin_gate` / `import permission_gate <key>`: the session check
|
||||
# against the backend. Some of these services have no auth of their own,
|
||||
# so a gated route that loses its import is open to the internet.
|
||||
# - Upstream read timeouts are not set anywhere: Caddy has none by default,
|
||||
# so a long hotel search, an email sync or a log tail is never cut off by
|
||||
# the proxy. (Cloudflare still gives up on an origin that sends nothing
|
||||
# for 100 s; see DEPLOYMENT.md.)
|
||||
#
|
||||
# Upstream names come from the environment ({$BACKEND_HOST} etc.; see the
|
||||
# caddy service in docker-compose.yml). The job tracker, activity tracker,
|
||||
# usaco, Dozzle and Garage containers have fixed names there, so they are
|
||||
# written literally.
|
||||
# =============================================================================
|
||||
# The route table for both modes, imported inside a `route` block: the first
|
||||
# matching handle wins, so denials go first and each carve-out precedes the
|
||||
# prefix it is carved from. `path` is case-insensitive on the cleaned path;
|
||||
# path_regexp is case-sensitive, hence (?i). caddy/edge_test.sh checks these.
|
||||
# A gated route that loses its gate import is open to the internet.
|
||||
|
||||
# Request bodies: 50 MB everywhere except garage-webui, which takes video
|
||||
# uploads and sets its own 2 GB below. (An outer limit cannot be raised by an
|
||||
# inner one, so the exception has to be carved out here.) The backend caps
|
||||
# uploads at 10 MB itself; this is the ceiling for everything else.
|
||||
# An inner limit cannot raise an outer one, so garage-webui's 2 GB is carved out here.
|
||||
@body_default not path /garage/*
|
||||
request_body @body_default {
|
||||
max_size 50MB
|
||||
@@ -57,38 +12,16 @@ request_body @body_default {
|
||||
|
||||
# ---- Denials -----------------------------------------------------------------
|
||||
|
||||
# /py/internal/: routes the Go backend calls directly over app-network (the
|
||||
# rowing photo reader, which spends a paid Claude call and has no auth of its
|
||||
# own). Never proxied. The Python side also refuses anything carrying the
|
||||
# X-Real-IP / X-Forwarded-For headers `proxy` sets, as a second layer.
|
||||
# Called by the backend over app-network only; spends paid Claude calls.
|
||||
handle /py/internal/* {
|
||||
respond 404
|
||||
}
|
||||
|
||||
# PUBLIC notes viewer privacy boundary. /notes/ is a second, read-only
|
||||
# SilverBullet over the vault /sb/ edits, and SB_SPACE_IGNORE only hides
|
||||
# paths from its file LIST. Everything else serves them (all verified against
|
||||
# 2.11.0 with curl):
|
||||
# /notes/.fs/private/x.md raw file, straight off disk
|
||||
# /notes/private/x the page URL: the server pre-renders the
|
||||
# note's content into the HTML shell
|
||||
# /notes/.fs/.git/... the vault's whole git repo, i.e. every
|
||||
# version of every private note ever
|
||||
# and gitignore semantics mean `private/` in SB_SPACE_IGNORE hides a private/
|
||||
# folder at ANY depth, so the block must too.
|
||||
#
|
||||
# 1. private/ or templates/ as any path segment, page URL or /.fs/. (?i) so
|
||||
# Private/ is caught; (/|$) so the folder itself matches.
|
||||
# 2. Any dot-segment below the first: .git, .obsidian, .env, ... The first
|
||||
# segment is exempt because that is where SilverBullet's own endpoints
|
||||
# live (/.fs, /.config, /.client, /.events ...). Nothing the client
|
||||
# legitimately loads has a dot-segment deeper than that.
|
||||
# 3. Revisions are read from the vault's own .git, i.e. the full history of
|
||||
# every file INCLUDING private/ and anything ever deleted.
|
||||
# SB_REVISIONS=disabled already turns this off upstream; this is the
|
||||
# second lock in case that env var is ever dropped.
|
||||
# Keep the folder list in step with SB_SPACE_IGNORE on silverbullet-public.
|
||||
# 404 rather than 403 so the response does not confirm a private path exists.
|
||||
# SB_SPACE_IGNORE only hides paths from listings, so these block direct
|
||||
# fetches: private/ or templates/ at any depth, any dot-segment below the
|
||||
# first (SilverBullet's own endpoints live at the first), and revisions.
|
||||
# Keep the folder list in step with silverbullet-public's SB_SPACE_IGNORE.
|
||||
# 404, not 403, so a private path's existence isn't confirmed.
|
||||
@notes_private path_regexp (?i)^/notes/(.*/)?(private|templates)(/|$)
|
||||
handle @notes_private {
|
||||
respond 404
|
||||
@@ -104,9 +37,7 @@ handle /notes/.revisions* {
|
||||
}
|
||||
|
||||
# ---- Bare prefixes and moved URLs ----------------------------------------------
|
||||
# So a user typing /gitea without the slash lands correctly. Exact paths: unlike
|
||||
# nginx's prefix locations, /gitea-something is not caught and is left to the
|
||||
# SPA (where an admin-created canvas page with that slug now works).
|
||||
# Exact paths, so /gitea-something is left to the SPA.
|
||||
redir {$BACKEND_ENDPOINT} {$BACKEND_ENDPOINT}/ 301
|
||||
redir /radio /radio/ 301
|
||||
redir /dozzle /dozzle/ 301
|
||||
@@ -120,19 +51,14 @@ redir /usaco /usaco/ 301
|
||||
redir /tracker /tracker/ 301
|
||||
redir /receipt /receipt/ 301
|
||||
|
||||
# Where the job tracker used to be. The SPA routes were client-side, so these
|
||||
# only catch bookmarks and typed URLs. The userscript's old @updateURL lands
|
||||
# on the third, which is how installed copies find version 2.0.0 and its new
|
||||
# API base.
|
||||
# Old job tracker URLs; the userscript's old @updateURL finds its update here.
|
||||
redir /cv/jobs /jobs/ 301
|
||||
redir /cv/leads /jobs/leads 301
|
||||
redir /job-capture.user.js /jobs/job-capture.user.js 301
|
||||
|
||||
# ---- Backend API ---------------------------------------------------------------
|
||||
|
||||
# Live chat / activity feed websocket. Deliberately NOT rate limited: a
|
||||
# websocket is one long-lived request, and a limit here would drop reconnect
|
||||
# storms, not abuse.
|
||||
# Not rate limited: a limit would only drop reconnect storms.
|
||||
handle {$BACKEND_ENDPOINT}/ws* {
|
||||
uri strip_prefix {$BACKEND_ENDPOINT}
|
||||
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
||||
@@ -140,7 +66,7 @@ handle {$BACKEND_ENDPOINT}/ws* {
|
||||
}
|
||||
}
|
||||
|
||||
# Brute-force defence on password auth, on top of the backend's own 5/min.
|
||||
# On top of the backend's own 5/min.
|
||||
handle {$BACKEND_ENDPOINT}/auth/login* {
|
||||
import limit login 5 1m
|
||||
uri strip_prefix {$BACKEND_ENDPOINT}
|
||||
@@ -157,8 +83,7 @@ handle {$BACKEND_ENDPOINT}/uploads* {
|
||||
}
|
||||
}
|
||||
|
||||
# Tighter than the REST catch-all, because one GraphQL query can be
|
||||
# arbitrarily expensive to resolve.
|
||||
# One GraphQL query can be arbitrarily expensive.
|
||||
handle {$BACKEND_ENDPOINT}/graphql* {
|
||||
import limit graphql 10 1s
|
||||
uri strip_prefix {$BACKEND_ENDPOINT}
|
||||
@@ -177,11 +102,7 @@ handle {$BACKEND_ENDPOINT}/* {
|
||||
|
||||
# ---- Admin-gated services ------------------------------------------------------
|
||||
|
||||
# Dozzle: live view of every container's logs, including the `traffic`
|
||||
# container's request-body log. It reads the Docker socket, so it is
|
||||
# effectively root on the host: admin only. DOZZLE_BASE=/dozzle makes it serve
|
||||
# under the prefix itself. Its log tails are server-sent events, which Caddy
|
||||
# streams without buffering.
|
||||
# Docker socket access is root on the host.
|
||||
handle /dozzle/* {
|
||||
import admin_gate
|
||||
reverse_proxy dozzle:8080 {
|
||||
@@ -189,11 +110,7 @@ handle /dozzle/* {
|
||||
}
|
||||
}
|
||||
|
||||
# garage-webui: buckets, keys and a file browser for the Garage object store.
|
||||
# It holds Garage's admin token, so admin only, and its own login is left
|
||||
# unset (one login, not two). BASE_PATH=/garage makes it serve under the
|
||||
# prefix. 2 GB so videos can be uploaded through it; the body streams through
|
||||
# rather than landing on disk first.
|
||||
# Holds Garage's admin token. 2 GB for video uploads.
|
||||
handle /garage/* {
|
||||
import admin_gate
|
||||
request_body {
|
||||
@@ -204,9 +121,7 @@ handle /garage/* {
|
||||
}
|
||||
}
|
||||
|
||||
# The icecast ADMIN UI is a full station-control surface (kick sources, change
|
||||
# metadata) protected only by the icecast admin password. Ahead of /radio/*,
|
||||
# so listener traffic (the mount, status.xsl) is untouched.
|
||||
# Station-control UI guarded only by the icecast password.
|
||||
handle /radio/admin/* {
|
||||
import admin_gate
|
||||
uri strip_prefix /radio
|
||||
@@ -215,10 +130,8 @@ handle /radio/admin/* {
|
||||
}
|
||||
}
|
||||
|
||||
# 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
|
||||
# the app loads a blank page with no error in the log.
|
||||
# No prefix strip: with SB_URL_PREFIX the app builds its URLs from /sb, and a
|
||||
# stripped prefix loads a blank page.
|
||||
handle /sb/* {
|
||||
import admin_gate
|
||||
reverse_proxy {$SILVERBULLET_HOST}:{$SILVERBULLET_PORT} {
|
||||
@@ -235,32 +148,20 @@ handle /radio/* {
|
||||
}
|
||||
}
|
||||
|
||||
# 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.
|
||||
# Gitea is at git.DOMAIN; the registry at /v2/ is still proxied (prod.caddy).
|
||||
handle_path /gitea/* {
|
||||
redir https://git.{$DOMAIN}{uri} 301
|
||||
}
|
||||
|
||||
# The public notes viewer, behind the denials at the top of this file. No
|
||||
# prefix strip, for the same reason as /sb/ (SB_URL_PREFIX=/notes).
|
||||
# No prefix strip (SB_URL_PREFIX=/notes).
|
||||
handle /notes/* {
|
||||
reverse_proxy {$SILVERBULLET_PUBLIC_HOST}:{$SILVERBULLET_PUBLIC_PORT} {
|
||||
import proxy
|
||||
}
|
||||
}
|
||||
|
||||
# /py/hotels/search[/stream] and /py/hotels/scan/stream: public, minutes-long
|
||||
# upstream calls to Travelodge/TfL with a single search slot on the Python
|
||||
# side, so this zone is really concurrency protection. flush_interval -1
|
||||
# passes each NDJSON progress line on as it arrives (chunked responses are
|
||||
# flushed anyway; this makes it explicit). `encode` never touches
|
||||
# application/x-ndjson.
|
||||
# Minutes-long searches with one slot on the Python side, so the limit is
|
||||
# really concurrency protection. flush_interval passes NDJSON lines straight on.
|
||||
@hotels path_regexp ^/py/hotels/(search|scan)
|
||||
handle @hotels {
|
||||
import limit hotel_search 3 1m
|
||||
@@ -280,16 +181,8 @@ handle /py/* {
|
||||
}
|
||||
|
||||
# ---- Job tracker (/jobs/) ----
|
||||
# Its own container (the adamf/job-tracker repo), which serves its SPA and its
|
||||
# API from the same prefix, NOT stripped: the app is built to live at /jobs/.
|
||||
# Gated like /sb/ (the app checks the session itself too), with two
|
||||
# exceptions ahead of it that a session cookie can never reach:
|
||||
# - the capture API, called by the userscript from job sites' origins with
|
||||
# the capture bearer token rather than cookies; the app's
|
||||
# CaptureTokenMiddleware guards it;
|
||||
# - the userscript itself: userscript managers fetch its @updateURL without
|
||||
# the session, and it holds no secrets (the token is entered after
|
||||
# install).
|
||||
# Not stripped: the app lives at /jobs/. The capture API (bearer token) and
|
||||
# the userscript (fetched without cookies, holds no secrets) bypass the gate.
|
||||
handle /jobs/api/capture* {
|
||||
import limit api 30 1s
|
||||
reverse_proxy jobs:8080 {
|
||||
@@ -311,12 +204,9 @@ handle /jobs/* {
|
||||
}
|
||||
}
|
||||
|
||||
# ---- USACO practice log (/usaco/) ----
|
||||
# Its own container (the usaco repo's site/), shaped like /jobs/: SPA and API
|
||||
# under one prefix that is NOT stripped, and no gate, because most of it is
|
||||
# public and the app checks the session itself for the admin's edits. Gitea's
|
||||
# push webhook (/usaco/api/hooks/gitea) comes through here too, from the
|
||||
# Gitea LXC over the LAN; it is signed with USACO_WEBHOOK_SECRET.
|
||||
# ---- USACO (/usaco/) ----
|
||||
# Not stripped, not gated: the app checks the session for admin edits. The
|
||||
# Gitea webhook arrives here, signed with USACO_WEBHOOK_SECRET.
|
||||
handle /usaco/* {
|
||||
import limit api 30 1s
|
||||
reverse_proxy usaco:8080 {
|
||||
@@ -325,15 +215,8 @@ handle /usaco/* {
|
||||
}
|
||||
|
||||
# ---- Activity tracker (/tracker/) ----
|
||||
# Its own container (the adamf/ccp repo): an ingest API for device collectors,
|
||||
# which send batches of events with a per-device bearer key, plus a dashboard
|
||||
# and setup page. Gated like /sb/ (the app also checks the session itself),
|
||||
# with two exceptions ahead of it: the API, which collectors call with bearer
|
||||
# keys and no cookies (the app guards each route, by device key, admin
|
||||
# session or either), and the public userscript. Unlike /jobs/ the prefix IS
|
||||
# stripped: the server serves /api/v1/... and /readyz from /. Collectors must
|
||||
# use the www host: the apex 301 would turn their POSTs into GETs. Health Auto
|
||||
# Export bodies can be several MB; the 50 MB default above covers them.
|
||||
# The collector API (bearer keys) and the userscript bypass the gate.
|
||||
# Collectors must use www: the apex 301 turns POSTs into GETs.
|
||||
handle /tracker/api/v1/* {
|
||||
import limit api 30 1s
|
||||
uri strip_prefix /tracker
|
||||
@@ -359,21 +242,10 @@ handle /tracker/* {
|
||||
}
|
||||
|
||||
# ---- Receipt printer (/receipt/) ----
|
||||
# The adamf/receipt_maker repo's `receipt serve`, running on stppi (not in
|
||||
# this stack: that machine reaches the printer on the home LAN), reached over
|
||||
# Tailscale by IP. A page for printing a note or an uploaded image, plus its
|
||||
# API. Behind the permission gate on `receipt`, so an account granted it in
|
||||
# the admin panel can print without being an admin; the prefix IS stripped.
|
||||
# The server trusts nothing without X-Receipt-Token, which only this proxy
|
||||
# adds (header_up replaces any copy the client sent), and is told who is
|
||||
# printing in X-Remote-User, which the gate sets.
|
||||
#
|
||||
# A `route`, so the steps run in the order written: receipt_upstream is set
|
||||
# only after the gate has passed, so `errors` reports "printer offline" for a
|
||||
# failed dial to stppi and not for a backend outage during the auth check.
|
||||
# Its own zone, not `api`: a zone name must always carry the same numbers.
|
||||
# 17 MB: the server caps uploads at 16 MB, plus room for the multipart
|
||||
# framing around one.
|
||||
# Runs on stppi (it is on the printer's LAN), reached over Tailscale.
|
||||
# header_up replaces any client-sent X-Receipt-Token. A `route` so the
|
||||
# receipt_upstream var is set only after the gate passes, so a backend outage
|
||||
# is not reported as "printer offline". 17 MB: 16 MB uploads plus framing.
|
||||
handle /receipt/* {
|
||||
route {
|
||||
import limit receipt 10 1s
|
||||
@@ -386,8 +258,7 @@ handle /receipt/* {
|
||||
reverse_proxy {$RECEIPT_WEB_UPSTREAM} {
|
||||
import proxy
|
||||
header_up X-Receipt-Token {env.RECEIPT_WEB_TOKEN}
|
||||
# Caddy's default, spelt out: when stppi is off, fail fast and
|
||||
# let `errors` answer.
|
||||
# Fail fast when stppi is off.
|
||||
transport http {
|
||||
dial_timeout 3s
|
||||
}
|
||||
@@ -397,10 +268,7 @@ handle /receipt/* {
|
||||
|
||||
# ---- Uploads (/uploads/) ----
|
||||
|
||||
# PRIVATE attachments (admin-only): files on *private* chat messages, which
|
||||
# the backend always writes to disk, at uploads/private/. Ahead of the public
|
||||
# route below, and matched on the cleaned, lower-cased path, so no spelling of
|
||||
# a path into private/ reaches the ungated one.
|
||||
# Private chat attachments, always on disk. Must precede /uploads/*.
|
||||
handle /uploads/private/* {
|
||||
import admin_gate
|
||||
import upload_headers
|
||||
@@ -408,20 +276,8 @@ handle /uploads/private/* {
|
||||
file_server
|
||||
}
|
||||
|
||||
# GARAGE FIRST, DISK SECOND. /uploads/<name> is fetched from the Garage
|
||||
# bucket's website endpoint, which serves the bucket anonymously and picks it
|
||||
# by the Host header (garage/garage.toml: s3_web). The bucket is reachable
|
||||
# only over app-network, so this is the only public way in. If Garage has no
|
||||
# such file (404), errors (5xx), or cannot be reached at all (a dial error,
|
||||
# caught by `errors` through the uploads_fallback variable), the file is
|
||||
# served from the shared `uploads` volume instead (`uploads_disk`). That
|
||||
# volume holds uploads from before Garage and anything the backend wrote
|
||||
# there because Garage refused it (backend/services/uploads.go). So the bucket
|
||||
# is the source of truth (deleting a file in garage-webui unpublishes it
|
||||
# unless a disk copy exists), while a Garage outage only costs files that are
|
||||
# nowhere else. dial_timeout 2s: Garage is on the same bridge, so a slow
|
||||
# connect means it is down; fall back quickly. Range requests pass through
|
||||
# either way, so video seeks.
|
||||
# Garage first, disk second: a 404, 5xx or dial error falls back to the
|
||||
# volume, so the bucket is the source of truth.
|
||||
handle /uploads/* {
|
||||
import upload_headers
|
||||
vars uploads_fallback yes
|
||||
|
||||
Reference in New Issue
Block a user