Document and verify auth on indexer admin analytics endpoints - #35
Merged
priscaenoch merged 1 commit intoJul 24, 2026
Merged
Conversation
Adds docs/ADMIN_AUTH.md documenting the admin bearer-token scheme (issuance, scope, expiry, rotation, logging) for every /api/admin/* route, and indexer/test/api/admin-auth.test.js asserting 401 for missing/invalid tokens on every admin route and a non-401 response for a valid token on the four analytics routes the frontend rate-limit dashboard calls. No source change was needed: router.use(adminAuthMiddleware) in indexer/src/routes/admin.js already gates the whole admin router, and neither the request logger nor the audit logger record the Authorization header.
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.
Summary
Adds
docs/ADMIN_AUTH.mddocumenting the admin bearer-token auth scheme used by every/api/admin/*route on the indexer — howADMIN_SECRETis configured, its scope, expiry, and rotation — andindexer/test/api/admin-auth.test.js, which asserts every/api/admin/*route (including the four analytics routes the frontend rate-limit dashboard calls:rate-limit-hits,top-users,violation-heatmap,upgrade-recommendations) returns401for both a missing and an invalid token, and that a valid token succeeds on the analytics routes.Context
indexer/src/admin/adminAuth.jsalready appliesrouter.use(adminAuthMiddleware)to the whole admin router inindexer/src/routes/admin.js, so every route on it — including the four analytics routes — was already gated; there was no undocumented gap in enforcement. I also confirmed theAuthorizationheader is never logged: the request logger inindexer/src/api.jsdoesn't log headers, andindexer/src/audit/auditLogger.jsrecords onlymethod,endpoint,status_code,ip, anduser-agent. Given that, this PR is documentation + tests only — no source change was required to satisfy the issue's enforcement requirement.One thing worth calling out: the auth model here is a single shared static secret (no per-token scope), so there's no case where a valid token is rejected for insufficient permission — the middleware only ever returns
401, never403. I documented this explicitly indocs/ADMIN_AUTH.mdrather than force an artificial403branch that doesn't correspond to real behavior.Before / After
Before: admin auth enforcement was implied by the router wiring but undocumented, and untested.
After: documented in
docs/ADMIN_AUTH.md, and covered by tests proving401on missing/invalid tokens across all 12 admin routes and a successful (!= 401) response with a valid token on the 4 analytics routes named in the issue.Testing
Added
indexer/test/api/admin-auth.test.js, following the existingindexer/test/api/*.test.jsconvention (Jest + supertest +startApi()/db.init()against a real Postgres test database viaTEST_DATABASE_URL/DATABASE_URL), matching the pattern used by the other files in that directory (e.g.contract.test.js,api.test.js).Caveat: I was not able to run this locally (no Postgres instance /
npm ciin this environment, and the repo instructions asked me not to install dependencies), so I have not executed this test suite myself — please run it in CI/locally before merging. Separately, I noticed.github/workflows/ci.ymlcurrently only runs the root-levelnpm testand has no job that installsindexer/'s dependencies or runsindexer/test/api/*.test.jsat all (pre-existing gap, unrelated to this change) — worth a follow-up issue ifindexer/tests aren't meant to be run manually only.Closes #22