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:
+8
-5
@@ -60,8 +60,8 @@ backend icecast2 gitea sb sb-pub python | |
|
|||||||
| silverbullet-public (notes site) | `${SILVERBULLET_PUBLIC_HOST}` | `${SILVERBULLET_PUBLIC_PORT}` | `/notes/` (**public**, read-only) | no |
|
| silverbullet-public (notes site) | `${SILVERBULLET_PUBLIC_HOST}` | `${SILVERBULLET_PUBLIC_PORT}` | `/notes/` (**public**, read-only) | no |
|
||||||
| silverbullet-git | n/a | n/a | none (timer loop) | no |
|
| silverbullet-git | n/a | n/a | none (timer loop) | no |
|
||||||
| python (FastAPI) | `${PYTHON_HOST}` | `${PYTHON_PORT}` | `/py/`, docs at `/py/docs` | no |
|
| python (FastAPI) | `${PYTHON_HOST}` | `${PYTHON_PORT}` | `/py/`, docs at `/py/docs` | no |
|
||||||
| jobs (job tracker, published image) | `jobs` | 8080 | `/jobs/` (admin-gated by the app itself) | no |
|
| jobs (job tracker, published image) | `jobs` | 8080 | `/jobs/` (admin-gated by nginx `auth_request`; capture API and userscript public, bearer-token) | no |
|
||||||
| activity-tracker (published image, adamf/ccp) | `activity-tracker` | 8080 | `/tracker/`, prefix stripped (collectors: per-device bearer keys; pages: admin-gated by the app itself) | no |
|
| activity-tracker (published image, adamf/ccp) | `activity-tracker` | 8080 | `/tracker/`, prefix stripped (pages admin-gated by nginx `auth_request`; `/api/v1/` bearer/app-checked) | no |
|
||||||
| icecast2 + liquidsoap | `${ICECAST_HOST}` | `${ICECAST_PORT}` | `/radio/` | **harbor port only** |
|
| icecast2 + liquidsoap | `${ICECAST_HOST}` | `${ICECAST_PORT}` | `/radio/` | **harbor port only** |
|
||||||
| gitea | `${GITEA_HOST}` | 3000, 2222 | `/gitea/` | **3000, 2222** |
|
| gitea | `${GITEA_HOST}` | 3000, 2222 | `/gitea/` | **3000, 2222** |
|
||||||
| vue | `vue` | 5173 (dev only) | `/` (dev only) | no |
|
| vue | `vue` | 5173 (dev only) | `/` (dev only) | no |
|
||||||
@@ -86,9 +86,12 @@ in one step — never change one without the other.**
|
|||||||
- **Per-request DNS.** Upstreams go through `set $upstream_* ...` variables with
|
- **Per-request DNS.** Upstreams go through `set $upstream_* ...` variables with
|
||||||
`resolver 127.0.0.11`, so names resolve per request. nginx boots fine with a
|
`resolver 127.0.0.11`, so names resolve per request. nginx boots fine with a
|
||||||
backend down (502s until it appears) instead of refusing to start.
|
backend down (502s until it appears) instead of refusing to start.
|
||||||
- **Admin gate.** `/sb/`, `/radio/admin/` and `/uploads/private/` are protected by an `auth_request`
|
- **Admin gate.** `/sb/`, `/jobs/`, `/tracker/`, `/radio/admin/` and `/uploads/private/` are
|
||||||
subrequest to the backend's `/auth/validate-admin`; a failure redirects to the
|
protected by an `auth_request` subrequest to the backend's `/auth/validate-admin`; a failure
|
||||||
SPA login. None of these services has any auth of its own at that path.
|
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
|
||||||
|
cookie never reaches, stay public at nginx and are guarded by bearer tokens in the apps:
|
||||||
|
`/jobs/api/capture` and `/jobs/job-capture.user.js`, `/tracker/api/v1/` and `/tracker/tracker.user.js`.
|
||||||
- **Public notes privacy boundary.** `/notes/` is public, and the only thing
|
- **Public notes privacy boundary.** `/notes/` is public, and the only thing
|
||||||
keeping `private/` (and `templates/`, `.git`, `.obsidian`) off it is a pair of
|
keeping `private/` (and `templates/`, `.git`, `.obsidian`) off it is a pair of
|
||||||
nginx deny blocks. SilverBullet's `SB_SPACE_IGNORE` only hides paths from its
|
nginx deny blocks. SilverBullet's `SB_SPACE_IGNORE` only hides paths from its
|
||||||
|
|||||||
+9
-6
@@ -482,9 +482,11 @@ services:
|
|||||||
# database role of its own. A variable the tracker reads must be added to
|
# database role of its own. A variable the tracker reads must be added to
|
||||||
# the list below as well as .env.example.
|
# the list below as well as .env.example.
|
||||||
#
|
#
|
||||||
# It has no login. AUTH_VALIDATE_URL is the backend's validate-admin route
|
# It has no login. nginx's auth_request gates /jobs/ like /sb/ (except the
|
||||||
# (the one nginx's auth_request uses), which the tracker asks with the
|
# bearer-token capture API and the userscript), and the tracker checks
|
||||||
# visitor's cookies on each admin request.
|
# again itself: AUTH_VALIDATE_URL is the backend's validate-admin route
|
||||||
|
# (the one nginx's auth_request uses), which it asks with the visitor's
|
||||||
|
# cookies on each admin request.
|
||||||
#
|
#
|
||||||
# ./jobs-data holds the Microsoft Graph session and the capture token. The
|
# ./jobs-data holds the Microsoft Graph session and the capture token. The
|
||||||
# image runs as uid 1000, so the directory must be owned by it.
|
# image runs as uid 1000, so the directory must be owned by it.
|
||||||
@@ -564,9 +566,10 @@ services:
|
|||||||
# Two kinds of auth. Collectors send per-device bearer keys, made on the
|
# Two kinds of auth. Collectors send per-device bearer keys, made on the
|
||||||
# tracker's /tracker/setup page or with `docker exec activity-tracker
|
# tracker's /tracker/setup page or with `docker exec activity-tracker
|
||||||
# tracker apikey create`. The dashboard and setup pages have no login of
|
# tracker apikey create`. The dashboard and setup pages have no login of
|
||||||
# their own: like jobs, the tracker asks AUTH_VALIDATE_URL (the backend's
|
# their own: nginx's auth_request gates them like /sb/ (everything but
|
||||||
# validate-admin) with the visitor's cookies and sends anyone else to
|
# /tracker/api/v1/ and the userscript), and like jobs the tracker also asks
|
||||||
# /admin/login.
|
# AUTH_VALIDATE_URL (the backend's validate-admin) with the visitor's
|
||||||
|
# cookies and sends anyone else to /admin/login.
|
||||||
activity-tracker:
|
activity-tracker:
|
||||||
image: adam-french.co.uk/adamf/activity-tracker:${ACTIVITY_TRACKER_IMAGE_TAG:-latest}
|
image: adam-french.co.uk/adamf/activity-tracker:${ACTIVITY_TRACKER_IMAGE_TAG:-latest}
|
||||||
container_name: activity-tracker
|
container_name: activity-tracker
|
||||||
|
|||||||
@@ -372,15 +372,18 @@
|
|||||||
# ---- Job tracker (/jobs/) ----
|
# ---- Job tracker (/jobs/) ----
|
||||||
# Its own container (the adamf/job-tracker repo), which serves its SPA
|
# 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
|
# 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
|
# app is built to live at /jobs/. Gated like /sb/: everything under
|
||||||
# SPA's files are public, and every API route that is not checks the
|
# /jobs/ needs the admin session, checked here by auth_request before
|
||||||
# session itself, by asking the backend's validate-admin with the
|
# the app sees it (the app still checks the session itself too). Two
|
||||||
# visitor's cookies. ^~ so no regex location can claim a /jobs/ path.
|
# exceptions, below, that a session cookie can never reach. ^~ so no
|
||||||
|
# regex location can claim a /jobs/ path.
|
||||||
location = /jobs {
|
location = /jobs {
|
||||||
return 301 /jobs/;
|
return 301 /jobs/;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ^~ /jobs/ {
|
location ^~ /jobs/ {
|
||||||
|
auth_request /internal/auth/admin-validate;
|
||||||
|
error_page 401 403 = @auth_denied;
|
||||||
limit_req zone=api burst=20 nodelay;
|
limit_req zone=api burst=20 nodelay;
|
||||||
# "Sync now" on the Settings page runs a whole email sync before
|
# "Sync now" on the Settings page runs a whole email sync before
|
||||||
# answering.
|
# answering.
|
||||||
@@ -392,6 +395,29 @@
|
|||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
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/) ----
|
# ---- USACO practice log (/usaco/) ----
|
||||||
# Its own container (the usaco repo's site/), shaped like /jobs/: SPA
|
# Its own container (the usaco repo's site/), shaped like /jobs/: SPA
|
||||||
# and API under one prefix that is NOT stripped, and no
|
# and API under one prefix that is NOT stripped, and no
|
||||||
@@ -417,19 +443,23 @@
|
|||||||
# ---- Activity tracker (/tracker/) ----
|
# ---- Activity tracker (/tracker/) ----
|
||||||
# Its own container (the adamf/ccp repo): an ingest API for device
|
# Its own container (the adamf/ccp repo): an ingest API for device
|
||||||
# collectors, which send batches of events with a per-device bearer
|
# 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
|
# key, plus a dashboard and setup page. Gated like /sb/: the pages
|
||||||
# no auth_request: the pages check the site session by asking the
|
# and their assets need the admin session, checked here by
|
||||||
# backend's validate-admin with the visitor's cookies, as /jobs/
|
# auth_request (the app also checks it itself). Two exceptions,
|
||||||
# does, and /tracker.user.js is public. Unlike /jobs/
|
# below: the API, which collectors call with bearer keys and no
|
||||||
# the prefix IS stripped: the server serves /api/v1/... and /readyz
|
# cookies (the app guards each route, by device key, admin session or
|
||||||
# from /. Collectors must use the www host: the apex 301 would turn
|
# either), and the public /tracker.user.js. Unlike /jobs/ the prefix
|
||||||
# their POSTs into GETs. Health Auto Export bodies can be several MB;
|
# IS stripped: the server serves /api/v1/... and /readyz from /.
|
||||||
# the server-wide 50M client_max_body_size covers them.
|
# 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 {
|
location = /tracker {
|
||||||
return 301 /tracker/;
|
return 301 /tracker/;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ^~ /tracker/ {
|
location ^~ /tracker/ {
|
||||||
|
auth_request /internal/auth/admin-validate;
|
||||||
|
error_page 401 403 = @auth_denied;
|
||||||
limit_req zone=api burst=20 nodelay;
|
limit_req zone=api burst=20 nodelay;
|
||||||
rewrite ^/tracker/(.*)$ /$1 break;
|
rewrite ^/tracker/(.*)$ /$1 break;
|
||||||
proxy_pass $upstream_tracker;
|
proxy_pass $upstream_tracker;
|
||||||
@@ -439,6 +469,25 @@
|
|||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
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
|
# Where the tracker used to be. The SPA routes were client-side, so
|
||||||
# these only catch bookmarks and typed URLs. The userscript's old
|
# these only catch bookmarks and typed URLs. The userscript's old
|
||||||
# @updateURL lands on the third, which is how installed copies find
|
# @updateURL lands on the third, which is how installed copies find
|
||||||
@@ -453,7 +502,7 @@
|
|||||||
return 301 /jobs/job-capture.user.js;
|
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;
|
# (/uploads/private/ is declared in the including template, not here;
|
||||||
# it points at the two locations below by name.)
|
# it points at the two locations below by name.)
|
||||||
# `auth_request` makes nginx fire a subrequest here before serving the
|
# `auth_request` makes nginx fire a subrequest here before serving the
|
||||||
|
|||||||
Reference in New Issue
Block a user