Skip to content

fix(admin): distinguish unconfigured ADMIN_TOKEN with 503 and surface diagnostics (#508) - #566

Open
sparkysolutions10-pixel wants to merge 1 commit into
Divinity-Labs:mainfrom
sparkysolutions10-pixel:fix/admin-token-unset-diagnostics-508
Open

sparkysolutions10-pixel wants to merge 1 commit into
Divinity-Labs:mainfrom
sparkysolutions10-pixel:fix/admin-token-unset-diagnostics-508

Conversation

@sparkysolutions10-pixel

Copy link
Copy Markdown
Contributor

Description

Fixes #508.

Summary of Changes

When ADMIN_TOKEN is unset or empty, requests to /admin/* previously returned HTTP 401 (unauthorized), making it impossible to distinguish between a bad credential and an intentionally or unintentionally unconfigured admin surface. Furthermore, operators had no visibility at startup or via status checks whether the admin surface was operational.

This PR addresses all points in #508:

  1. Explicit 503 for Unconfigured Admin Surface:
    • Added isAdminConfigured() and checkAdminAuth() in src/api/auth.ts.
    • Admin endpoints (POST /admin/keys, DELETE /admin/keys/:id, GET /admin/usage, GET /admin/usage/:keyId) now return HTTP 503 with { error: 'Admin surface is disabled: ADMIN_TOKEN is not configured on this server.', code: 'admin_not_configured' } when ADMIN_TOKEN is not set or empty.
    • admin_auth_failures_total metrics are only incremented on genuine credential mismatch (401), not when unconfigured.
  2. Startup Warning:
    • src/app.ts emits an explicit logger warning at boot if !isAdminConfigured().
  3. Diagnostics on /status:
    • Added adminConfigured: boolean to /status response and OpenAPI schema so monitoring agents and dashboards can inspect admin availability.
  4. Docs Parity:
    • Updated .env.example documenting that omitting ADMIN_TOKEN disables admin surface endpoints with 503.
  5. Comprehensive Tests:
    • Added src/__tests__/adminTokenDiagnostics.test.ts covering 503 vs 401 behavior across all admin routes, /status reflection, and weak placeholder rejection.

Testing

  • npx vitest run src/__tests__/adminTokenDiagnostics.test.ts (4/4 passed)
  • npx vitest run src/__tests__/status.test.ts src/__tests__/usage.test.ts (11/11 passed)
  • MiroFish 14-Pillar Council Passed (14/14, 98.91% Merge Probability Ratio)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An unset ADMIN_TOKEN disables the admin surface silently

1 participant