Azure AD OAuth2 authentication

Only available in Grafana v6.7+

The Azure AD authentication provides the possibility to use an Azure Active Directory tenant as an identity provider for Grafana. By using Azure AD Application Roles it is also possible to assign Users and Groups to Grafana roles from the Azure Portal.

Create the Azure AD application

To enable the Azure AD OAuth2 you must register your application with Azure AD.

  1. Log in to Azure Portal and 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.

  2. Under Manage in the side menu, click App Registrations and then New Registration. Provide a fitting name.

  3. Under Redirect URI, select Web as the app type.

  4. Add the redirect URL https://<grafana domain>/login/azuread, then click Register.

  5. The app’s Overview page is displayed. Note the Application ID, this is the OAuth client id.

  6. Click Endpoints from the top menu.

    • Note the OAuth 2.0 authorization endpoint (v2), this is the auth URL.
    • Note the OAuth 2.0 token endpoint (v2), this is the token URL.
  7. Click Certificates & secrets and add a new entry under Client secrets.

    • Description: Grafana OAuth
    • Expires: Never
  8. Click Add, then copy the key value. This is the OAuth client secret.

  9. Click Manifest.

    • Add definitions for the required Application Roles for Grafana (Viewer, Editor, Admin). Without this configuration, all users will be assigned the Viewer role.

    • Every role requires a unique id. On Linux, this can be created with uuidgen. For example:

      1. "appRoles": [
      2. {
      3. "allowedMemberTypes": [
      4. "User"
      5. ],
      6. "description": "Grafana admin Users",
      7. "displayName": "Grafana Admin",
      8. "id": "SOME_UNIQUE_ID",
      9. "isEnabled": true,
      10. "lang": null,
      11. "origin": "Application",
      12. "value": "Admin"
      13. },
      14. {
      15. "allowedMemberTypes": [
      16. "User"
      17. ],
      18. "description": "Grafana read only Users",
      19. "displayName": "Grafana Viewer",
      20. "id": "SOME_UNIQUE_ID",
      21. "isEnabled": true,
      22. "lang": null,
      23. "origin": "Application",
      24. "value": "Viewer"
      25. },
      26. {
      27. "allowedMemberTypes": [
      28. "User"
      29. ],
      30. "description": "Grafana Editor Users",
      31. "displayName": "Grafana Editor",
      32. "id": "SOME_UNIQUE_ID",
      33. "isEnabled": true,
      34. "lang": null,
      35. "origin": "Application",
      36. "value": "Editor"
      37. }
      38. ],
  10. Go to Azure Active Directory and then to Enterprise Applications. Search for your application and click on it.

  11. Click on Users and Groups and add Users/Groups to the Grafana roles by using Add User.

Enable Azure AD OAuth in Grafana

  1. Add the following to the Grafana configuration file:
  1. [auth.azuread]
  2. name = Azure AD
  3. enabled = true
  4. allow_sign_up = true
  5. client_id = APPLICATION_ID
  6. client_secret = CLIENT_SECRET
  7. scopes = openid email profile
  8. auth_url = https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/authorize
  9. token_url = https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token
  10. allowed_domains =
  11. allowed_groups =

Note: Ensure that the root_url in Grafana is set in your Azure Application Reply URLs (App -> Settings -> Reply URLs)

Configure allowed groups and domains

To limit access to authenticated users that are members of one or more groups, set allowed_groups to a comma- or space-separated list of group Object Ids. Object Id for a specific group can be found on the Azure portal: go to Azure Active Directory -> Groups. For instance, if you want to only give access to members of the group example which has Id 8bab1c86-8fba-33e5-2089-1d1c80ec267d, set

  1. allowed_groups = 8bab1c86-8fba-33e5-2089-1d1c80ec267d

You’ll need to ensure that you’ve enabled group attributes in your Azure AD Application Registration manifest file (Azure Portal -> Azure Active Directory -> Application Registrations -> Select Application -> Manifest)

  1. "groupMembershipClaims": "ApplicationGroup, SecurityGroup"

The allowed_domains option limits access to the users belonging to the specific domains. Domains should be separated by space or comma.

  1. allowed_domains = mycompany.com mycompany.org

Team Sync (Enterprise only)

Only available in Grafana Enterprise v6.7+

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.

Azure AD groups can be referenced by group Object Id, like 8bab1c86-8fba-33e5-2089-1d1c80ec267d.

Learn more about Team Sync