auth: add AUTH_MODE=access (Cloudflare Access JWT)

For running behind Cloudflare Access on stppriv, where the main site's
cookie is not sent. Verifies Cf-Access-Jwt-Assertion (or the
CF_Authorization cookie) as RS256 against the team's certs, with issuer
and audience checks. Default mode is still forward.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-26 13:34:03 +00:00
co-authored by Claude Opus 5.5
parent acc6876e33
commit 179463795b
4 changed files with 423 additions and 4 deletions
+11 -4
View File
@@ -50,13 +50,20 @@ func main() {
// AUTH
// Settled before anything else, so a bad mode fails fast.
// "forward" (the default) asks the main site; "dev" admits everyone and
// is refused outside DEV_MODE, so a stray setting cannot open the
// tracker in production.
// "forward" (the default) asks the main site; "access" verifies the
// Cloudflare Access JWT (on stppriv, where the main site's cookie is not
// sent); "dev" admits everyone and is refused outside DEV_MODE, so a
// stray setting cannot open the tracker in production.
var checker auth.Checker
switch mode := getenv("AUTH_MODE", "forward"); mode {
case "forward":
checker = auth.NewForward(getenv("AUTH_VALIDATE_URL", "http://backend:8080/auth/validate-admin"))
case "access":
a, err := auth.NewAccess(os.Getenv("ACCESS_TEAM_DOMAIN"), os.Getenv("ACCESS_AUD"))
if err != nil {
log.Fatalf("AUTH_MODE=access: %v", err)
}
checker = a
case "dev":
if !devMode {
log.Fatal("AUTH_MODE=dev is only allowed with DEV_MODE=true")
@@ -64,7 +71,7 @@ func main() {
log.Println("[Auth] AUTH_MODE=dev: every request is treated as the admin")
checker = auth.AllowAll{}
default:
log.Fatalf("unknown AUTH_MODE %q (want forward or dev)", mode)
log.Fatalf("unknown AUTH_MODE %q (want forward, access or dev)", mode)
}
databaseURL := os.Getenv("DATABASE_URL")