|
| 1 | +--- |
| 2 | +title: "Azure Active Directory" |
| 3 | +description: "Configure Azure AD SSO and group mapping in Open-Source DefectDojo" |
| 4 | +weight: 6 |
| 5 | +audience: opensource |
| 6 | +--- |
| 7 | + |
| 8 | +Open-Source DefectDojo supports login via Azure Active Directory (Azure AD), including automatic User Group synchronization. DefectDojo Pro users should refer to the [Pro Azure AD guide](../PRO__azure_ad/). |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +Complete the following steps in the Azure portal before configuring DefectDojo: |
| 13 | + |
| 14 | +1. [Register a new app](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app) in Azure Active Directory. |
| 15 | + |
| 16 | +2. Note the following values from the registered app: |
| 17 | + - **Application (client) ID** |
| 18 | + - **Directory (tenant) ID** |
| 19 | + - Under **Certificates & Secrets**, create a new **Client Secret** and note its value |
| 20 | + |
| 21 | +3. Under **Authentication > Redirect URIs**, add a **Web** type URI: |
| 22 | + `https://your-instance.cloud.defectdojo.com/complete/azuread-tenant-oauth2/` |
| 23 | + |
| 24 | +## Configuration |
| 25 | + |
| 26 | +Set the following as environment variables, or without the `DD_` prefix in your `local_settings.py` file (see [Configuration](/get_started/open_source/configuration/)): |
| 27 | + |
| 28 | +{{< highlight python >}} |
| 29 | +DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY=(str, 'YOUR_APPLICATION_ID'), |
| 30 | +DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET=(str, 'YOUR_CLIENT_SECRET'), |
| 31 | +DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID=(str, 'YOUR_DIRECTORY_ID'), |
| 32 | +DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_ENABLED=True |
| 33 | +{{< /highlight >}} |
| 34 | + |
| 35 | +Restart DefectDojo. A **Login with Azure AD** button will appear on the login page. |
| 36 | + |
| 37 | +## Group Mapping |
| 38 | + |
| 39 | +To import User Group membership from Azure AD, set the following variable: |
| 40 | + |
| 41 | +{{< highlight python >}} |
| 42 | +DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GET_GROUPS=True |
| 43 | +{{< /highlight >}} |
| 44 | + |
| 45 | +On login, DefectDojo will assign the user to all groups found in the Azure AD token. Any groups not found in DefectDojo will be created automatically. This allows product access to be governed via groups. |
| 46 | + |
| 47 | +### Configuring Azure AD to send groups |
| 48 | + |
| 49 | +The Azure AD token must be configured to include group IDs. Without this, no group information will be present in the token. |
| 50 | + |
| 51 | +To configure this: |
| 52 | +1. Add a [Group Claim](https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-fed-group-claims) to the token. If unsure which group type to select, choose **All Groups**. |
| 53 | +2. Do **not** enable **Emit groups as role claims**. |
| 54 | +3. Update the application's API permissions to include `GroupMember.Read.All` or `Group.Read.All`. `GroupMember.Read.All` is recommended as it grants fewer permissions. |
| 55 | + |
| 56 | +### Filtering groups |
| 57 | + |
| 58 | +To limit which groups are imported, use a regex filter: |
| 59 | + |
| 60 | +{{< highlight python >}} |
| 61 | +DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GROUPS_FILTER='^team-.*' # or 'teamA|teamB|groupC' |
| 62 | +{{< /highlight >}} |
| 63 | + |
| 64 | +### Automatic Group Cleanup |
| 65 | + |
| 66 | +To remove stale groups when users are removed from them in Azure AD: |
| 67 | + |
| 68 | +{{< highlight python >}} |
| 69 | +DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_CLEANUP_GROUPS=True |
| 70 | +{{< /highlight >}} |
| 71 | + |
| 72 | +When a user is removed from a group in Azure AD, they are also removed from the corresponding group in DefectDojo. Empty groups are left in place for record purposes. |
0 commit comments