Migrate auth to AuthGuard, retiring local Postgres-backed accounts
Lint / Lint (push) Failing after 32s
Tests / Go backend (push) Successful in 54s
Tests / Dashboard checks (push) Successful in 51s
Docker / Docker Build & Push (push) Successful in 5m14s

Same pattern as GameStream (commit 6a46007), adapted for CollabTable
being genuinely multi-user (not single-admin): admin user management
(list/create/update/delete, role reassignment, superadmin protection)
is fully proxied to AuthGuard, which already enforces the same rules
CollabTable checked locally. Cookie forwarding, no local session token,
AUTHGUARD_URL optional (unset = auth fully disabled), transport
failures always surface as errAuthGuardUnavailable rather than ever
letting a request through - proven with live tests against a closed
socket.

CollabTable's device-sync API token feature (separate from browser
sessions) is deliberately left local-only regardless of AUTHGUARD_URL,
keyed by a new currentUserID helper (AuthGuard's id when enabled, the
shared placeholder id 0 when disabled) - a real, functional token
either way, not faked data.

Real bug found and fixed: api_tokens.user_id had a hard FK into the
local auth_users table, which would reject new tokens once accounts
stop being written locally. Dropped the now-invalid FK.

Known, accepted gap (same as GameStream): self-service profile editing
for non-admin accounts is lost, since AuthGuard only exposes an admin
endpoint, no self-edit. TOTP QR issuer branding now comes from AuthGuard
rather than CollabTable.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-01 01:34:48 +02:00
1 parent a1c29728f0
commit 9a6ec940f7
48 files changed
+12401 -511

No files matched your search

