Gate /jobs/ and /tracker/ behind the nginx admin auth_request, like /sb/
The bearer-token routes a session cookie never reaches stay public at nginx and are guarded by the apps: /jobs/api/capture and the job-capture userscript, /tracker/api/v1/ and tracker.user.js. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -372,15 +372,18 @@
|
||||
# ---- Job tracker (/jobs/) ----
|
||||
# Its own container (the adamf/job-tracker repo), which serves its SPA
|
||||
# and its API from the same prefix. The prefix is NOT stripped: the
|
||||
# app is built to live at /jobs/. There is no auth_request here: the
|
||||
# SPA's files are public, and every API route that is not checks the
|
||||
# session itself, by asking the backend's validate-admin with the
|
||||
# visitor's cookies. ^~ so no regex location can claim a /jobs/ path.
|
||||
# app is built to live at /jobs/. Gated like /sb/: everything under
|
||||
# /jobs/ needs the admin session, checked here by auth_request before
|
||||
# the app sees it (the app still checks the session itself too). Two
|
||||
# exceptions, below, that a session cookie can never reach. ^~ so no
|
||||
# regex location can claim a /jobs/ path.
|
||||
location = /jobs {
|
||||
return 301 /jobs/;
|
||||
}
|
||||
|
||||
location ^~ /jobs/ {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
# "Sync now" on the Settings page runs a whole email sync before
|
||||
# answering.
|
||||
@@ -392,6 +395,29 @@
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# The capture API is called by the userscript from job sites' origins,
|
||||
# with the capture bearer token rather than cookies, so it cannot pass
|
||||
# the session gate; the app's CaptureTokenMiddleware guards it.
|
||||
location ^~ /jobs/api/capture {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
proxy_pass $upstream_jobs;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# The userscript itself: userscript managers fetch its @updateURL
|
||||
# without the session, and it holds no secrets (the token is entered
|
||||
# after install).
|
||||
location = /jobs/job-capture.user.js {
|
||||
proxy_pass $upstream_jobs;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# ---- 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
|
||||
@@ -417,19 +443,23 @@
|
||||
# ---- 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. The app does its own auth, so
|
||||
# no auth_request: the pages check the site session by asking the
|
||||
# backend's validate-admin with the visitor's cookies, as /jobs/
|
||||
# does, and /tracker.user.js is public. 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 server-wide 50M client_max_body_size covers them.
|
||||
# key, plus a dashboard and setup page. Gated like /sb/: the pages
|
||||
# and their assets need the admin session, checked here by
|
||||
# auth_request (the app also checks it itself). Two exceptions,
|
||||
# below: 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 /tracker.user.js. 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
|
||||
# server-wide 50M client_max_body_size covers them.
|
||||
location = /tracker {
|
||||
return 301 /tracker/;
|
||||
}
|
||||
|
||||
location ^~ /tracker/ {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
rewrite ^/tracker/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_tracker;
|
||||
@@ -439,6 +469,25 @@
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location ^~ /tracker/api/v1/ {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
rewrite ^/tracker/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_tracker;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location = /tracker/tracker.user.js {
|
||||
rewrite ^/tracker/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_tracker;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Where the 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
|
||||
@@ -453,7 +502,7 @@
|
||||
return 301 /jobs/job-capture.user.js;
|
||||
}
|
||||
|
||||
# ---- Admin gate (/sb/, /radio/admin/, /uploads/private/) ----
|
||||
# ---- Admin gate (/sb/, /jobs/, /tracker/, /radio/admin/, /uploads/private/) ----
|
||||
# (/uploads/private/ is declared in the including template, not here;
|
||||
# it points at the two locations below by name.)
|
||||
# `auth_request` makes nginx fire a subrequest here before serving the
|
||||
|
||||
Reference in New Issue
Block a user