Skip to content

feat(raw): authenticate embedded Grafana with a service account token - #3

Merged
paymog merged 6 commits into
mainfrom
feat/grafana-service-account-token
Jul 8, 2026
Merged

paymog merged 6 commits into
mainfrom
feat/grafana-service-account-token

Conversation

@paymog

@paymog paymog commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Problem

raw grafana … commands never worked. They target the embedded Grafana at
app.groundcover.com/grafana/api/*, which is behind a session-gated proxy that
ignores the gcsa_ API key. Every call returned the ~980KB Grafana SPA
index.html (HTTP 200, text/html) instead of JSON.

Verified: the gcsa_ bearer is valid against the real API
(api.groundcover.com/api/* returns JSON), so the breakage was specific to the
Grafana proxy path, not the key. The proxy only accepts a Grafana service
account token (glsa_…).

Fix

  • raw grafana … (WebApp) commands now authenticate with a Grafana service
    account token via a plain HTTP client, bypassing the SDK transport (which
    unconditionally overwrites Authorization with the gcsa bearer).
  • Token comes from GROUNDCOVER_GRAFANA_SERVICE_ACCOUNT_TOKEN /
    GC_GRAFANA_SERVICE_ACCOUNT_TOKEN or --grafana-token.
  • Non-grafana raw commands are unchanged (gcsa + X-Backend-Id via SDK
    transport, X-Tenant-UUID when set).
  • Running any raw grafana … command without a token prints an actionable
    setup guide: install groundcover's official CLI, auth login,
    auth generate-service-account-token, then export the token. The guide also
    handles the binary-name collision (the official CLI is also groundcover; its
    installer prepends ~/.groundcover/bin to PATH, shadowing this one) by
    steering users to invoke it by full path.

Verification

  • Live: raw grafana search / folders list return real dashboard/folder JSON;
    missing-token path prints the guide and makes zero HTTP calls; non-grafana raw
    commands still work with just the gcsa key.
  • Tests: TestRunGrafanaWebApp_WithToken, _MissingToken,
    TestRunNonWebApp_SDKHeaders, TestGrafanaSetupGuideContent. Full suite
    green, go vet clean.

Docs

README + skills/groundcover-cli/SKILL.md updated with the token requirement,
generation steps, and the PATH-collision note; corrected a stale X-Tenant-UUID
claim.

paymog added 6 commits July 6, 2026 13:38
The `raw grafana …` commands target app.groundcover.com/grafana/api/*, an
embedded Grafana behind a session-gated proxy that ignores the gcsa bearer
token: every call returned the ~980KB Grafana SPA index.html instead of JSON.

Route WebApp (grafana) commands through a plain HTTP client that sets
Authorization: Bearer <glsa_...> from GROUNDCOVER_GRAFANA_SERVICE_ACCOUNT_TOKEN
(or --grafana-token), bypassing the SDK transport that would clobber the header
with the gcsa key. Non-grafana raw commands are unchanged (gcsa + X-Backend-Id
via SDK transport, plus X-Tenant-UUID when set).

Verified live: `raw grafana search` and `folders list` return real JSON.
Running any `raw grafana ...` command without a Grafana service account token
now prints an actionable setup guide instead of a one-line error: how to
generate a glsa_ token with groundcover's official CLI (install, auth login,
auth generate-service-account-token) and hand it to this CLI.

The official CLI also ships a `groundcover` binary; its installer puts it in
~/.groundcover/bin and prepends that dir to PATH, shadowing this CLI. The guide
calls that out and steers users to invoke the official binary by full path.

Removes the now-superseded config.RequireGrafanaToken (terse message) in favor
of the raw-layer guide. Tests cover the guide content and the missing-token
short-circuit.
@paymog
paymog merged commit d5a2516 into main Jul 8, 2026
1 check passed
@paymog
paymog deleted the feat/grafana-service-account-token branch July 8, 2026 15:33
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.

1 participant