You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add /api/gcx-token: self-serve read-only Grafana token for gcx (#8154)
## What
New `GET/POST /api/gcx-token` endpoint that mints a **read-only
(Viewer)** Grafana service-account token for the
[`gcx`](https://github.com/grafana/gcx) CLI, so contributors can
self-serve a `GRAFANA_TOKEN` instead of creating one by hand in the
Grafana UI.
## Auth
Gated by GitHub identity **exactly like Flambeau**: the caller must have
write access to `pytorch/pytorch` (or be on the Flambeau allow list).
Reuses `getOctokitWithUserToken` + `hasWritePermissionsUsingOctokit`.
## Usage (no browser, nothing to install)
```bash
export GRAFANA_TOKEN=$(curl -fsSL \
-H "Authorization: Bearer $(gh auth token)" \
https://hud.pytorch.org/api/gcx-token)
```
Also accepts a browser NextAuth session as a fallback. Returns the token
as `text/plain` by default, or JSON with `Accept: application/json` /
`?format=json`.
## Token model
Each GitHub user gets a dedicated service account `gcx-<github-login>`
(Viewer role). Tokens are **long-lived**; revocation is manual via the
Grafana UI. Viewer = read-only: good for `gcx resources
validate`/dry-run and querying, **not** for `push` (publishing needs
Editor).
## Deploy prerequisite (not in this PR)
Set in Vercel env:
- `GRAFANA_ADMIN_TOKEN` — Grafana Admin SA token
(`serviceaccounts:write` / `serviceaccounts.tokens:write`). Server-side
only; never returned.
- `GRAFANA_SERVER` — optional, defaults to
`https://pytorchci.grafana.net`.
## Validation
- Grafana mint path verified end-to-end against pytorchci.grafana.net
(create Viewer SA → create token → token reads OK, writes 403 →
cleanup).
- Unit tests (`test/gcxToken.test.ts`): 405 / 401 / 403 / 200 text / 200
JSON. `tsc` clean.
Draft until reviewed.
0 commit comments