2022-05-26 10:06:25 -05:00
---
aliases:
2022-12-09 10:36:04 -06:00
- ../../../auth/azuread/
2022-06-02 11:57:22 -05:00
description: Grafana Azure AD OAuth Guide
2022-05-26 10:06:25 -05:00
keywords:
- grafana
- configuration
- documentation
- oauth
Explicitly set all front matter labels in the source files (#71548)
* Set every page to have defaults of 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/enterprise-licensing pages to have 'Enterprise' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/recorded-queries pages to have labels cloud,enterprise
* Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/stats-and-license pages to have labels cloud,enterprise
* Set alerting pages to have labels cloud,enterprise,oss
* Set breaking-changes pages to have labels cloud,enterprise,oss
* Set dashboards pages to have labels cloud,enterprise,oss
* Set datasources pages to have labels cloud,enterprise,oss
* Set explore pages to have labels cloud,enterprise,oss
* Set fundamentals pages to have labels cloud,enterprise,oss
* Set introduction/grafana-cloud pages to have labels cloud
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Fix introduction pages products
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set panels-visualizations pages to have labels cloud,enterprise,oss
* Set release-notes pages to have labels cloud,enterprise,oss
* Set search pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set troubleshooting pages to have labels cloud,enterprise,oss
* Set whatsnew pages to have labels cloud,enterprise,oss
* Apply updated labels from review
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
---------
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 03:10:12 -05:00
labels:
products:
- cloud
- enterprise
- oss
2023-06-29 07:44:33 -05:00
menuTitle: Azure AD OAuth2
Explicitly set all front matter labels in the source files (#71548)
* Set every page to have defaults of 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/enterprise-licensing pages to have 'Enterprise' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/recorded-queries pages to have labels cloud,enterprise
* Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/stats-and-license pages to have labels cloud,enterprise
* Set alerting pages to have labels cloud,enterprise,oss
* Set breaking-changes pages to have labels cloud,enterprise,oss
* Set dashboards pages to have labels cloud,enterprise,oss
* Set datasources pages to have labels cloud,enterprise,oss
* Set explore pages to have labels cloud,enterprise,oss
* Set fundamentals pages to have labels cloud,enterprise,oss
* Set introduction/grafana-cloud pages to have labels cloud
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Fix introduction pages products
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set panels-visualizations pages to have labels cloud,enterprise,oss
* Set release-notes pages to have labels cloud,enterprise,oss
* Set search pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set troubleshooting pages to have labels cloud,enterprise,oss
* Set whatsnew pages to have labels cloud,enterprise,oss
* Apply updated labels from review
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
---------
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 03:10:12 -05:00
title: Configure Azure AD OAuth2 authentication
2023-06-29 07:44:33 -05:00
weight: 800
2022-05-26 10:06:25 -05:00
---
2020-02-13 03:12:25 -06:00
2022-06-02 11:57:22 -05:00
# Configure Azure AD OAuth2 authentication
2020-02-13 03:12:25 -06:00
2021-10-04 10:14:33 -05:00
The Azure AD authentication allows you to use an Azure Active Directory tenant as an identity provider for Grafana. You can use Azure AD Application Roles to assign users and groups to Grafana roles from the Azure Portal. This topic has the following sections:
2020-03-10 11:15:25 -05:00
2023-05-30 11:17:45 -05:00
- [Configure Azure AD OAuth2 authentication ](#configure-azure-ad-oauth2-authentication )
2022-03-10 03:28:16 -06:00
- [Create the Azure AD application ](#create-the-azure-ad-application )
2023-05-30 11:17:45 -05:00
- [Assign server administrator privileges ](#assign-server-administrator-privileges )
2022-03-10 03:28:16 -06:00
- [Enable Azure AD OAuth in Grafana ](#enable-azure-ad-oauth-in-grafana )
2023-05-30 11:17:45 -05:00
- [Configure refresh token ](#configure-refresh-token )
2023-07-14 07:03:01 -05:00
- [Configure allowed tenants ](#configure-allowed-tenants )
2022-03-10 03:28:16 -06:00
- [Configure allowed groups ](#configure-allowed-groups )
- [Configure allowed domains ](#configure-allowed-domains )
2023-05-30 11:17:45 -05:00
- [PKCE ](#pkce )
- [Configure automatic login ](#configure-automatic-login )
2022-03-10 03:28:16 -06:00
- [Team Sync (Enterprise only) ](#team-sync-enterprise-only )
2023-05-30 11:17:45 -05:00
- [Common troubleshooting ](#common-troubleshooting )
- [Users with over 200 Group assignments ](#users-with-over-200-group-assignments )
- [Force fetching groups from Microsoft graph API ](#force-fetching-groups-from-microsoft-graph-api )
- [Map roles ](#map-roles )
- [Skip organization role sync ](#skip-organization-role-sync )
2020-02-13 03:12:25 -06:00
2020-02-14 05:03:00 -06:00
## Create the Azure AD application
2020-02-13 03:12:25 -06:00
2021-10-04 10:14:33 -05:00
To enable the Azure AD OAuth2, register your application with Azure AD.
2020-02-13 03:12:25 -06:00
2021-10-04 10:14:33 -05:00
1. Log in to [Azure Portal ](https://portal.azure.com ), then click **Azure Active Directory** in the side menu.
2020-02-13 03:12:25 -06:00
2021-10-04 10:14:33 -05:00
1. If you have access to more than one tenant, select your account in the upper right. Set your session to the Azure AD tenant you wish to use.
2020-02-13 03:12:25 -06:00
2021-10-04 10:14:33 -05:00
1. Under **Manage** in the side menu, click **App Registrations** > **New Registration** . Enter a descriptive name.
2020-02-13 03:12:25 -06:00
2021-10-04 10:14:33 -05:00
1. Under **Redirect URI** , select the app type **Web** .
2020-02-13 03:12:25 -06:00
2021-10-04 10:14:33 -05:00
1. Add the following redirect URLs `https://<grafana domain>/login/azuread` and `https://<grafana domain>` then click **Register** . The app's **Overview** page opens.
1. Note the **Application ID** . This is the OAuth client ID.
2020-02-13 03:12:25 -06:00
2020-07-20 14:39:23 -05:00
1. Click **Endpoints** from the top menu.
2021-10-04 10:14:33 -05:00
- Note the **OAuth 2.0 authorization endpoint (v2)** URL. This is the authorization URL.
2021-07-14 11:55:25 -05:00
- Note the **OAuth 2.0 token endpoint (v2)** . This is the token URL.
2020-02-13 03:12:25 -06:00
2021-10-04 10:14:33 -05:00
1. Click **Certificates & secrets** , then add a new entry under **Client secrets** with the following configuration.
2020-02-13 03:12:25 -06:00
2021-07-14 11:55:25 -05:00
- Description: Grafana OAuth
- Expires: Never
2021-10-04 10:14:33 -05:00
1. Click **Add** then copy the key value. This is the OAuth client secret.
2020-02-13 03:12:25 -06:00
2021-10-04 10:14:33 -05:00
1. Click **Manifest** , then define the required Application Role values for Grafana: Viewer, Editor, or Admin. If not defined, all users will have the Viewer role. Every role requires a unique ID which you can generate on Linux with `uuidgen` , and on Windows through Microsoft PowerShell with `New-Guid` .
2021-07-14 11:55:25 -05:00
2021-10-04 10:14:33 -05:00
1. Include the unique ID in the configuration file:
2020-02-13 03:12:25 -06:00
2022-03-10 03:28:16 -06:00
```json
"appRoles": [
{
"allowedMemberTypes": [
"User"
],
2022-09-08 05:11:00 -05:00
"description": "Grafana org admin Users",
"displayName": "Grafana Org Admin",
2022-03-10 03:28:16 -06:00
"id": "SOME_UNIQUE_ID",
"isEnabled": true,
"lang": null,
"origin": "Application",
"value": "Admin"
},
{
"allowedMemberTypes": [
"User"
],
"description": "Grafana read only Users",
"displayName": "Grafana Viewer",
"id": "SOME_UNIQUE_ID",
"isEnabled": true,
"lang": null,
"origin": "Application",
"value": "Viewer"
},
{
"allowedMemberTypes": [
"User"
],
"description": "Grafana Editor Users",
"displayName": "Grafana Editor",
"id": "SOME_UNIQUE_ID",
"isEnabled": true,
"lang": null,
"origin": "Application",
"value": "Editor"
}
],
```
2020-02-13 03:12:25 -06:00
2020-07-08 18:30:15 -05:00
1. Go to **Azure Active Directory** and then to **Enterprise Applications** . Search for your application and click on it.
2020-02-13 03:12:25 -06:00
2020-11-09 14:26:49 -06:00
1. Click on **Users and Groups** and add Users/Groups to the Grafana roles by using **Add User** .
2020-02-13 03:12:25 -06:00
2022-09-08 05:11:00 -05:00
### Assign server administrator privileges
> Available in Grafana v9.2 and later versions.
If the application role received by Grafana is `GrafanaAdmin` , Grafana grants the user server administrator privileges.
This is useful if you want to grant server administrator privileges to a subset of users.
Grafana also assigns the user the `Admin` role of the default organization.
The setting `allow_assign_grafana_admin` under `[auth.azuread]` must be set to `true` for this to work.
If the setting is set to `false` , the user is assigned the role of `Admin` of the default organization, but not server administrator privileges.
```json
{
"allowedMemberTypes": ["User"],
"description": "Grafana server admin Users",
"displayName": "Grafana Server Admin",
"id": "SOME_UNIQUE_ID",
"isEnabled": true,
"lang": null,
"origin": "Application",
"value": "GrafanaAdmin"
}
```
2020-05-13 04:23:01 -05:00
## Enable Azure AD OAuth in Grafana
2020-02-14 05:03:00 -06:00
2023-05-18 09:50:20 -05:00
1. Add the following to the [Grafana configuration file ]({{< relref "../../../configure-grafana#configuration-file-location" >}} ):
2020-02-13 03:12:25 -06:00
2021-10-04 10:14:33 -05:00
```
2020-02-13 03:12:25 -06:00
[auth.azuread]
name = Azure AD
enabled = true
allow_sign_up = true
2023-01-19 08:53:02 -06:00
auto_login = false
2020-02-13 03:12:25 -06:00
client_id = APPLICATION_ID
client_secret = CLIENT_SECRET
scopes = openid email profile
auth_url = https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/authorize
token_url = https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token
2020-02-14 05:03:00 -06:00
allowed_domains =
allowed_groups =
2023-06-16 11:29:09 -05:00
allowed_organizations = TENANT_ID
2022-03-18 05:34:16 -05:00
role_attribute_strict = false
2022-09-08 05:11:00 -05:00
allow_assign_grafana_admin = false
2023-01-16 06:16:01 -06:00
skip_org_role_sync = false
2023-05-30 11:17:45 -05:00
use_pkce = true
2020-02-13 03:12:25 -06:00
```
2021-09-15 20:47:03 -05:00
You can also use these environment variables to configure **client_id** and **client_secret** :
2021-09-20 02:08:00 -05:00
2021-09-15 20:47:03 -05:00
```
GF_AUTH_AZUREAD_CLIENT_ID
GF_AUTH_AZUREAD_CLIENT_SECRET
```
2021-09-20 02:08:00 -05:00
2023-05-18 09:50:20 -05:00
**Note:** Verify that the Grafana [root_url ]({{< relref "../../../configure-grafana#root_url" >}} ) is set in your Azure Application Redirect URLs.
2021-07-14 11:55:25 -05:00
2022-11-14 09:47:46 -06:00
### Configure refresh token
> Available in Grafana v9.3 and later versions.
> **Note:** This feature is behind the `accessTokenExpirationCheck` feature toggle.
When a user logs in using an OAuth provider, Grafana verifies that the access token has not expired. When an access token expires, Grafana uses the provided refresh token (if any exists) to obtain a new access token.
Grafana uses a refresh token to obtain a new access token without requiring the user to log in again. If a refresh token doesn't exist, Grafana logs the user out of the system after the access token has expired.
2023-07-14 07:03:01 -05:00
Refresh token fetching and access token expiration check is enabled by default for the AzureAD provider since Grafana v10.1.0 if the `accessTokenExpirationCheck` feature toggle is enabled. If you would like to disable access token expiration check then set the `use_refresh_token` configuration value to `false` .
> **Note:** The `accessTokenExpirationCheck` feature toggle will be removed in Grafana v10.2.0 and the `use_refresh_token` configuration value will be used instead for configuring refresh token fetching and access token expiration check.
2022-11-14 09:47:46 -06:00
2023-06-16 11:29:09 -05:00
### Configure allowed tenants
To limit access to authenticated users who are members of one or more tenants, set `allowed_organizations`
to a comma- or space-separated list of tenant IDs. You can find tenant IDs on the Azure portal under **Azure Active Directory -> Overview** .
Make sure to include the tenant IDs of all the federated Users' root directory if your Azure AD contains external identities.
For example, if you want to only give access to members of the tenant `example` with an ID of `8bab1c86-8fba-33e5-2089-1d1c80ec267d` , then set the following:
```
allowed_organizations = 8bab1c86-8fba-33e5-2089-1d1c80ec267d
```
2021-07-14 11:55:25 -05:00
### Configure allowed groups
2020-02-14 05:03:00 -06:00
2021-07-14 11:55:25 -05:00
To limit access to authenticated users who are members of one or more groups, set `allowed_groups`
to a comma- or space-separated list of group object IDs. You can find object IDs for a specific group on the Azure portal:
2020-02-14 05:03:00 -06:00
2021-10-04 10:14:33 -05:00
1. Go to **Azure Active Directory -> Groups** . If you want to only give access to members of the group `example` with an ID of `8bab1c86-8fba-33e5-2089-1d1c80ec267d` , then set the following:
2020-02-14 05:03:00 -06:00
2021-10-04 10:14:33 -05:00
```
allowed_groups = 8bab1c86-8fba-33e5-2089-1d1c80ec267d
```
2020-02-14 05:03:00 -06:00
2021-10-04 10:14:33 -05:00
1. Verify that [group attributes ](https://docs.microsoft.com/en-us/azure/active-directory/hybrid/how-to-connect-fed-group-claims#configure-the-azure-ad-application-registration-for-group-attributes ) is enabled in your Azure AD Application Registration manifest file by navigating to **Azure Portal** > **Azure Active Directory** > **Application Registrations** > **Select Application** -> **Manifest** , and set the following:
2020-04-06 12:23:49 -05:00
2021-10-04 10:14:33 -05:00
```
"groupMembershipClaims": "ApplicationGroup, SecurityGroup"
```
2020-04-06 12:23:49 -05:00
2021-07-14 11:55:25 -05:00
### Configure allowed domains
2021-10-04 10:14:33 -05:00
The `allowed_domains` option limits access to users who belong to specific domains. Separate domains with space or comma. For example,
2020-02-14 05:03:00 -06:00
2021-10-04 10:14:33 -05:00
```
2020-02-14 05:03:00 -06:00
allowed_domains = mycompany.com mycompany.org
```
2023-05-30 11:17:45 -05:00
### PKCE
IETF's [RFC 7636 ](https://datatracker.ietf.org/doc/html/rfc7636 )
introduces "proof key for code exchange" (PKCE) which provides
additional protection against some forms of authorization code
interception attacks. PKCE will be required in [OAuth 2.1 ](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-03 ).
> You can disable PKCE in Grafana by setting `use_pkce` to `false` in the`[auth.azuread]` section.
2023-01-19 08:53:02 -06:00
### Configure automatic login
2023-05-30 11:17:45 -05:00
To bypass the login screen and log in automatically, enable the "auto_login" feature.
2023-01-19 08:53:02 -06:00
This setting is ignored if multiple auth providers are configured to use auto login.
```
auto_login = true
```
2020-02-14 05:03:00 -06:00
### Team Sync (Enterprise only)
With Team Sync you can map your Azure AD groups to teams in Grafana so that your users will automatically be added to
2020-03-10 11:15:25 -05:00
the correct teams.
2020-02-14 05:03:00 -06:00
2021-07-14 11:55:25 -05:00
You can reference Azure AD groups by group object ID, like `8bab1c86-8fba-33e5-2089-1d1c80ec267d` .
2020-02-14 05:03:00 -06:00
2023-05-18 09:50:20 -05:00
To learn more, refer to the [Team Sync ]({{< relref "../../configure-team-sync" >}} ) documentation.
2022-09-19 08:45:05 -05:00
## Common troubleshooting
Here are some common issues and particulars you can run into when
configuring Azure AD authentication in Grafana.
### Users with over 200 Group assignments
> Supported in Grafana v8.5 and later versions.
To ensure that the token size doesn't exceed HTTP header size limits,
Azure AD limits the number of object IDs that it includes in the groups claim.
If a user is member of more groups than the
overage limit (200), then
Azure AD does not emit the groups claim in the token and emits a group overage claim instead.
2023-06-07 16:43:04 -05:00
> More information in [Groups overage claim](https://learn.microsoft.com/en-us/azure/active-directory/develop/id-token-claims-reference#groups-overage-claim)
2022-09-19 08:45:05 -05:00
If Grafana receives a token with a group overage claim instead of a groups claim,
Grafana attempts to retrieve the user's group membership by calling the included endpoint.
> Note: The token must include the `GroupMember.Read.All` permission for group overage claim calls to succeed.
> Admin consent may be required for this permission.
2022-10-14 05:55:00 -05:00
### Force fetching groups from Microsoft graph API
To force fetching groups from Microsoft Graph API instead of the `id_token` . You can use the `force_use_graph_api` config option.
```
force_use_graph_api = true
```
2023-01-16 06:16:01 -06:00
### Map roles
By default, Azure AD authentication will map users to organization roles based on the most privileged application role assigned to the user in AzureAD.
If no application role is found, the user is assigned the role specified by
[the `auto_assign_org_role` option ]({{< relref "../../../configure-grafana#auto_assign_org_role" >}} ).
You can disable this default role assignment by setting `role_attribute_strict = true` .
It denies user access if no role or an invalid role is returned.
**On every login** the user organization role will be reset to match AzureAD's application role and
their organization membership will be reset to the default organization.
## Skip organization role sync
2023-02-07 09:28:40 -06:00
If Azure AD authentication is not intended to sync user roles and organization membership and prevent the sync of org roles from AzureAD, set `skip_org_role_sync` to `true` . This is useful if you want to manage the organization roles for your users from within Grafana or that your organization roles are synced from another provider.
2023-05-18 09:50:20 -05:00
See [Configure Grafana ]({{< relref "../../../configure-grafana#authazuread" >}} ) for more details.
2023-01-16 06:16:01 -06:00
```ini
[auth.azuread]
# ..
2023-02-07 09:28:40 -06:00
# prevents the sync of org roles from AzureAD
2023-01-16 06:16:01 -06:00
skip_org_role_sync = true
```