Installation

Install as Agent Plugin Recommended
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install admin@skills-hub

Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled). Plugin admin v1.0.0 follows the Agent Plugins spec.

Install with the gh extension
gh skills-hub install admin

Don't have the extension? Run gh extension install samueltauil/skills-hub first.

Download and extract to your repository:

.github/skills/admin/

Extract the ZIP to .github/skills/ in your repo. The folder name must match admin for Copilot to auto-discover it.

Skill Files (4)

SKILL.md 5.8 KB
---
name: admin
license: Apache-2.0
description: Manage Grafana Cloud accounts — organizations, stacks, RBAC roles and assignments, SSO/SAML/OAuth/GitHub auth, service accounts for CI/CD, user invites, team membership, and API-driven provisioning. Creates stacks via the Cloud API, mints service-account tokens, applies role assignments, configures SSO providers, and provisions teams/folders/dashboards via Terraform. Use when managing Grafana Cloud access, configuring SSO/SAML/OAuth, setting up service accounts for Terraform/CI/CD, assigning RBAC roles, inviting users, managing multiple stacks or organizations, provisioning cloud resources via API or Terraform, or auditing admin actions — even when the user says "set up SSO", "create a stack", "make a service account", or "onboard a team" without explicitly saying "admin".
---

# Grafana Cloud Admin

> **Docs**: https://grafana.com/docs/grafana-cloud/account-management.md

## Common Workflows

### Setting up a new stack

```bash
# 1. Create the stack via Cloud API
curl -X POST https://grafana.com/api/instances \
  -H "Authorization: Bearer <grafana-com-api-key>" \
  -H "Content-Type: application/json" \
  -d '{"name": "my-new-stack", "slug": "my-new-stack", "region": "us-east-0", "plan": "grafana-cloud-free"}'

# 2. Verify the stack is reachable (poll until 200)
until curl -fs https://my-new-stack.grafana.net/api/health > /dev/null; do sleep 2; done

# 3. Mint an admin service-account token (see § Service Accounts below)

# 4. Test the token
curl https://my-new-stack.grafana.net/api/org -H "Authorization: Bearer <token>"
# Returns 200 + org JSON → token works
```

### Onboarding a team

