Skip to content

realm-server: lock grafana operator endpoints to POST + Bearer (CS-10927)#4792

Merged
lukemelia merged 1 commit into
mainfrom
cs-10927-remove-get-support-from-grafana-operator-endpoints
May 13, 2026
Merged

realm-server: lock grafana operator endpoints to POST + Bearer (CS-10927)#4792
lukemelia merged 1 commit into
mainfrom
cs-10927-remove-get-support-from-grafana-operator-endpoints

Conversation

@lukemelia
Copy link
Copy Markdown
Contributor

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 with Authorization: Bearer ${grafana_secret} — the legacy shapes have no remaining live callers.

Linear: CS-10927

Changes (three independent knobs)

Knob What's removed Why
A convertAuthHeaderQueryParam middleware (server.ts import + .use(); file deleted) The ?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.
B Bare-secret branch in grafanaAuthorization The middleware now accepts only Authorization: Bearer <secret> (RFC 6750: case-insensitive scheme, flexible whitespace).
C GET registration in registerGrafanaEndpoint All five operator endpoints (reindex, complete-job, add-credit, full-reindex, upsert-realm-user-permission) are POST-only now. The helper now also covers the upsert endpoint, which was always POST-only.

Test 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:

  • POST + valid Bearer → 204
  • POST + wrong Bearer → 401
  • POST + no Authorization header → 401
  • POST + bare-secret (no Bearer prefix) → 401 (new shape — was 204 before)
  • GET + Bearer → 404 (routing removed — was 204 before)
  • POST + lowercase scheme + extra whitespace → 204 (RFC 6750 conformance)

Doc + script callers updated

  • .claude/skills/indexing-diagnostics/SKILL.md: curl examples for _grafana-reindex and _grafana-full-reindex now POST with Authorization: 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

  • All committed Grafana dashboards (realms.json, users.json, indexing.json, job-queue.json) already use method: 'POST' + Authorization: Bearer ${grafana_secret}.
  • CORS is wide-open (origin: '*', Authorization allow-listed) — Grafana origins covered.

Test plan

  • pnpm test in packages/realm-server against the test-pg + synapse + dual-realm-server stack — confirms all 30+ maintenance-endpoints tests pass with the new shape.
  • Manual smoke against local Grafana: click "Reindex" on a realm panel and confirm it returns 204 (button-panel customCode already POSTs with Bearer).
  • Manual smoke against staging Grafana once merged: same.

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

…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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/realm-server/middleware/index.ts
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 2026

Host Test Results

    1 files      1 suites   1h 47m 11s ⏱️
2 658 tests 2 643 ✅ 15 💤 0 ❌
2 677 runs  2 662 ✅ 15 💤 0 ❌

Results for commit 46f7d09.

Realm Server Test Results

    1 files      1 suites   11m 19s ⏱️
1 328 tests 1 328 ✅ 0 💤 0 ❌
1 407 runs  1 407 ✅ 0 💤 0 ❌

Results for commit 46f7d09.

@lukemelia lukemelia marked this pull request as ready for review May 12, 2026 20:38
@lukemelia lukemelia requested review from a team and habdelra May 12, 2026 20:38
@lukemelia lukemelia merged commit 2e875ed into main May 13, 2026
99 checks passed
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.

3 participants