RousselTMLEARNING

TP · Grafana: From Discovery to Expertise

Lab: a multi-team Grafana with permissions with correction

The correction is integrated into the TP (See the green boxes)

What you will learn in this TP
  • Create teams and users through the API
  • Separate folders per team
  • Remove default permissions
  • Create a time-limited service account
  • Check each profile's access

Introduction #

What you will learn in this section
  • Create teams and users through the API
  • Separate folders per team
  • Remove default permissions
  • Create a time-limited service account
  • Check each profile's access

Context. Your Grafana is shared by three departments. Today everyone sees and edits everything. You must separate them without creating three instances.

Prerequisites: a machine with Docker and Docker Compose, curl and jq  ·  Estimated time: 60 min

Three teams, three protected folders, one user per team and a service account for CI.

Setup #

Guided steps, with their solution.

  1. 1. Start Grafana

    Why? A throwaway instance lets you test safely.

    Start Grafana with Docker Compose and check /api/health.
    See the correction
    # docker-compose.yml
    services:
      grafana:
        image: grafana/grafana:latest
        ports: ["3000:3000"]
        environment:
          GF_SECURITY_ADMIN_PASSWORD: ChangeMe-2026
    docker compose up -d
    export GRAFANA=http://localhost:3000
    curl -s $GRAFANA/api/health
  2. 2. Create an admin service account

    Why? Scripts must not use the admin account.

    With the admin account, create the tp-admin service account (Admin role) and a one-day token.
    See the correction
    A=(-u admin:ChangeMe-2026 -H 'Content-Type: application/json')
    SA=$(curl -s "${A[@]}" -X POST $GRAFANA/api/serviceaccounts -d '{"name":"tp-admin","role":"Admin"}' | jq .id)
    export TOKEN=$(curl -s "${A[@]}" -X POST $GRAFANA/api/serviceaccounts/$SA/tokens -d '{"name":"tp","secondsToLive":86400}' | jq -r .key)
    H=(-H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json')
  3. 3. Create teams and users

    Why? Rights go to teams, never to people one by one.

    Create the Production, Infrastructure and Development teams, one user (Viewer role) per team, and add each user to their team.
    See the correction
    for t in prod infra dev; do
      TID=$(curl -s "${H[@]}" -X POST $GRAFANA/api/teams -d "{\"name\":\"$t\"}" | jq .teamId)
      # la création d'utilisateurs exige l'authentification basique d'un administrateur serveur
      UID_=$(curl -s "${A[@]}" -X POST $GRAFANA/api/admin/users -d "{\"login\":\"user-$t\",\"password\":\"Pass-$t-2026\",\"email\":\"$t@exemple.fr\"}" | jq .id)
      curl -s "${H[@]}" -X POST $GRAFANA/api/teams/$TID/members -d "{\"userId\":$UID_}"
    done
    curl -s "${H[@]}" "$GRAFANA/api/teams/search" | jq -r '.teams[] | "\(.id) \(.name) \(.memberCount)"'
  4. 4. One folder per team

    Why? Without removing default permissions, every Viewer would see every folder.

    Create one folder per team, give edit rights to the owning team and view rights to the Infrastructure team on the Production folder. Replace the default permissions.
    See the correction
    team() { curl -s "${H[@]}" "$GRAFANA/api/teams/search?name=$1" | jq '.teams[0].id'; }
    for t in prod infra dev; do curl -s "${H[@]}" -X POST $GRAFANA/api/folders -d "{\"uid\":\"f-$t\",\"title\":\"$t\"}" >/dev/null; done
    # POST .../permissions remplace toute la liste : les permissions par défaut (Viewer, Editor) disparaissent
    curl -s "${H[@]}" -X POST $GRAFANA/api/folders/f-prod/permissions -d "{\"items\":[{\"teamId\":$(team prod),\"permission\":2},{\"teamId\":$(team infra),\"permission\":1}]}"
    curl -s "${H[@]}" -X POST $GRAFANA/api/folders/f-infra/permissions -d "{\"items\":[{\"teamId\":$(team infra),\"permission\":2}]}"
    curl -s "${H[@]}" -X POST $GRAFANA/api/folders/f-dev/permissions -d "{\"items\":[{\"teamId\":$(team dev),\"permission\":2}]}"
    curl -s "${H[@]}" $GRAFANA/api/folders/f-prod/permissions | jq -r '.[] | "\(.team // .role) -> \(.permissionName)"'
  5. 5. Check access

    Why? Separation is proven by acting as each user.

    With each user account, list visible folders. Then explain why, in Grafana OSS, the Development team could still query data sources from Explore.
    See the correction
    for t in prod infra dev; do
      echo "== user-$t"; curl -s -u "user-$t:Pass-$t-2026" $GRAFANA/api/folders | jq -r '.[].title'
    done
    # Attendu : prod voit « prod » ; infra voit « infra » et « prod » (lecture) ; dev voit « dev ».
    # Les permissions de sources de données (Enterprise, Cloud) sont nécessaires pour empêcher un Viewer
    # d'interroger une source depuis Explore ; en OSS, il faut une organisation séparée.

Difficulty level : ●●●○○ (3/5)

My progress

  • ⏱ Estimated time : ≈ 1 h

Sign in to track your progress and take notes. Sign in

💬 Recent discussions about this course

Ask a question about this lesson →See all discussions about this course

Course Glossary

Alerting

The process of notifying teams (via email, Slack, Teams) when a specific event, threshold breach, or anomaly is detected.

HTTP Code 200 (OK)

An HTTP status code indicating that the client's request was successfully processed by the server.

HTTP Code 403 (Forbidden)

An HTTP status code indicating that the server understood the request but refuses to authorize it, usually due to a lack of permissions.

HTTP Code 404 (Not Found)

An HTTP status code indicating that the requested resource could not be found on the server.

Grafana

An open-source interactive data visualization platform that allows users to create, explore, and share analytic dashboards from multiple time-series d...

Recommended Articles

Grafana Assistant: AI at the service of observability

Discover Grafana Assistant, Grafana's AI assistant (Cloud, OSS and Enterprise). Learn how this la...

Grafana vs Kibana: which visualization tool to choose?

Discover the fundamental differences between Grafana, the king of multi-source metrics, and Kiban...

Grafana provisioning: automate the management of your dashboards and data sources

Learn how to use Grafana provisioning to manage your configuration (dashboards, data sources, not...

Git Sync in Grafana: version dashboards in GitHub

Sync Grafana dashboards and folders with a GitHub repository: prerequisites, token, setup in Admi...

Mimir: multi-tenancy, limits and runtime configuration

Isolate teams in Mimir: tenants and the X-Scope-OrgID header, gateway authentication, ingestion a...

Synthetic Monitoring in Grafana Cloud

Synthetic Monitoring in Grafana Cloud: HTTP, DNS, TCP, Ping, Traceroute, multi-step, k6 script an...

Application Observability in Grafana Cloud

Application Observability in Grafana Cloud: RED metrics from traces, service map, OpenTelemetry o...

Grafana Loki best practices: labels, queries, storage and costs

Loki best practices: choosing labels and cardinality, structured metadata, efficient LogQL querie...

Grafana IRM: on-call and incidents in Grafana Cloud

Grafana IRM in Grafana Cloud: on-call (OnCall) and incident management (Incident) combined. Alert...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!