Repository navigation
fix(admin): distinguish unconfigured ADMIN_TOKEN with 503 and surface diagnostics (#508) - #566
Open
sparkysolutions10-pixel wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #508.
Summary of Changes
When
ADMIN_TOKENis 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:
isAdminConfigured()andcheckAdminAuth()insrc/api/auth.ts.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' }whenADMIN_TOKENis not set or empty.admin_auth_failures_totalmetrics are only incremented on genuine credential mismatch (401), not when unconfigured.src/app.tsemits an explicit logger warning at boot if!isAdminConfigured()./status:adminConfigured: booleanto/statusresponse and OpenAPI schema so monitoring agents and dashboards can inspect admin availability..env.exampledocumenting that omittingADMIN_TOKENdisables admin surface endpoints with 503.src/__tests__/adminTokenDiagnostics.test.tscovering 503 vs 401 behavior across all admin routes,/statusreflection, 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)