stppriv's Caddy asks /api/auth/validate-admin for every request it gates, all from its one LAN IP, which would exhaust the 30/s per-IP api bucket on a SilverBullet page load. Requests from STPPRIV_LAN_IP to that one path go straight to the backend. Public traffic always arrives from cloudflared's address, so it cannot match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
311 lines
7.8 KiB
Plaintext
311 lines
7.8 KiB
Plaintext
# 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.
|
|
|
|
# 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
|
|
}
|
|
|
|
# ---- Denials -----------------------------------------------------------------
|
|
|
|
# Called by the backend over app-network only; spends paid Claude calls.
|
|
handle /py/internal/* {
|
|
respond 404
|
|
}
|
|
|
|
# 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
|
|
}
|
|
|
|
@notes_dot path_regexp ^/notes/.+/\.
|
|
handle @notes_dot {
|
|
respond 404
|
|
}
|
|
|
|
handle /notes/.revisions* {
|
|
respond 404
|
|
}
|
|
|
|
# ---- Bare prefixes and moved URLs ----------------------------------------------
|
|
# Exact paths, so /gitea-something is left to the SPA.
|
|
redir {$BACKEND_ENDPOINT} {$BACKEND_ENDPOINT}/ 301
|
|
redir /radio /radio/ 301
|
|
redir /dozzle /dozzle/ 301
|
|
redir /garage /garage/ 301
|
|
redir /gitea https://git.{$DOMAIN}/ 301
|
|
redir /notes /notes/ 301
|
|
redir /sb /sb/ 301
|
|
redir /py /py/ 301
|
|
redir /jobs /jobs/ 301
|
|
redir /usaco /usaco/ 301
|
|
redir /tracker /tracker/ 301
|
|
redir /receipt /receipt/ 301
|
|
|
|
# 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 ---------------------------------------------------------------
|
|
|
|
# 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} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# stppriv's admin_gate checks every one of its requests here from one LAN IP,
|
|
# so it would exhaust the per-IP api limit. Public traffic always arrives from
|
|
# cloudflared, so it can never match.
|
|
@stppriv_gate {
|
|
path {$BACKEND_ENDPOINT}/auth/validate-admin
|
|
remote_ip {$STPPRIV_LAN_IP}
|
|
}
|
|
handle @stppriv_gate {
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# On top of the backend's own 5/min.
|
|
handle {$BACKEND_ENDPOINT}/auth/login* {
|
|
import limit login 5 1m
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
handle {$BACKEND_ENDPOINT}/uploads* {
|
|
import limit upload 30 1m
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# One GraphQL query can be arbitrarily expensive.
|
|
handle {$BACKEND_ENDPOINT}/graphql* {
|
|
import limit graphql 10 1s
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
handle {$BACKEND_ENDPOINT}/* {
|
|
import limit api 30 1s
|
|
uri strip_prefix {$BACKEND_ENDPOINT}
|
|
reverse_proxy {$BACKEND_HOST}:{$BACKEND_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# ---- Admin-gated services ------------------------------------------------------
|
|
|
|
# Docker socket access is root on the host.
|
|
handle /dozzle/* {
|
|
import admin_gate
|
|
reverse_proxy dozzle:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# Holds Garage's admin token. 2 GB for video uploads.
|
|
handle /garage/* {
|
|
import admin_gate
|
|
request_body {
|
|
max_size 2GB
|
|
}
|
|
reverse_proxy garage-webui:3909 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# Station-control UI guarded only by the icecast password.
|
|
handle /radio/admin/* {
|
|
import admin_gate
|
|
uri strip_prefix /radio
|
|
reverse_proxy {$ICECAST_HOST}:{$ICECAST_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# 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} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# ---- Public services -----------------------------------------------------------
|
|
|
|
handle /radio/* {
|
|
uri strip_prefix /radio
|
|
reverse_proxy {$ICECAST_HOST}:{$ICECAST_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# Gitea is at git.DOMAIN; the registry at /v2/ is still proxied (prod.caddy).
|
|
handle_path /gitea/* {
|
|
redir https://git.{$DOMAIN}{uri} 301
|
|
}
|
|
|
|
# No prefix strip (SB_URL_PREFIX=/notes).
|
|
handle /notes/* {
|
|
reverse_proxy {$SILVERBULLET_PUBLIC_HOST}:{$SILVERBULLET_PUBLIC_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# 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
|
|
uri strip_prefix /py
|
|
reverse_proxy {$PYTHON_HOST}:{$PYTHON_PORT} {
|
|
import proxy
|
|
flush_interval -1
|
|
}
|
|
}
|
|
|
|
handle /py/* {
|
|
import limit api 30 1s
|
|
uri strip_prefix /py
|
|
reverse_proxy {$PYTHON_HOST}:{$PYTHON_PORT} {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# ---- Job tracker (/jobs/) ----
|
|
# 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 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
handle /jobs/job-capture.user.js {
|
|
reverse_proxy jobs:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
handle /jobs/* {
|
|
import admin_gate
|
|
import limit api 30 1s
|
|
reverse_proxy jobs:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# ---- 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 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# ---- Activity tracker (/tracker/) ----
|
|
# 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
|
|
reverse_proxy activity-tracker:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
handle /tracker/tracker.user.js {
|
|
uri strip_prefix /tracker
|
|
reverse_proxy activity-tracker:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
handle /tracker/* {
|
|
import admin_gate
|
|
import limit api 30 1s
|
|
uri strip_prefix /tracker
|
|
reverse_proxy activity-tracker:8080 {
|
|
import proxy
|
|
}
|
|
}
|
|
|
|
# ---- Receipt printer (/receipt/) ----
|
|
# 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
|
|
request_body {
|
|
max_size 17MB
|
|
}
|
|
import permission_gate receipt
|
|
vars receipt_upstream yes
|
|
uri strip_prefix /receipt
|
|
reverse_proxy {$RECEIPT_WEB_UPSTREAM} {
|
|
import proxy
|
|
header_up X-Receipt-Token {env.RECEIPT_WEB_TOKEN}
|
|
# Fail fast when stppi is off.
|
|
transport http {
|
|
dial_timeout 3s
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---- Uploads (/uploads/) ----
|
|
|
|
# Private chat attachments, always on disk. Must precede /uploads/*.
|
|
handle /uploads/private/* {
|
|
import admin_gate
|
|
import upload_headers
|
|
root * /srv
|
|
file_server
|
|
}
|
|
|
|
# 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
|
|
uri strip_prefix /uploads
|
|
reverse_proxy garage:3902 {
|
|
import proxy
|
|
header_up Host uploads.web.garage
|
|
transport http {
|
|
dial_timeout 2s
|
|
}
|
|
@not_in_bucket status 404 5xx
|
|
handle_response @not_in_bucket {
|
|
import uploads_disk
|
|
}
|
|
}
|
|
}
|