Cut the edge over from nginx and certbot to Caddy
Caddy takes nginx's place in compose: ports 80/443, the fixed address 172.28.255.251 that cloudflared pins the public names to, the network aliases, the healthcheck and the autoheal label. nginx and certbot are removed from compose; Caddy already holds its own certificates in ./caddy/data, obtained while it ran beside nginx. `traffic` now tails logs/caddy/payloads.log, and the dev override switches Caddy to its dev sites instead of putting nginx in DEV_MODE. Docs and comments that described nginx's behaviour now describe Caddy's: CLAUDE.md, DEPLOYMENT.md (topology, boot paths, TLS, rate limits, runbook with a rollback, rough edges), the READMEs, .env.example and the comments in the backend, Python service, Vue source and infra files. nginx/ and certbot/ stay in the repo as the rollback until this has settled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -10,17 +10,17 @@ import (
|
||||
// service (the receipt printer, say) without being made an admin.
|
||||
//
|
||||
// A permission is a key from PermissionTypes stored in models.User.Permissions.
|
||||
// nginx gates a service on one key by asking GET /auth/validate/<key>
|
||||
// Caddy gates a service on one key by asking GET /auth/validate/<key>
|
||||
// (handlers.Store.ValidatePermission); admins pass every such check, so
|
||||
// moving a service from the admin gate to a permission gate never locks an
|
||||
// admin out. Services that are not listed here stay admin-only.
|
||||
//
|
||||
// Adding a grantable service is one entry below plus swapping that location's
|
||||
// nginx gate from /internal/auth/admin-validate to the permission gate (see
|
||||
// "Permission gate" in nginx/nginx_routes.conf.template).
|
||||
// Adding a grantable service is one entry below plus swapping its route in
|
||||
// caddy/routes.caddy from `import admin_gate` to `import permission_gate
|
||||
// <key>` (the snippet is in caddy/Caddyfile).
|
||||
|
||||
// PermissionType describes one grantable service. Key is what is stored and
|
||||
// what nginx names; Label and Path are for the admin panel's checkboxes and
|
||||
// what Caddy names; Label and Path are for the admin panel's checkboxes and
|
||||
// the signed-in user's /account list of links.
|
||||
type PermissionType struct {
|
||||
Key string
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestValidPermission(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Keys must be URL-path safe: nginx splices them into /auth/validate/<key>.
|
||||
// Keys must be URL-path safe: Caddy splices them into /auth/validate/<key>.
|
||||
func TestPermissionKeysArePathSafe(t *testing.T) {
|
||||
seen := map[string]bool{}
|
||||
for _, p := range PermissionTypes {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// (handlers/handle_rowing.go); the job posting reader, email classifier and
|
||||
// lead scorer went with the job tracker to its own repo.
|
||||
//
|
||||
// The routes are internal in a specific sense: nginx answers 404 for
|
||||
// The routes are internal in a specific sense: Caddy answers 404 for
|
||||
// /py/internal/, and each route itself refuses a request carrying a proxy
|
||||
// header, so the only way in is this direct container-to-container call. That
|
||||
// is why the request below sets nothing but Content-Type.
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestCallPythonRequestAndReply(t *testing.T) {
|
||||
)
|
||||
url := pythonStub(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
method, path, contentType = r.Method, r.URL.Path, r.Header.Get("Content-Type")
|
||||
// The Python routes treat either header as "came through nginx" and
|
||||
// The Python routes treat either header as "came through Caddy" and
|
||||
// answer 404, so the helper must never send them.
|
||||
forwarded = r.Header.Get("X-Real-IP") != "" || r.Header.Get("X-Forwarded-For") != ""
|
||||
if err := json.NewDecoder(r.Body).Decode(&got); err != nil {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// RateLimiter is an in-memory sliding-window limiter keyed by an arbitrary
|
||||
// string (in practice the client IP). It is process-local: restarting the
|
||||
// backend clears every window, and a multi-replica deployment would limit
|
||||
// per replica rather than globally. Nginx applies its own rate limits in
|
||||
// per replica rather than globally. Caddy applies its own rate limits in
|
||||
// front of this, so this layer is a second line of defence, not the only one.
|
||||
type RateLimiter struct {
|
||||
mu sync.Mutex
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
// site owner scanning the log for "who is using my site". Two goals:
|
||||
//
|
||||
// 1. Quietness. The log is flooded by traffic that is not a human visit:
|
||||
// nginx auth_request subrequests (/auth/validate-admin, re-run for every
|
||||
// Caddy forward_auth subrequests (/auth/validate-admin, re-run for every
|
||||
// admin page hit), the front end's own polling (`/auth/refresh_token`,
|
||||
// home-data refreshes), and Vite dev asset fetches. Each is collapsed to
|
||||
// a single terse line, or dropped entirely when repeated in a short
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
// logQuietDrop lists paths whose 2xx responses are dropped outright. These
|
||||
// are all heartbeat-style endpoints: identical every few seconds, no signal.
|
||||
var logQuietDrop = map[string]bool{
|
||||
"/auth/validate-admin": true, // nginx auth_request subrequest
|
||||
"/auth/validate-admin": true, // Caddy forward_auth subrequest
|
||||
"/auth/refresh": true, // front-end token refresh
|
||||
"/auth/check": true, // front-end session check
|
||||
}
|
||||
@@ -76,7 +76,7 @@ func TrafficLogFormatter(params gin.LogFormatterParams) string {
|
||||
fmt.Sprintf("%.0f%s", float64(latency), unit), marker)
|
||||
|
||||
// Visitor traffic gets the IP appended — the "who". Infrastructure
|
||||
// traffic (nginx's own feet on the internal subnet) already has its IP
|
||||
// traffic (the edge's own feet on the internal subnet) already has its IP
|
||||
// implied and is left lean.
|
||||
if params.StatusCode >= 400 || logIsInterestingClient(params.ClientIP) {
|
||||
line += " " + params.ClientIP
|
||||
@@ -86,10 +86,10 @@ func TrafficLogFormatter(params gin.LogFormatterParams) string {
|
||||
}
|
||||
|
||||
// logIsInterestingClient reports whether a client IP is likely an actual
|
||||
// visitor rather than infrastructure. nginx proxies everything, so the IPs
|
||||
// visitor rather than infrastructure. Caddy proxies everything, so the IPs
|
||||
// that appear are either forwarded-from-humans or the ingress itself.
|
||||
func logIsInterestingClient(ip string) bool {
|
||||
// Docker's bridge network: nginx's own feet. Not a visitor.
|
||||
// Docker's bridge network: the edge's own feet. Not a visitor.
|
||||
return !startsWith(ip, "172.28.")
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -34,26 +34,26 @@ import (
|
||||
//
|
||||
// WHERE FILES GO
|
||||
// Public files go to the Garage bucket `uploads` (garage/garage.toml), with
|
||||
// the `uploads` volume as a fallback for when Garage refuses a write. nginx
|
||||
// the `uploads` volume as a fallback for when Garage refuses a write. Caddy
|
||||
// mirrors that: /uploads/<name> is fetched from the bucket first and the
|
||||
// volume second (nginx.conf.template), so the URL is the same wherever the
|
||||
// volume second (caddy/routes.caddy), so the URL is the same wherever the
|
||||
// file landed. With S3_ENDPOINT unset there is no bucket and the volume is
|
||||
// the only store.
|
||||
// Private files (admin-only chat attachments) always go to the volume, under
|
||||
// /uploads/private/, which nginx gates behind an admin check. nginx can't
|
||||
// /uploads/private/, which Caddy gates behind an admin check. Caddy can't
|
||||
// sign S3 requests, so it has no way to gate a bucket.
|
||||
//
|
||||
// Everything public is reachable by anyone who has the URL, with no login.
|
||||
// That is why the type checks below are strict, and why names are random.
|
||||
|
||||
// MaxUploadSize caps one upload. It bounds how fast one account can fill the
|
||||
// disk or the bucket; nginx rate-limits the route as well.
|
||||
// disk or the bucket; Caddy rate-limits the route as well.
|
||||
const MaxUploadSize = 10 << 20 // 10MB
|
||||
|
||||
// UploadType describes one allowed file extension.
|
||||
type UploadType struct {
|
||||
// ContentType is stored with the file and served back with it. Garage
|
||||
// returns exactly this, and the browser renders by it: nginx adds
|
||||
// returns exactly this, and the browser renders by it: Caddy adds
|
||||
// `nosniff`, so a wrong type means the file doesn't display.
|
||||
ContentType string
|
||||
// SniffPrefix is what http.DetectContentType must report for the file's
|
||||
@@ -100,7 +100,7 @@ type Uploads struct {
|
||||
private FileStore
|
||||
}
|
||||
|
||||
// URL prefixes the files are served under; nginx owns both paths.
|
||||
// URL prefixes the files are served under; Caddy owns both paths.
|
||||
const (
|
||||
publicURLPrefix = "/uploads/"
|
||||
privateURLPrefix = "/uploads/private/"
|
||||
@@ -238,7 +238,7 @@ type FileStore interface {
|
||||
type DiskFileStore struct{ Dir string }
|
||||
|
||||
func (d DiskFileStore) Put(_ context.Context, key, _ string, r io.ReadSeeker, _ int64) error {
|
||||
// 0755 and 0644 so nginx, a different user, can reach and read the files.
|
||||
// 0755 and 0644 so the edge, in another container, can reach and read the files.
|
||||
if err := os.MkdirAll(d.Dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -334,7 +334,7 @@ func (s *S3FileStore) Put(ctx context.Context, key, contentType string, r io.Rea
|
||||
|
||||
// List pages through the whole bucket. Keys containing "/" are skipped: they
|
||||
// are not uploads (Save never makes one) but something put under a prefix by
|
||||
// hand, and nginx's /uploads/<name> only ever serves a top-level name anyway.
|
||||
// hand, and Caddy's /uploads/<name> only ever serves a top-level name anyway.
|
||||
func (s *S3FileStore) List(ctx context.Context) ([]StoredFile, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, s3Timeout)
|
||||
defer cancel()
|
||||
@@ -358,7 +358,7 @@ func (s *S3FileStore) List(ctx context.Context) ([]StoredFile, error) {
|
||||
}
|
||||
|
||||
// FallbackFileStore tries Primary and, if that fails, logs it and writes to
|
||||
// Fallback instead. The upload still succeeds and its URL still works (nginx
|
||||
// Fallback instead. The upload still succeeds and its URL still works (Caddy
|
||||
// looks in both places), so a Garage outage costs a log line rather than
|
||||
// broken uploads.
|
||||
type FallbackFileStore struct {
|
||||
@@ -378,7 +378,7 @@ func (f FallbackFileStore) Put(ctx context.Context, key, contentType string, r i
|
||||
return f.Fallback.Put(ctx, key, contentType, r, size)
|
||||
}
|
||||
|
||||
// List is the union of both stores, since nginx serves from both: the
|
||||
// List is the union of both stores, since Caddy serves from both: the
|
||||
// fallback holds whatever was written while the primary was down (and, on
|
||||
// the live volume, the pre-Garage copies). A name in both is listed once,
|
||||
// with the primary's details. A primary that can't list is logged and the
|
||||
|
||||
Reference in New Issue
Block a user