+32 -17
View File
@@ -15,6 +15,8 @@ import (
"time"
_ "github.com/joho/godotenv/autoload"
authclient "repos.gfranz.ch/Gabriel20xx/shared/backend/authclient"
)
// The SvelteKit build is copied here by the Docker builder before go build.
@@ -50,7 +52,20 @@ func main() {
go database.pruneExpiredSessions(ctx)
go database.cleanupNotifications(ctx)
auth := newAuthService(database, strings.EqualFold(os.Getenv("COOKIE_SECURE"), "true"))
// AuthGuard is optional (see auth.go's top-of-file "Auth-disabled mode"
// section): a nil client means every request is treated as already
// authenticated, with nothing gated -- an explicit choice for local
// development or a standalone deployment, not a degraded fallback.
authGuardURL := strings.TrimSpace(os.Getenv("AUTHGUARD_URL"))
var authGuard *authclient.Client
if authGuardURL != "" {
authGuard = authclient.New(authGuardURL)
fmt.Printf("auth: AuthGuard at %s\n", authGuardURL)
} else {
fmt.Println("auth: DISABLED (AUTHGUARD_URL not set) -- every request is treated as authenticated")
}
auth := newAuthService(authGuard, database, strings.EqualFold(os.Getenv("COOKIE_SECURE"), "true"))
server := &Server{db: database, auth: auth, startTime: time.Now()}
webRoot, err := fs.Sub(webFS, "web")
@@ -121,19 +136,19 @@ func (s *Server) registerRoutes(mux *http.ServeMux, webRoot fs.FS) {
mux.HandleFunc("POST /api/auth/reset/confirm", s.auth.handleResetConfirm)
mux.HandleFunc("POST /api/auth/setup", s.auth.handleSetup)
mux.HandleFunc("POST /api/auth/login", s.auth.handleLogin)
mux.Handle("POST /api/auth/logout", s.auth.requireSession(s.auth.handleLogout))
mux.Handle("POST /api/auth/credentials", s.auth.requireSession(s.auth.handleUpdateCredentials))
mux.Handle("GET /api/auth/users", s.auth.requireSession(s.auth.handleUsers))
mux.Handle("POST /api/auth/users", s.auth.requireSession(s.auth.handleUsers))
mux.Handle("PUT /api/auth/users/{id}", s.auth.requireSession(s.auth.handleUser))
mux.Handle("PATCH /api/auth/users/{id}", s.auth.requireSession(s.auth.handleUser))
mux.Handle("DELETE /api/auth/users/{id}", s.auth.requireSession(s.auth.handleUser))
mux.Handle("GET /api/auth/totp/status", s.auth.requireSession(s.auth.handleTOTPStatus))
mux.Handle("POST /api/auth/totp/setup", s.auth.requireSession(s.auth.handleTOTPSetup))
mux.Handle("POST /api/auth/totp/enable", s.auth.requireSession(s.auth.handleTOTPEnable))
mux.Handle("POST /api/auth/totp/disable", s.auth.requireSession(s.auth.handleTOTPDisable))
mux.Handle("GET /api/auth/token/status", s.auth.requireSession(s.auth.handleTokenStatus))
mux.Handle("POST /api/auth/token/regenerate", s.auth.requireSession(s.auth.handleTokenRegenerate))
mux.Handle("POST /api/auth/logout", s.auth.requireSession(http.HandlerFunc(s.auth.handleLogout)))
mux.Handle("POST /api/auth/credentials", s.auth.requireSession(http.HandlerFunc(s.auth.handleUpdateCredentials)))
mux.Handle("GET /api/auth/users", s.auth.requireSession(http.HandlerFunc(s.auth.handleUsers)))
mux.Handle("POST /api/auth/users", s.auth.requireSession(http.HandlerFunc(s.auth.handleUsers)))
mux.Handle("PUT /api/auth/users/{id}", s.auth.requireSession(http.HandlerFunc(s.auth.handleUser)))
mux.Handle("PATCH /api/auth/users/{id}", s.auth.requireSession(http.HandlerFunc(s.auth.handleUser)))
mux.Handle("DELETE /api/auth/users/{id}", s.auth.requireSession(http.HandlerFunc(s.auth.handleUser)))
mux.Handle("GET /api/auth/totp/status", s.auth.requireSession(http.HandlerFunc(s.auth.handleTOTPStatus)))
mux.Handle("POST /api/auth/totp/setup", s.auth.requireSession(http.HandlerFunc(s.auth.handleTOTPSetup)))
mux.Handle("POST /api/auth/totp/enable", s.auth.requireSession(http.HandlerFunc(s.auth.handleTOTPEnable)))
mux.Handle("POST /api/auth/totp/disable", s.auth.requireSession(http.HandlerFunc(s.auth.handleTOTPDisable)))
mux.Handle("GET /api/auth/token/status", s.auth.requireSession(http.HandlerFunc(s.auth.handleTokenStatus)))
mux.Handle("POST /api/auth/token/regenerate", s.auth.requireSession(http.HandlerFunc(s.auth.handleTokenRegenerate)))
// Sync/collaboration API routes use a long-lived bearer token shared by the
// user's devices. This is deliberately separate from browser sessions.
@@ -163,8 +178,8 @@ func (s *Server) registerRoutes(mux *http.ServeMux, webRoot fs.FS) {
// The dashboard is a public SPA shell, but its data and tech-stack endpoints
// are protected by the browser session.
mux.Handle("GET /api/tech-stack", s.auth.requireSession(s.handleTechStack))
mux.Handle("GET /web/data", s.auth.requireSession(s.handleWebData))
mux.Handle("GET /api/tech-stack", s.auth.requireSession(http.HandlerFunc(s.handleTechStack)))
mux.Handle("GET /web/data", s.auth.requireSession(http.HandlerFunc(s.handleWebData)))
mux.Handle("/", spaFileServer(webRoot))
}
@@ -274,7 +289,7 @@ type stackEntry struct {
Value string `json:"value"`
}
func (s *Server) handleTechStack(w http.ResponseWriter, _ *http.Request, _ *AuthUser) {
func (s *Server) handleTechStack(w http.ResponseWriter, _ *http.Request) {
writeJSON(w, http.StatusOK, techStackResponse{
AppVersion: envOrDefault("APP_VERSION", "dev"),
Stack: []stackEntry{