Skip to content

Commit d228975

Browse files
authored
Merge pull request #218979 from maud-lv/ml-g-apikeys9
Use service accounts
2 parents ddb0d73 + 52272b6 commit d228975

File tree

10 files changed

+248
-5
lines changed

10 files changed

+248
-5
lines changed

articles/managed-grafana/how-to-create-api-keys.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ description: Learn how to generate and manage Grafana API keys, and start making
44
author: maud-lv
55
ms.author: malev
66
ms.service: managed-grafana
7+
ms.custom: engagement-fy23
78
ms.topic: how-to
8-
ms.date: 08/31/2022
9+
ms.date: 11/17/2022
910
---
1011

1112
# Generate and manage Grafana API keys in Azure Managed Grafana
1213

14+
> [!NOTE]
15+
> This document is deprecated as the API keys feature has been replaced by a new feature in Grafana 9.1. Go to [Service accounts](./how-to-service-accounts.md) to access the current recommended method to create and manage API keys.
16+
17+
> [!TIP]
18+
> To switch to using service accounts, in Grafana instances created before the release of Grafana 9.1, go to **Configuration > API keys and select Migrate to service accounts now**. Select **Yes, migrate now**. Each existing API keys will be automatically migrated into a service account with a token. The service account will be created with the same permission as the API Key and current API keys will continue to work as before.
19+
1320
In this guide, learn how to generate and manage API keys, and start making API calls to the Grafana server. Grafana API keys will enable you to create integrations between Azure Managed Grafana and other services.
1421

1522
## Prerequisites
@@ -19,7 +26,7 @@ In this guide, learn how to generate and manage API keys, and start making API c
1926

2027
## Enable API keys
2128

22-
API keys are disabled by default in Azure Managed Grafana. You can enable this feature during the creation of the instance on the Azure portal, or you can activate it on an existing instance, using the Azure portal or the CLI.
29+
API keys are disabled by default in Azure Managed Grafana. You can enable this feature during the creation of the instance in the Azure portal, or you can activate it on an existing instance, using the Azure portal or the CLI.
2330

2431
### Create an Azure Managed Grafana workspace with API key creation enabled
2532

@@ -59,7 +66,7 @@ az grafana update --name <azure-managed-grafana-name> --api-keys Enabled
5966
| **Managed Grafana role** | Choose a Managed Grafana role: Viewer, Editor or Admin. | *Editor* |
6067
| **Time to live** | Enter a time before your API key expires. Use *s* for seconds, *m* for minutes, *h* for hours, *d* for days, *w* for weeks, *M* for months, *y* for years. | 7d |
6168

62-
:::image type="content" source="media/create-api-keys/form.png" alt-text="Screenshot of the Grafana dashboard. API creation form filled out.":::
69+
:::image type="content" source="media/create-api-keys/form.png" alt-text="Screenshot of the Grafana dashboard. API creation form is filled out.":::
6370

6471
1. Once the key has been generated, a message pops up with the new key and a curl command including your key. Copy this information and save it in your records now, as it will be hidden once you leave this page. If you close this page without save the new API key, you'll need to generate a new one.
6572

@@ -135,7 +142,7 @@ az grafana api-key delete --name <azure-managed-grafana-name> --key <key>
135142

136143
## Next steps
137144

138-
In this how-to guide, you learned how to create an API key for Azure Managed Grafana. To learn how to call Grafana APIs, see:
145+
In this how-to guide, you learned how to create an API key for Azure Managed Grafana. When you're ready, start using service accounts as the new way to authenticate applications that interact with Grafana:
139146

