Skip to main content
Version: Preview

Connect Grafana

Catalog Grafana's dashboards, charts and data sources with a pipeline that signs in with Marmot's identity, so there's no service account token to create, store or rotate. Grafana fetches your instance's public keys from your instance, and your instance connects to Grafana with a short-lived token. Tasks use the same sign-in for the Grafana tools.

Before you start​

  • You hold ingestion.admin across the whole catalog in your instance.
  • You can change Grafana's configuration (grafana.ini or its GF_* environment variables) and restart it.
  • Grafana can reach your instance over https, to fetch its keys.
  • Your instance can reach Grafana at a public address. For a Grafana on a private network, use a runner instead.

How it works​

Before every run, connection test, query and tool call, your instance gives the pipeline a 5-minute token with the pipeline as its subject and Grafana's own address as the audience, so a token is only good for the Grafana it was sent to. Grafana checks it against your instance's published keys and signs the pipeline in as a Grafana user named after the subject; Workload identity explains the model.

Values you'll need​

Replace <instance> and <grafana-host> with your own:

  • Issuer: https://<instance>.marmotdata.cloud. Always the marmotdata.cloud address, even with a custom domain
  • Key set URL: https://<instance>.marmotdata.cloud/.well-known/jwks.json
  • Audience: https://<grafana-host>, the scheme, host and port of the Grafana URL the pipeline uses, with no path
  • Subject: pipeline:<pipeline-name>, the name you give the pipeline

The add source form shows all four, and the grafana.ini block with them filled in, as soon as you choose Marmot's identity and enter Grafana's URL.

  1. Trust your instance in Grafana

    Turn on JWT authentication in grafana.ini:

    [auth.jwt]
    enabled = true
    header_name = Authorization
    username_claim = sub
    auto_sign_up = true
    jwk_set_url = https://<instance>.marmotdata.cloud/.well-known/jwks.json
    expect_claims = {"iss": "https://<instance>.marmotdata.cloud", "aud": ["https://<grafana-host>"], "sub": "pipeline:<pipeline-name>"}
    role_attribute_path = join('', ['Viewer'])
    role_attribute_strict = true

    expect_claims admits this pipeline only. Then restart Grafana. With the Helm chart or Docker, set the same keys as GF_AUTH_JWT_ENABLED, GF_AUTH_JWT_JWK_SET_URL and so on.

    role_attribute_path = join('', ['Viewer']) makes every pipeline a Viewer, which reads dashboards, library panels, the data source list and, for tools, queries. If your Grafana restricts data source permissions, grant each pipeline's user Query on the data sources it should reach. Don't shorten it to 'Viewer': grafana.ini strips the outer quotes, so Grafana reads Viewer as a claim name and refuses sign-in.

  2. Add the pipeline

    1. Open Plugins and select Grafana under Add a source.
    2. Choose Marmot's identity and enter Grafana's URL.
    3. Name the pipeline, then select Test connection. The test signs in to Grafana as the pipeline.
    4. Set a schedule and select Create pipeline.

Check that it worked​

Open the pipeline under Plugins and select Run now. The run succeeds, your dashboards appear in Discover, and Grafana lists a user named pipeline:<pipeline-name> under Administration, Users.

Troubleshooting​

What you seeWhat to do
401 Unauthorized from GrafanaCheck that iss, aud and sub in expect_claims match the values the add source form shows, character for character
Name the pipeline first: it signs in as Marmot under that nameName the pipeline before testing the connection
signing in with Marmot's identity needs the address the token is sent toEnter Grafana's URL, starting with https://
The run reads dashboards but no data sourcesThe Viewer can't list them on your Grafana. Grant the pipeline's user the permission

Things to know​

  • Without sub in expect_claims, any pipeline in your instance that signs in this way gets a Viewer user of its own.
  • Renaming the pipeline signs it in as a new Grafana user. Update expect_claims and grant data source permissions again, or keep the name.
  • Grafana caches the key set for cache_ttl (60 minutes by default). Your instance publishes a new key a day before it signs with it, so the cache never misses one.
  • A Grafana service account token still works: choose Service account token instead.