realm-server: lock grafana operator endpoints to POST + Bearer (CS-10927)#4792
Merged
lukemelia merged 1 commit intoMay 13, 2026
Merged
Conversation
…927)
Following the 2026-05-06 cutover to self-host Grafana, all committed
dashboards POST with `Authorization: Bearer ${grafana_secret}`. Removes
three vestigial paths from the AMG era:
A. Drop the `convertAuthHeaderQueryParam` middleware. The `?authHeader=`
querystring-to-header promotion was AMG's only auth shape because
AMG can't run plugin JS. It put the shared secret in URL access
logs, browser history, and HTTP referers — the only meaningful
security smell here. Self-host dashboards never used it.
B. Remove the bare-secret branch from `grafanaAuthorization`. The
middleware now only accepts `Authorization: Bearer <secret>`
(RFC 6750: case-insensitive scheme, flexible whitespace).
C. Drop GET registration from `registerGrafanaEndpoint`. All five
operator endpoints — reindex, complete-job, add-credit, full-reindex,
upsert-realm-user-permission — are POST-only now. The helper folds
the upsert endpoint (always POST-only) into the same registration.
Test surgery: every test that hit `.get(/_grafana-X?authHeader=...)`
now POSTs with a Bearer header. The "accepts bare-secret" and "accepts
GET" tests are flipped to reject tests (401 / 404 respectively). New
or kept coverage: POST + Bearer 204, POST + wrong Bearer 401, POST +
no Authorization 401, POST + bare-secret 401, GET 404, lowercase
scheme + extra whitespace 204.
Doc + script callers updated:
- `.claude/skills/indexing-diagnostics/SKILL.md`: curl examples now
POST with `Authorization: Bearer`; removed the "grafana endpoint is
a GET" line.
- `packages/realm-server/scripts/full-reindex.sh`: now POSTs with a
Bearer header instead of GET + ?authHeader=.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens realm-server Grafana operator-action endpoints by removing legacy auth/verb shapes from the AMG-era cutover, standardizing them on POST-only requests authenticated via Authorization: Bearer <secret>.
Changes:
- Removed
?authHeader=query-param promotion middleware and updated server wiring accordingly. - Locked all
/_grafana-*operator endpoints to POST-only routing and Bearer-only authorization parsing. - Updated maintenance endpoint tests, local reindex script, and internal docs to use POST + Bearer.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/realm-server/middleware/index.ts | Tightens grafanaAuthorization to Bearer-only token parsing. |
| packages/realm-server/middleware/convert-auth-header-qp.ts | Deletes legacy middleware that promoted ?authHeader= into headers. |
| packages/realm-server/server.ts | Removes the deleted middleware from server initialization. |
| packages/realm-server/routes.ts | Makes Grafana operator endpoints POST-only and routes all via the shared helper. |
| packages/realm-server/tests/server-endpoints/maintenance-endpoints-test.ts | Updates tests to POST + Bearer; adds rejection coverage for GET and bare-secret auth. |
| packages/realm-server/scripts/full-reindex.sh | Switches local script from GET + querystring auth to POST + Bearer. |
| .claude/skills/indexing-diagnostics/SKILL.md | Updates curl examples and endpoint description to POST + Bearer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
habdelra
approved these changes
May 12, 2026
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
Removes three vestigial AMG-era auth shapes from realm-server's
/_grafana-*operator endpoints. After the 2026-05-06 cutover, all committed dashboards POST withAuthorization: Bearer ${grafana_secret}— the legacy shapes have no remaining live callers.Linear: CS-10927
Changes (three independent knobs)
convertAuthHeaderQueryParammiddleware (server.tsimport +.use(); file deleted)?authHeader=<secret>→ header promotion was AMG's only auth shape because AMG can't run plugin JS. It put the secret in URL access logs, browser history, and HTTP referers — the actual security smell.grafanaAuthorizationAuthorization: Bearer <secret>(RFC 6750: case-insensitive scheme, flexible whitespace).registerGrafanaEndpointTest changes
Every test that hit
.get('/_grafana-X?authHeader=...')now POSTs with a Bearer Authorization header. The "accepts bare-secret" and "accepts GET + Bearer" tests are flipped to reject tests (401 / 404 respectively). Kept and new coverage:Doc + script callers updated
.claude/skills/indexing-diagnostics/SKILL.md:curlexamples for_grafana-reindexand_grafana-full-reindexnow POST withAuthorization: Bearer; removed the line claiming "grafana endpoint is a GET, no MIME gotcha."packages/realm-server/scripts/full-reindex.sh: local-dev script switched from GET +?authHeader=to POST + Bearer.Other callers verified clean
realms.json,users.json,indexing.json,job-queue.json) already usemethod: 'POST'+Authorization: Bearer ${grafana_secret}.origin: '*',Authorizationallow-listed) — Grafana origins covered.Test plan
pnpm testinpackages/realm-serveragainst the test-pg + synapse + dual-realm-server stack — confirms all 30+ maintenance-endpoints tests pass with the new shape.Notes
This goes beyond the strict ticket scope, which called for a deprecation log + bake period before removing GET. Decision recorded inline with the user: the security smell of
?authHeader=(token in URL → logs) outweighs the empirical-evidence value of a bake period, since all known callers have been verified migrated.🤖 Generated with Claude Code