140147
> [!div class="nextstepaction"]
141-
> [Call Grafana APIs](how-to-api-calls.md)
148+
> [User service accounts](how-to-service-accounts.md)
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
---
2+
title: How to use service accounts in Azure Managed Grafana
3+
description: In this guide, learn how to use service accounts in Azure Managed Grafana.
4+
author: maud-lv
5+
ms.author: malev
6+
ms.service: managed-grafana
7+
ms.topic: how-to
8+
ms.date: 11/30/2022
9+
---
10+
11+
# How to use service accounts in Azure Managed Grafana
12+
13+
In this guide, learn how to use service accounts. Service accounts are used to run automated operations and authenticate applications in Grafana with the Grafana API.
14+
15+
Common use cases include:
16+
17+
- Provisioning or configuring dashboards
18+
- Scheduling reports
19+
- Defining alerts
20+
- Setting up an external SAML authentication provider
21+
- Interacting with Grafana without signing in as a user
22+
23+
## Prerequisites
24+
25+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free).
26+
- An Azure Managed Grafana instance. If you don't have one yet, [create an Azure Managed Grafana instance](./quickstart-managed-grafana-portal.md).
27+
28+
## Enable service accounts
29+
30+
Service accounts are disabled by default in Azure Managed Grafana. If your existing Grafana workspace doesn't have service accounts enabled, you can enable them by updating the preference settings of your Grafana instance.
31+
32+
### [Portal](#tab/azure-portal)
33+
34+
1. In the Azure portal, under **Settings**, select **Configuration**, and then under **API keys and service accounts**, select **Enable**.
35+
36+
:::image type="content" source="media/service-accounts/enable.png" alt-text="Screenshot of the Azure platform. Enable service accounts.":::
37+
1. Select **Save** to confirm that you want to enable API keys and service accounts in Azure Managed Grafana.
38+
39+
### [Azure CLI](#tab/azure-cli)
40+
41+
1. Azure Managed Grafana CLI extension 0.3.0 or above is required. To update your extension, run `az extension update --name amg`.
42+
1. Run the [az grafana update](/cli/azure/grafana#az-grafana-update) command to enable the creation of API keys and service accounts in an existing Azure Managed Grafana instance. In the command below, replace `<azure-managed-grafana-name>` with the name of the Azure Managed Grafana instance to update.
43+
44+
```azurecli-interactive
45+
az grafana update --name <azure-managed-grafana-name> ---service-account Enabled
46+
```
47+
48+
---
49+
50+
## Create a service account
51+
52+
Follow the steps below to create a new Grafana service account and list existing service accounts:
53+
54+
### [Portal](#tab/azure-portal)
55+
56+
1. Go to your Grafana instance endpoint, and under **Configuration**, select **Service accounts**.
57+
1. Select **Add service account**, and enter a **Display name** and a **Role** for your new Grafana service account: *Viewer*, *Editor* or *Admin* and select **Create**.
58+
59+
:::image type="content" source="media/service-accounts/service-accounts.png" alt-text="Screenshot of Grafana. Add service account page.":::
60+
1. The page displays the notification *Service account successfully created* and some information about your new service account.
61+
1. Select the back arrow sign to view a list of all the service accounts of your Grafana instance.
62+
63+
### [Azure CLI](#tab/azure-cli)
64+
65+
Run the `az grafana service-account create` command to create a service account. Replace the placeholders `<azure-managed-grafana-name>`, `<service-account-name>` and `<role>` with your own information.
66+
67+
Available roles: `Admin`, `Editor`, `Viewer`.
68+
69+
```azurecli-interactive
70+
az grafana service-account create --name <azure-managed-grafana-name> --service-account <service-account-name> --role <role>
71+
```
72+
73+
#### List service accounts
74+
75+
Run the `az grafana service-account list` command to get a list of all service accounts that belong to a given Azure Managed Grafana instance. Replace `<azure-managed-grafana-name>` with the name of your Azure Managed Grafana workspace.
76+
77+
```azurecli-interactive
78+
az grafana service-account list --name <azure-managed-grafana-name> --output table
79+
```
80+
81+
Example of output:
82+
83+
```output
84+
AvatarUrl IsDisabled Login Name OrgId Role Tokens
85+
-------------------- ------------ ----------- ---------- ------- ------ --------
86+
/avatar/abc12345678 False sa-account1 account1 1 Viewer 0
87+
```
88+
89+
#### Display service account details
90+
91+
Run the `az grafana service-account show` command to get the details of a service account. Replace `<azure-managed-grafana-name>` and `<service-account-name>` with your own information.
92+
93+
```azurecli-interactive
94+
az grafana service-account show --name <azure-managed-grafana-name> --service-account <service-account-name>
95+
```
96+
97+
---
98+
99+
## Add a service account token and review tokens
100+
101+
Once you've created a service account, add one or more access tokens. Access tokens are generated strings used to authenticate to the Grafana API.
102+
103+
### [Portal](#tab/azure-portal)
104+
105+
1. To create a service account token, select **Add token**.
106+
1. Use the automatically generated **Display name** or enter a name of your choice, and optionally select an **Expiration date** or keep the default option to set no expiry date.
107+
108+
:::image type="content" source="media/service-accounts/add-service-account-token.png" alt-text="Screenshot of the Azure platform. Add service account token page.":::
109+
110+
1. Select **Generate token**, and take note of the token generated. This token will only be shown once, so make sure you save it, as loosing a token requires creating a new one.
111+
1. Select the service account to access information about your service account, including a list of all associated tokens.
112+
113+
### [Azure CLI](#tab/azure-cli)
114+
115+
#### Create a new token
116+
117+
1. Create a Grafana service account token with `az grafana service-account token create`. Replace the placeholders `<azure-managed-grafana-name>`, `<service-account-name>` and `<token-name>` with your own information.
118+
119+
Optionally set an expiry time:
120+
121+
| Parameter | Description | Example |
122+
|---------------|----------------------------------------------------------------------------------------------------------------|-------------------|
123+
| `--time-to-live` | Tokens have an unlimited expiry date by default. Set an expiry time to disable the token after a given time. Use `s` for seconds, `m` for minutes, `h` for hours, `d` for days, `w` for weeks, `M` for months or `y` for years. | `15d` |
124+
125+
```azurecli-interactive
126+
az grafana service-account token create --name <azure-managed-grafana-name> --service-account <service-account-name> --token <token-name> --time-to-live 15d
127+
```
128+
129+
1. Take note of the generated token. This token will only be shown once, so make sure you save it, as loosing a token requires creating a new one.
130+
131+
#### List service account tokens
132+
133+
Run the `az grafana service-account token list` command to get a list of all tokens that belong to a given service account. Replace the placeholders `<azure-managed-grafana-name>` and `<service-account-name>` with your own information.
134+
135+
```azurecli-interactive
136+
az grafana service-account token list --name <azure-managed-grafana-name> --service-account <service-account-name> --output table
137+
```
138+
139+
Example of output:
140+
141+
```output
142+
Created Expiration HasExpired Name SecondsUntilExpiration
143+
-------------------- -------------------- ------------ ------ ------------------------
144+
2022-12-07T11:40:45Z 2022-12-08T11:40:45Z False token1 85890.870731556
145+
2022-12-07T11:42:35Z 2022-12-22T11:42:35Z False token2 0
146+
```
147+
148+
---
149+
150+
## Edit a service account
151+
152+
In this section, learn how to update a Grafana service account in the following ways:
153+
154+
- Edit the name of a service account
155+
- Edit the role of a service account
156+
- Disable a service account
157+
- Enable a service account
158+
159+
### [Portal](#tab/azure-portal)
160+
161+
Actions:
162+
163+
- To edit the name, select the service account and under **Information** select **Edit**.
164+
- To edit the role, select the service account and under **Information**, select the role and choose another role name.
165+
- To disable a service account, select a service account and at the top of the page select **Disable service account**, then select **Disable service account** to confirm. Disabled service accounts can be re-enabled by selecting **Enable service account**.
166+
167+
:::image type="content" source="media/service-accounts/edit-service-account.png" alt-text="Screenshot of the Azure platform. Edit service account page.":::
168+
169+
The notification *Service account updated* is instantly displayed.
170+
171+
### [Azure CLI](#tab/azure-cli)
172+
173+
Edit a service account with `az grafana service-account update`. Replace the placeholders `<azure-managed-grafana-name>`, and `<service-account-name>` with your own information and use one or several of the following parameters:
174+
175+
| Parameter | Description |
176+
|-----------------|-------------------------------------------------------------------------------------------------------------|
177+
| `--is-disabled` | Enter `--is-disabled true` disable a service account, or `--is-disabled false` to enable a service account. |
178+
| `--name` | Enter another name for your service account. |
179+
| `--role` | Enter another role for your service account. Available roles: `Admin`, `Editor`, `Viewer`. |
180+
181+
```azurecli-interactive
182+
az grafana service-account update --name <azure-managed-grafana-name> --service-account <service-account-name> --role <role> --enabled false
183+
```
184+
185+
To disable a service account run the `az grafana update` command and use the option `--is-disabled true`. To enable a service account, use `--is-disabled false`.
186+
187+
```azurecli-interactive
188+
az grafana update --service-account Disabled --name <service-account-name>
189+
```
190+
191+
---
192+
193+
## Delete a service account
194+
195+
### [Portal](#tab/azure-portal)
196+
197+
To delete a Grafana service account, select a service account and at the top of the page select **Delete service account**, then select **Delete service account** to confirm. Deleting a service account is final and a service account can't be recovered once deleted.
198+
199+
:::image type="content" source="media/service-accounts/delete.png" alt-text="Screenshot of the Azure platform. Deleting service account page.":::
200+
201+
### [Azure CLI](#tab/azure-cli)
202+
203+
To delete a service account, run the `az grafana service-account delete` command. Replace the placeholders `<azure-managed-grafana-name>` and `<service-account-name>` with your own information.
204+
205+
```azurecli-interactive
206+
az grafana service-account delete --name <azure-managed-grafana-name> --service-account <service-account-name>
207+
```
208+
209+
---
210+
211+
## Delete a service account token
212+
213+
### [Portal](#tab/azure-portal)
214+
215+
To delete a service account token, select a service account and under **Tokens**, select **Delete (x)**. Select **Delete** to confirm.
216+
217+
:::image type="content" source="media/service-accounts/delete-token.png" alt-text="Screenshot of the Azure platform. Deleting service account token page.":::
218+
219+
### [Azure CLI](#tab/azure-cli)
220+
221+
To delete a service account, run the `az grafana service-account token delete` command. Replace the placeholders `<azure-managed-grafana-name>`, `<service-account-name>` and `<token-name>` with your own information.
222+
223+
```azurecli-interactive
224+
az grafana service-account token delete --name <azure-managed-grafana-name> --service-account <service-account-name> --toke <token-name>
225+
```
226+
227+
---
228+
229+
## Next steps
230+
231+
In this how-to guide, you learned how to create and manage service accounts and tokens to run automated operations in Azure Managed Grafana. When you're ready, explore more articles:
232+
233+
> [!div class="nextstepaction"]
234+
> [Enable zone redundancy](how-to-enable-zone-redundancy.md)
90.8 KB
Loading
26.6 KB
Loading
5.07 KB
Loading
46.6 KB
Loading
90.6 KB
Loading
34.2 KB
Loading
56.7 KB
Loading

articles/managed-grafana/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ items:
3939
href: how-to-share-grafana-workspace.md
4040
- name: Monitor a Managed Grafana instance
4141
href: how-to-monitor-managed-grafana-workspace.md
42+
- name: Use service accounts
43+
href: how-to-service-accounts.md
4244
- name: Create and manage API keys
4345
href: how-to-create-api-keys.md
4446
- name: Enable zone redundancy

0 commit comments

Comments
 (0)