* extract errors to errors file * implement oauth server admin assignment * add server admin tests * deduplicate autoAssignOrgRole * deduplicate strict setting * deduplicate strict setting * add support for generic oauth * add role attribute strict support for generic oauth * add support for github/gitlab * assignGrafanaAdmin option is here to stay * unify similar errors * add config option * add okta server admin mapping * remove never used Company attribute * unify generic oauth role extract with other methods * case insensitive role match as in azure * add ini settings * add server admin to devenv * remove duplicate fields * add documentation to oauth * fix titlecase test * implement doc feedback
7.0 KiB
aliases | description | keywords | title | weight | ||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Grafana Azure AD OAuth Guide |
|
Configure Azure AD OAuth2 authentication | 600 |
Configure Azure AD OAuth2 authentication
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:
Create the Azure AD application
To enable the Azure AD OAuth2, register your application with Azure AD.
-
Log in to Azure Portal, then click Azure Active Directory in the side menu.
-
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.
-
Under Manage in the side menu, click App Registrations > New Registration. Enter a descriptive name.
-
Under Redirect URI, select the app type Web.
-
Add the following redirect URLs
https://<grafana domain>/login/azuread
andhttps://<grafana domain>
then click Register. The app's Overview page opens. -
Note the Application ID. This is the OAuth client ID.
-
Click Endpoints from the top menu.
- Note the OAuth 2.0 authorization endpoint (v2) URL. This is the authorization URL.
- Note the OAuth 2.0 token endpoint (v2). This is the token URL.
-
Click Certificates & secrets, then add a new entry under Client secrets with the following configuration.
- Description: Grafana OAuth
- Expires: Never
-
Click Add then copy the key value. This is the OAuth client secret.
-
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 withNew-Guid
. -
Include the unique ID in the configuration file:
"appRoles": [ { "allowedMemberTypes": [ "User" ], "description": "Grafana org admin Users", "displayName": "Grafana Org Admin", "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" } ],
-
Go to Azure Active Directory and then to Enterprise Applications. Search for your application and click on it.
-
Click on Users and Groups and add Users/Groups to the Grafana roles by using Add User.
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.
{
"allowedMemberTypes": ["User"],
"description": "Grafana server admin Users",
"displayName": "Grafana Server Admin",
"id": "SOME_UNIQUE_ID",
"isEnabled": true,
"lang": null,
"origin": "Application",
"value": "GrafanaAdmin"
}
Enable Azure AD OAuth in Grafana
- Add the following to the [Grafana configuration file]({{< relref "../../configure-grafana/#config-file-locations" >}}):
[auth.azuread]
name = Azure AD
enabled = true
allow_sign_up = true
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
allowed_domains =
allowed_groups =
role_attribute_strict = false
allow_assign_grafana_admin = false
You can also use these environment variables to configure client_id and client_secret:
GF_AUTH_AZUREAD_CLIENT_ID
GF_AUTH_AZUREAD_CLIENT_SECRET
Note: Verify that the Grafana [root_url]({{< relref "../../configure-grafana/#root-url" >}}) is set in your Azure Application Redirect URLs.
Configure allowed groups
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:
-
Go to Azure Active Directory -> Groups. If you want to only give access to members of the group
example
with an ID of8bab1c86-8fba-33e5-2089-1d1c80ec267d
, then set the following:allowed_groups = 8bab1c86-8fba-33e5-2089-1d1c80ec267d
-
Verify that 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:
"groupMembershipClaims": "ApplicationGroup, SecurityGroup"
Configure allowed domains
The allowed_domains
option limits access to users who belong to specific domains. Separate domains with space or comma. For example,
allowed_domains = mycompany.com mycompany.org
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 the correct teams.
You can reference Azure AD groups by group object ID, like 8bab1c86-8fba-33e5-2089-1d1c80ec267d
.
To learn more, refer to the [Team Sync]({{< relref "../configure-team-sync/" >}}) documentation.