hub v0.152.0: operator access tokens with scopes (09 §3 decision 251, operator 2026-10-15 11:38)
gates / gates (push) Successful in 6m44s
gates / gates (push) Successful in 6m44s
- Configuration → Access tokens: named, scoped (group read/write), expiring (≤365 d), shown once, stored SHA-256 only, every use logged by name. Bearer fhp_… on the web surface only; /api/v1 refuses it. - Route table = the code's single source (web/routes.go), pinned to ServeHTTP's switch; session-only: secrets shown/minted, deletes/resets, password, tokens. - R-952 closed: /api/v1 route table names each caller, pinned to the switch; no-credential refusal test. - Fail-open fixed: an empty operator password served the UI open (main skipped RequireAuth). Live hub never open. - 05 §17, 04 §6.2, 13, 09 §3 251; register 155→157 (+R-1054, R-1055, R-1056, −R-952); STATUS. - website: prowlarr-logo.svg (byte copy from felhom.eu-media) — the site gate refused every push. Not deployed — waits for the operator's yes. Claude-Session: https://claude.ai/code/session_012qRErfCoiTkvDK9N5XHbzb
This commit is contained in:
1 parent
e92501f5a1
commit
d62cc08b2e
37 files changed
+2567
-21
No files matched your search
@@ -712,6 +712,19 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
// Access tokens (v0.152.0, `05` §17) — session only (routes.go), each handler checks again.
|
||||
case path == "/configuration/tokens":
|
||||
if r.Method == http.MethodPost {
|
||||
s.handleTokenCreate(w, r)
|
||||
} else {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
case strings.HasPrefix(path, "/configuration/tokens/") && strings.HasSuffix(path, "/revoke"):
|
||||
if r.Method == http.MethodPost {
|
||||
s.handleTokenRevoke(w, r, strings.TrimSuffix(strings.TrimPrefix(path, "/configuration/tokens/"), "/revoke"))
|
||||
} else {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
case strings.HasPrefix(path, "/configs/") && strings.HasSuffix(path, "/delete"):
|
||||
// Customer DELETE cascade (v0.69.0, R-25b): GET returns the guided dialog's live inventory
|
||||
// (hosts + offsite + PBS + custody + any incomplete journal), POST runs the full teardown.
|
||||
@@ -861,9 +874,19 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// RequireAuth wraps a handler with session or basic authentication.
|
||||
func (s *Server) RequireAuth(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Skip auth if no password configured
|
||||
// No operator password configured → every operator route is CLOSED (v0.152.0). Before, this
|
||||
// branch served everything with no credential, and main.go did not even mount RequireAuth when
|
||||
// the ConfigMap seed was empty — so a hub whose password lived only in the DB override, or a
|
||||
// manifest that lost auth.password_hash, served the whole operator UI open. The public /bind/
|
||||
// surface does not depend on the operator password and stays up; /login renders but cannot
|
||||
// succeed. Pinned by TestRequireAuth_NoPasswordRefusesEveryOperatorRoute.
|
||||
if s.effectivePasswordHash() == "" {
|
||||
next.ServeHTTP(w, r)
|
||||
if isPublicBindPath(r.URL.Path) || r.URL.Path == "/login" {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
s.logger.Printf("[ERROR] operator route refused: no operator password is configured — %s %s", r.Method, r.URL.Path)
|
||||
http.Error(w, "Service unavailable: no operator password is configured", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -877,6 +900,13 @@ func (s *Server) RequireAuth(next http.Handler) http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
// An access token (v0.152.0, `05` §17) is decided by its scopes alone — it never falls through
|
||||
// to the session or Basic paths, so a token request is never full operator.
|
||||
if tok := bearerToken(r); tok != "" {
|
||||
s.serveWithToken(w, r, next, tok)
|
||||
return
|
||||
}
|
||||
|
||||
// Check session cookie (random token stored server-side)
|
||||
if cookie, err := r.Cookie(SessionCookieName); err == nil {
|
||||
s.sessionsMu.RLock()
|
||||
@@ -976,6 +1006,11 @@ const OperatorCLIHeader = "X-Felhom-Operator"
|
||||
// Before v0.135.0 a request with no session cookie passed unconditionally (measured live: a Basic-auth
|
||||
// POST with no cookie reached the handler).
|
||||
func (s *Server) validateCSRF(r *http.Request) bool {
|
||||
// An access token is not a credential a browser sends on its own (tokens.go explains); the token
|
||||
// path in RequireAuth has already checked it and its scope for this route.
|
||||
if requestToken(r) != nil {
|
||||
return true
|
||||
}
|
||||
cookie, err := r.Cookie(SessionCookieName)
|
||||
if err != nil {
|
||||
_, _, basic := r.BasicAuth()
|
||||
@@ -1163,6 +1198,11 @@ func statusColor(status string) string {
|
||||
|
||||
// handleConfiguration renders the Configuration page.
|
||||
func (s *Server) handleConfiguration(w http.ResponseWriter, r *http.Request) {
|
||||
s.renderConfiguration(w, r, nil)
|
||||
}
|
||||
|
||||
// renderConfiguration renders the page; created is a token minted by this very request, shown once (tokens.go).
|
||||
func (s *Server) renderConfiguration(w http.ResponseWriter, r *http.Request, created *createdToken) {
|
||||
csrfToken := s.getCSRFToken(r)
|
||||
|
||||
assetCount := 0
|
||||
@@ -1201,6 +1241,16 @@ func (s *Server) handleConfiguration(w http.ResponseWriter, r *http.Request) {
|
||||
"AgentChoices": agentChoices,
|
||||
"GoldenChoices": goldenChoices,
|
||||
"Flash": r.URL.Query().Get("flash"),
|
||||
// Access tokens (v0.152.0): the card is managed only from a session — a token-authenticated
|
||||
// read of this page gets no token list (routes.go: token management is session only).
|
||||
"ShowTokens": requestToken(r) == nil,
|
||||
"TokenGroups": scopeGroups,
|
||||
"TokenDays": tokenDaysChoices,
|
||||
"TokenDefaultDays": tokenDefaultDays,
|
||||
"CreatedToken": created,
|
||||
}
|
||||
if requestToken(r) == nil {
|
||||
data["Tokens"] = s.tokenRows()
|
||||
}
|
||||
if err := s.templates.ExecuteTemplate(w, "configuration.html", data); err != nil {
|
||||
s.logger.Printf("[ERROR] configuration.html template: %v", err)
|
||||
|
||||
Reference in new issue
Block a user