1. Invite users via `POST /api/org/invites` (one curl per user — see [references/api-reference.md § Stack API](references/api-reference.md#stack-api--user--team--org-management))
2. Create the team via `POST /api/teams`
3. Add each user via `POST /api/teams/{teamId}/members`
4. Assign an RBAC role to the team (see [§ RBAC](#rbac) below)
5. Verify: `GET /api/teams/{teamId}/members` returns the expected user list

### Configuring SSO (Okta / SAML / GitHub)

1. Pick the provider config from [references/sso.md](references/sso.md) and drop into `grafana.ini`
2. Restart Grafana
3. **Always validate in an incognito window before announcing**: see [references/sso.md § Verifying SSO](references/sso.md#verifying-sso) for the 5-step verification + role-mapping debug pattern

### Deleting a stack (destructive)

```bash
# 1. Delete via Cloud API
curl -X DELETE https://grafana.com/api/instances/{id} \
  -H "Authorization: Bearer <grafana-com-api-key>"

# 2. Verify the stack is gone (must return 404)
curl https://grafana.com/api/instances/{id} \
  -H "Authorization: Bearer <grafana-com-api-key>"
```

If the GET still returns 200 after a few seconds, the delete didn't apply — re-check the stack ID and Cloud API key.

## Organization and Stack Structure

```
Grafana Cloud Account
└── Organization (billing unit)
    ├── Stack 1 (prod)   → dedicated Grafana, Prometheus, Loki, Tempo URLs
    ├── Stack 2 (staging)
    └── Stack 3 (dev)
```

- **Organization**: top-level account with billing, users, API keys, stacks
- **Stack**: dedicated Grafana + LGTM instance with its own URLs and credentials

## User Roles

| Role | Scope | Permissions |
|------|-------|-------------|
| **Org Admin** | Organization | Manage stacks, users, billing, API keys |
| **Admin** | Stack | Data sources, plugins, users, provisioning |
| **Editor** | Stack | Create/edit dashboards, alerts |
| **Viewer** | Stack | Read-only dashboards |

## RBAC

Define a custom role + assignment in provisioning YAML:

```yaml
# provisioning/access-control/roles.yaml
apiVersion: 1
roles:
  - name: TeamDashboardEditor
    description: Edit dashboards within team folder
    permissions:
      - action: dashboards:read
        scope: folders:UID:team-folder
      - action: dashboards:write
        scope: folders:UID:team-folder
      - action: dashboards:create
        scope: folders:UID:team-folder
```

```yaml
# provisioning/access-control/assignments.yaml
apiVersion: 1
roleAssignments:
  - roleName: TeamDashboardEditor
    users:
      - alice@example.com
      - bob@example.com
    teams:
      - platform-team
```

After committing the YAML and restarting Grafana, verify the role applied: `GET /api/access-control/roles | jq '.[] | select(.name=="TeamDashboardEditor")'`.

## Service Accounts

Service accounts are the recommended way for programmatic access (CI/CD, Terraform, agents).

```bash
# 1. Create the service account
curl -X POST https://yourstack.grafana.net/api/serviceaccounts \
  -H "Authorization: Bearer <admin-token>" \
  -H "Content-Type: application/json" \
  -d '{"name": "terraform-provisioner", "role": "Admin", "isDisabled": false}'

# 2. Mint a token for it
curl -X POST https://yourstack.grafana.net/api/serviceaccounts/{id}/tokens \
  -H "Authorization: Bearer <admin-token>" \
  -H "Content-Type: application/json" \
  -d '{"name": "ci-token", "secondsToLive": 0}'

# 3. Verify the token works (test on a harmless endpoint)
curl https://yourstack.grafana.net/api/org \
  -H "Authorization: Bearer <new-token>"
# 200 + org JSON → token works. Anything else → re-check role assignment in step 1.
```

Provisioning equivalent (YAML, declarative):

```yaml
# provisioning/access-control/service_accounts.yaml
apiVersion: 1
serviceAccounts:
  - name: alloy-writer
    orgId: 1
    role: Editor
    tokens:
      - name: alloy-token
```

## References

- [`references/sso.md`](references/sso.md) — OAuth / SAML / GitHub OAuth config + the 5-step SSO verification pattern + common failure modes
- [`references/terraform.md`](references/terraform.md) — Terraform provider config + common resource patterns (teams, users, folders, dashboards) + drift troubleshooting
- [`references/api-reference.md`](references/api-reference.md) — full Cloud API + Stack API endpoint reference + audit-log queries
references/
api-reference.md 2.6 KB
# Admin API reference

Endpoints split by audience: Cloud-level (manage stacks, orgs from grafana.com) vs Stack-level (per-instance Grafana API).

## Contents

- [Cloud API — stack management](#cloud-api-stack-management)
- [Stack API — user / team / org management](#stack-api-user-team-org-management)
- [Audit logs](#audit-logs)

## Cloud API — stack management

Base URL: `https://grafana.com/api/`. Auth: grafana.com API key.

```bash
# List stacks
curl https://grafana.com/api/instances \
  -H "Authorization: Bearer <grafana-com-api-key>"

# Create stack
curl -X POST https://grafana.com/api/instances \
  -H "Authorization: Bearer <grafana-com-api-key>" \
  -H "Content-Type: application/json" \
  -d '{"name": "my-new-stack", "slug": "my-new-stack", "region": "us-east-0", "plan": "grafana-cloud-free"}'

# Verify stack is reachable (poll until 200)
curl https://my-new-stack.grafana.net/api/health

# Delete stack
curl -X DELETE https://grafana.com/api/instances/{id} \
  -H "Authorization: Bearer <grafana-com-api-key>"

# Verify deletion
curl https://grafana.com/api/instances/{id} \
  -H "Authorization: Bearer <grafana-com-api-key>"
# Should return 404
```

## Stack API — user / team / org management

Base URL: `https://yourstack.grafana.net/api/`. Auth: Grafana service account token.

```bash
# List org users
GET /api/org/users

# Invite user to org
POST /api/org/invites
Body: { "loginOrEmail": "user@example.com", "role": "Editor", "sendEmail": true }

# Update user org role
PATCH /api/org/users/{userId}
Body: { "role": "Admin" }

# List teams
GET /api/teams/search?name=platform

# Create team
POST /api/teams
Body: { "name": "Platform Team", "email": "platform@example.com" }

# Add user to team
POST /api/teams/{teamId}/members
Body: { "userId": 2 }

# Look up a user (useful after SSO config changes)
GET /api/users/lookup?loginOrEmail=alice@example.com
```

## Audit logs

```bash
# Query audit logs (Enterprise / Cloud only)
GET /api/admin/auditlogs?query=login&from=1706745600&to=1706832000&limit=50
```

`from` and `to` are Unix epoch seconds. The `query` parameter is a free-text search over event names (`login`, `dashboard.create`, `team.member.add`, etc.).

## Common failure modes

| Symptom | Likely cause |
|---|---|
| `401 Unauthorized` | Token expired or wrong stack URL — check `Authorization` header |
| `403 Forbidden` on `/api/admin/*` | Service account lacks `Admin` role on the org |
| `404` on a known stack | Wrong region in URL (`us-east-0` vs `eu-west-0`) |
| Audit logs empty for a known event | Audit logging may not be enabled on free tier — confirm Enterprise/Cloud subscription |
sso.md 3.0 KB
# SSO / Auth Configuration

Provider-specific `grafana.ini` blocks. Drop one of these into your config, restart Grafana, then validate the login flow per [§ Verifying SSO](#verifying-sso) below.

## Generic OAuth (e.g. Okta)

```ini
[auth.generic_oauth]
enabled = true
name = Okta
allow_sign_up = true
client_id = your_client_id
client_secret = your_client_secret
scopes = openid profile email groups
auth_url = https://your-org.okta.com/oauth2/v1/authorize
token_url = https://your-org.okta.com/oauth2/v1/token
api_url = https://your-org.okta.com/oauth2/v1/userinfo
role_attribute_path = contains(groups[*], 'grafana-admins') && 'Admin' || 'Viewer'
groups_attribute_path = groups
```

## SAML (Enterprise / Cloud)

```ini
[auth.saml]
enabled = true
certificate_path = /etc/grafana/saml/grafana.crt
private_key_path = /etc/grafana/saml/grafana.key
idp_metadata_path = /etc/grafana/saml/idp-metadata.xml
max_issue_delay = 90s
metadata_valid_duration = 48h
assertion_attribute_login = mail
assertion_attribute_email = mail
assertion_attribute_name = displayName
assertion_attribute_role = role
role_values_admin = grafana-admins
role_values_editor = grafana-editors
```

## GitHub OAuth

```ini
[auth.github]
enabled = true
allow_sign_up = true
client_id = your_github_client_id
client_secret = your_github_client_secret
scopes = user:email,read:org
auth_url = https://github.com/login/oauth/authorize
token_url = https://github.com/login/oauth/access_token
api_url = https://api.github.com/user
allowed_organizations = ["your-org"]
team_ids = [123456]
role_attribute_path = "Admin"
```

## Verifying SSO

After restart, before announcing the change to users:

1. **Open the login page in an incognito window.** The new provider button should be visible.
2. **Click the provider button.** You should be redirected to the IdP, then back to Grafana logged in.
3. **Check the user's role.** Hit `https://yourstack.grafana.net/api/users/lookup?loginOrEmail=<your-email>` — the response's `role` field should match what your `role_attribute_path` / `role_values_*` mapping should have produced.
4. **If the role is wrong**, look at the IdP's actual claims:
   ```bash
   # Grafana logs the parsed claims on debug-level auth login
   journalctl -u grafana-server | grep -i "OAuth\|SAML" | tail -50
   ```
   The fix is almost always a mismatch between the claim path and the IdP's actual response shape.

5. **If login itself fails**, check `auth_url` / `token_url` / `api_url` for typos and confirm the IdP's allowed redirect URIs include `https://yourstack.grafana.net/login/<provider>`.

## Common failure modes

| Symptom | Likely cause |
|---|---|
| 500 after redirect from IdP | Wrong `token_url` or expired `client_secret` |
| User logs in but no role assigned | `role_attribute_path` expression doesn't match the IdP's claim shape |
| `redirect_uri_mismatch` from IdP | The IdP's app config is missing `https://yourstack.grafana.net/login/<provider>` as an allowed redirect URI |
| SAML "invalid signature" | Stale `idp_metadata.xml` — re-fetch from the IdP |
terraform.md 2.0 KB
# Terraform provider for Grafana

Use the official `grafana/grafana` Terraform provider for declarative management of teams, users, folders, dashboards, data sources, etc.

## Minimum viable provider block

```hcl
terraform {
  required_providers {
    grafana = {
      source  = "grafana/grafana"
      version = "~> 2.0"
    }
  }
}

provider "grafana" {
  url  = "https://yourstack.grafana.net"
  auth = var.grafana_service_account_token   # store in tfvars / env, not literal
}
```

## Common resource patterns

### Teams + membership

```hcl
resource "grafana_team" "platform" {
  name  = "Platform Team"
  email = "platform@example.com"
}

resource "grafana_user" "alice" {
  email    = "alice@example.com"
  login    = "alice"
  name     = "Alice"
  password = "changeme"   # ignored when SSO is configured
}

resource "grafana_team_member" "platform_alice" {
  team_id = grafana_team.platform.id
  user_id = grafana_user.alice.id
}
```

### Folders + dashboards

```hcl
resource "grafana_folder" "platform_dashboards" {
  title = "Platform Dashboards"
}

resource "grafana_dashboard" "overview" {
  folder      = grafana_folder.platform_dashboards.uid
  config_json = file("dashboards/overview.json")
}
```

## Validating the apply

After `terraform apply`:

1. `terraform plan` — should be clean (no drift)
2. Confirm in the Grafana UI:
   - Teams → "Platform Team" present with the expected members
   - Dashboards → folder + dashboard visible
3. If a resource shows as drift on the next plan but you haven't touched it: someone is modifying the same resource in the UI. Either reclaim it via Terraform (move all changes to code) or exclude it (use the `ignore_changes` lifecycle block).

## Common failure modes

| Symptom | Likely cause |
|---|---|
| `401 Unauthorized` on apply | Service account token expired or wrong stack URL |
| `409 Conflict` on resource create | Resource already exists in Grafana; import it first (`terraform import`) |
| Drift on every plan despite no UI changes | Provisioning files on disk modifying the same resource; pick one source of truth |

License (Apache-2.0)

View full license text
Licensed under the Apache License, Version 2.0. See https://github.com/grafana/skills/blob/main/LICENSE