Remove local admin reset now that AuthGuard owns that recovery flow
Lint / Lint (push) Successful in 42s
Tests / Go backend (push) Successful in 56s
Tests / Dashboard checks (push) Successful in 1m5s
Docker / Docker Build & Push (push) Successful in 4m14s

This project's own "break glass" admin reset never actually touched the
centralized AuthGuard account - it only printed a local one-time code and,
on confirm, wiped this project's local "setup completed" flag so its own
setup screen reappeared, leaving the real AuthGuard account untouched and
orphaned from this project's perspective. AuthGuard now has its own proper
superadmin reset in its web UI, which is where this recovery path belongs
going forward - having every integrated project also show a "Reset admin
account" link that does something different and doesn't actually solve
"I forgot my AuthGuard password" was confusing and redundant.

Removes the backend reset handlers, their routes, the local ResetManager
field/init, any local cleanup method that only existed to serve them, and
the frontend API calls plus the onRequestReset/onConfirmReset wiring that
made the shared AuthPage component's reset link appear.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-02 08:51:22 +02:00
1 parent ec4bdd6ac7
commit 4e39b5ac67
6 files changed
+97 -199

No files matched your search

+1 -68
View File
@@ -210,15 +210,10 @@ type AuthService struct {
db *DB db *DB
authGuard *authclient.Client authGuard *authclient.Client
secureCookie bool secureCookie bool
// reset backs CollabTable's own local break-glass recovery flow (see
// handleResetRequest/handleResetConfirm); it is unrelated to AuthGuard,
// which runs its own separate instance of the same ResetManager type for
// its own recovery flow.
reset *sharedauth.ResetManager
} }
func newAuthService(authGuard *authclient.Client, db *DB, secureCookie bool) *AuthService { func newAuthService(authGuard *authclient.Client, db *DB, secureCookie bool) *AuthService {
return &AuthService{db: db, authGuard: authGuard, secureCookie: secureCookie, reset: sharedauth.NewResetManager()} return &AuthService{db: db, authGuard: authGuard, secureCookie: secureCookie}
} }
func normalizeUsername(value string) (string, error) { func normalizeUsername(value string) (string, error) {
@@ -472,68 +467,6 @@ func (a *AuthService) handleStatus(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, a.statusResponse(r.Context(), *profile)) writeJSON(w, http.StatusOK, a.statusResponse(r.Context(), *profile))
} }
// handleResetRequest and handleResetConfirm are CollabTable's own local
// "break glass" account recovery: an operator with shell/log access to this
// container (not to AuthGuard) can recover access to CollabTable's UI
// without knowing the current AuthGuard account's password. This is
// deliberately NOT proxied to AuthGuard's own POST
// /api/password-reset/request|confirm -- a break-glass flow should never
// depend on the very identity service it exists to recover access to, and
// (like GameStream before it) CollabTable's existing frontend only ever
// sends {code}, not a new password, so it was built for a "wipe and redo
// setup" recovery model rather than AuthGuard's "set a specific new
// password" one in any case.
func (a *AuthService) handleResetRequest(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
if _, err := a.reset.Request(); err != nil {
writeJSONError(w, http.StatusInternalServerError, "Unable to create reset code")
return
}
writeJSON(w, http.StatusOK, map[string]bool{"ok": true})
}
// handleResetConfirm validates the one-time code handleResetRequest printed
// to this process's own stdout and, on success, resets the local "setup
// completed" flag so CollabTable's setup screen reappears.
//
// This intentionally does NOT touch the underlying AuthGuard account at all
// (does not delete it, does not change its password): CollabTable's local
// console-access recovery is only ever allowed to affect CollabTable's own
// claim on an identity, never to reach into and mutate the centralized
// identity store other projects may come to share. Concretely, this means
// the account AuthGuard already has is left behind (orphaned, from
// CollabTable's perspective) once this runs; re-running setup with the same
// username/email will hit AuthGuard's own 409 "already in use" and the
// operator will need to either choose a different identity at the setup
// screen or resolve the original account directly against AuthGuard (which
// has its own equivalent break-glass recovery).
func (a *AuthService) handleResetConfirm(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
var request struct {
Code string `json:"code"`
}
if err := decodeJSON(r, &request); err != nil || strings.TrimSpace(request.Code) == "" {
writeJSONError(w, http.StatusBadRequest, "Code required")
return
}
if !a.reset.Confirm(request.Code) {
writeJSONError(w, http.StatusUnauthorized, "Invalid or expired reset code.")
return
}
if err := a.db.ClearSetupClaim(r.Context()); err != nil {
writeJSONError(w, http.StatusInternalServerError, "Reset failed")
return
}
a.clearSessionCookies(w)
writeJSON(w, http.StatusOK, map[string]bool{"ok": true})
}
// handleSetup registers CollabTable's first account against AuthGuard's // handleSetup registers CollabTable's first account against AuthGuard's
// POST /api/register. See the top-of-file doc comment's "Setup flow" section // POST /api/register. See the top-of-file doc comment's "Setup flow" section
// for why this needs a small local claim flag instead of a count-based // for why this needs a small local claim flag instead of a count-based
-8
View File
@@ -276,14 +276,6 @@ func (d *DB) UnclaimSetup(ctx context.Context) error {
return nil return nil
} }
// ClearSetupClaim resets the local "setup completed" flag so the setup screen
// reappears. Used by the local break-glass password-reset flow (see
// handleResetConfirm in auth.go) -- it deliberately does not touch the
// underlying AuthGuard account at all.
func (d *DB) ClearSetupClaim(ctx context.Context) error {
return d.UnclaimSetup(ctx)
}
// GetCachedTOTPEnabled returns the best-effort locally-cached TOTP-enabled // GetCachedTOTPEnabled returns the best-effort locally-cached TOTP-enabled
// state for an AuthGuard account, or false if this instance has never // state for an AuthGuard account, or false if this instance has never
// observed that account's TOTP state. See handleTOTPStatus's doc comment in // observed that account's TOTP state. See handleTOTPStatus's doc comment in
-2
View File
@@ -132,8 +132,6 @@ func (s *Server) registerRoutes(mux *http.ServeMux, webRoot fs.FS) {
// Health and auth bootstrap routes are intentionally public. // Health and auth bootstrap routes are intentionally public.
mux.HandleFunc("GET /health", s.handleHealth) mux.HandleFunc("GET /health", s.handleHealth)
mux.HandleFunc("GET /api/auth/status", s.auth.handleStatus) mux.HandleFunc("GET /api/auth/status", s.auth.handleStatus)
mux.HandleFunc("POST /api/auth/reset/request", s.auth.handleResetRequest)
mux.HandleFunc("POST /api/auth/reset/confirm", s.auth.handleResetConfirm)
mux.HandleFunc("POST /api/auth/setup", s.auth.handleSetup) mux.HandleFunc("POST /api/auth/setup", s.auth.handleSetup)
mux.HandleFunc("POST /api/auth/login", s.auth.handleLogin) mux.HandleFunc("POST /api/auth/login", s.auth.handleLogin)
mux.Handle("POST /api/auth/logout", s.auth.requireSession(http.HandlerFunc(s.auth.handleLogout))) mux.Handle("POST /api/auth/logout", s.auth.requireSession(http.HandlerFunc(s.auth.handleLogout)))
+45 -58
View File
@@ -1,46 +1,46 @@
async function request(url, options) { async function request(url, options) {
const res = await fetch(url, { const res = await fetch(url, {
...options, ...options,
headers: options?.body ? { 'Content-Type': 'application/json', ...options?.headers } : options?.headers, headers: options?.body ? { 'Content-Type': 'application/json', ...options?.headers } : options?.headers,
}); });
if (!res.ok) { if (!res.ok) {
let message = `HTTP ${res.status}`; let message = `HTTP ${res.status}`;
try { try {
const body = await res.json(); const body = await res.json();
// This backend's error responses are { error: "<category>", message: "<human text>" } - // This backend's error responses are { error: "<category>", message: "<human text>" } -
// message is the human-readable text; error is just a category label (e.g. "Unauthorized"). // message is the human-readable text; error is just a category label (e.g. "Unauthorized").
if (body?.message) message = body.message; if (body?.message) message = body.message;
else if (body?.error) message = body.error; else if (body?.error) message = body.error;
} catch { } catch {
// Response body wasn't JSON (or was empty) - keep the generic status message. // Response body wasn't JSON (or was empty) - keep the generic status message.
} }
throw new Error(message); throw new Error(message);
} }
if (res.status === 204) return undefined; if (res.status === 204) return undefined;
return res.json(); return res.json();
} }
async function getJson(url) { async function getJson(url) {
return request(url); return request(url);
} }
export async function fetchOverview() { export async function fetchOverview() {
return getJson('/web/data'); return getJson('/web/data');
} }
export async function fetchTechStack() { export async function fetchTechStack() {
return getJson('/api/tech-stack'); return getJson('/api/tech-stack');
} }
export async function fetchHealth() { export async function fetchHealth() {
const res = await fetch('/health'); const res = await fetch('/health');
return { up: res.ok }; return { up: res.ok };
} }
export async function fetchAuthStatus() { export async function fetchAuthStatus() {
return getJson('/api/auth/status'); return getJson('/api/auth/status');
} }
export async function setupAccount(username, email, password) { export async function setupAccount(username, email, password) {
return request('/api/auth/setup', { method: 'POST', body: JSON.stringify({ username, email, password }) }); return request('/api/auth/setup', { method: 'POST', body: JSON.stringify({ username, email, password }) });
} }
@@ -65,23 +65,10 @@ export async function disableTotp(token) {
return request('/api/auth/totp/disable', { method: 'POST', body: JSON.stringify({ token }) }); return request('/api/auth/totp/disable', { method: 'POST', body: JSON.stringify({ token }) });
} }
export async function requestAdminReset() { export async function logout() {
return request('/api/auth/reset/request', { method: 'POST' }); return request('/api/auth/logout', { method: 'POST' });
} }
export async function confirmAdminReset(code) {
const result = await request('/api/auth/reset/confirm', {
method: 'POST',
body: JSON.stringify({ code }),
});
window.location.reload();
return result;
}
export async function logout() {
return request('/api/auth/logout', { method: 'POST' });
}
export async function updateCredentials({ newUsername, newEmail, newPassword }) { export async function updateCredentials({ newUsername, newEmail, newPassword }) {
return request('/api/auth/credentials', { return request('/api/auth/credentials', {
method: 'POST', method: 'POST',
@@ -7,8 +7,6 @@
const onLogin = (input) => auth.login(input.identifier, input.password, input.totpToken); const onLogin = (input) => auth.login(input.identifier, input.password, input.totpToken);
const onSetup = (input) => auth.setup(input.username, input.email, input.password); const onSetup = (input) => auth.setup(input.username, input.email, input.password);
const onRequestReset = () => auth.requestAdminReset();
const onConfirmReset = (code) => auth.confirmAdminReset(code);
</script> </script>
<SharedAuthPage <SharedAuthPage
@@ -19,6 +17,4 @@
{error} {error}
{onLogin} {onLogin}
{onSetup} {onSetup}
{onRequestReset}
{onConfirmReset}
/> />
+51 -59
View File
@@ -1,7 +1,6 @@
import { createMutation, createQuery, useQueryClient } from '@tanstack/svelte-query'; import { createMutation, createQuery, useQueryClient } from '@tanstack/svelte-query';
import { getContext, setContext } from 'svelte'; import { getContext, setContext } from 'svelte';
import { import {
confirmAdminReset,
createUser, createUser,
deleteUser, deleteUser,
disableTotp, disableTotp,
@@ -11,52 +10,51 @@ import {
login, login,
listUsers, listUsers,
logout, logout,
requestAdminReset,
setupTotp, setupTotp,
setupAccount, setupAccount,
updateCredentials, updateCredentials,
updateUser, updateUser,
} from '$lib/api.js'; } from '$lib/api.js';
const AUTH_STATUS_KEY = ['AuthStatus']; const AUTH_STATUS_KEY = ['AuthStatus'];
const AUTH_CONTEXT_KEY = Symbol('auth'); const AUTH_CONTEXT_KEY = Symbol('auth');
export function createAuthStore() { export function createAuthStore() {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const statusQuery = createQuery(() => ({ const statusQuery = createQuery(() => ({
queryKey: AUTH_STATUS_KEY, queryKey: AUTH_STATUS_KEY,
queryFn: fetchAuthStatus, queryFn: fetchAuthStatus,
})); }));
const setupMutation = createMutation(() => ({ const setupMutation = createMutation(() => ({
mutationFn: ({ username, email, password }) => setupAccount(username, email, password), mutationFn: ({ username, email, password }) => setupAccount(username, email, password),
})); }));
const loginMutation = createMutation(() => ({ const loginMutation = createMutation(() => ({
mutationFn: ({ identifier, password, totpToken }) => login(identifier, password, totpToken), mutationFn: ({ identifier, password, totpToken }) => login(identifier, password, totpToken),
})); }));
const logoutMutation = createMutation(() => ({ const logoutMutation = createMutation(() => ({
mutationFn: () => logout(), mutationFn: () => logout(),
})); }));
const updateCredentialsMutation = createMutation(() => ({ const updateCredentialsMutation = createMutation(() => ({
mutationFn: (input) => updateCredentials(input), mutationFn: (input) => updateCredentials(input),
})); }));
const refresh = () => queryClient.invalidateQueries({ queryKey: AUTH_STATUS_KEY }); const refresh = () => queryClient.invalidateQueries({ queryKey: AUTH_STATUS_KEY });
const store = { const store = {
get status() { get status() {
return statusQuery.data; return statusQuery.data;
}, },
get loading() { get loading() {
return statusQuery.isLoading; return statusQuery.isLoading;
}, },
get error() { get error() {
return statusQuery.error; return statusQuery.error;
}, },
async setup(username, email, password) { async setup(username, email, password) {
await setupMutation.mutateAsync({ username, email, password }); await setupMutation.mutateAsync({ username, email, password });
await refresh(); await refresh();
}, },
async login(identifier, password, totpToken = '') { async login(identifier, password, totpToken = '') {
await loginMutation.mutateAsync({ identifier, password, totpToken }); await loginMutation.mutateAsync({ identifier, password, totpToken });
await refresh(); await refresh();
@@ -76,16 +74,10 @@ export function createAuthStore() {
await disableTotp(token); await disableTotp(token);
await refresh(); await refresh();
}, },
async requestAdminReset() { async logout() {
await requestAdminReset(); await logoutMutation.mutateAsync();
await refresh();
}, },
async confirmAdminReset(code) {
await confirmAdminReset(code);
},
async logout() {
await logoutMutation.mutateAsync();
await refresh();
},
async updateCredentials(input) { async updateCredentials(input) {
await updateCredentialsMutation.mutateAsync(input); await updateCredentialsMutation.mutateAsync(input);
await refresh(); await refresh();
@@ -102,16 +94,16 @@ export function createAuthStore() {
async deleteUser(id) { async deleteUser(id) {
await deleteUser(id); await deleteUser(id);
}, },
}; };
setContext(AUTH_CONTEXT_KEY, store); setContext(AUTH_CONTEXT_KEY, store);
return store; return store;
} }
export function useAuth() { export function useAuth() {
const ctx = getContext(AUTH_CONTEXT_KEY); const ctx = getContext(AUTH_CONTEXT_KEY);
if (!ctx) { if (!ctx) {
throw new Error('useAuth() must be called within the root layout that calls createAuthStore()'); throw new Error('useAuth() must be called within the root layout that calls createAuthStore()');
} }
return ctx; return ctx;
} }