Azure AD SSO Configuration for DefectDojo
Azure AD App Registration Setup
Step 1: Create App Registration
- Go to Azure Portal > Azure Active Directory > App registrations
- Click "New registration"
- Configure:
- Name:
DefectDojo - Supported account types: "Accounts in this organizational directory only"
- Redirect URI: Web -
https://defectdojo.dev.cafehyna.com.br/complete/azuread-tenant-oauth2/
- Name:
Step 2: Configure API Permissions
Add these Application permissions (not Delegated):
| Permission | Type | Purpose |
|---|---|---|
Group.Read.All |
Application | Read all groups |
GroupMember.Read.All |
Application | Read group memberships |
User.Read.All |
Application | Read user profiles |
Grant admin consent after adding permissions.
Step 3: Configure Token Claims
- Go to App Registration > Token configuration
- Add Groups claim:
- Click "Add groups claim"
- Select "All groups"
- Important: Do NOT check "Emit groups as role claims"
Step 4: Create Client Secret
- Go to Certificates & secrets
- Create new client secret
- Store in Azure Key Vault as
defectdojo-azuread-client-secret
DefectDojo Environment Variables
Required Variables
extraEnv:
# Enable Azure AD OAuth2 authentication
- name: DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_ENABLED
value: "True"
# Azure AD Application (client) ID
- name: DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY
value: "79ada8c7-4270-41e8-9ea0-1e1e62afff3d"
# Azure AD Directory (tenant) ID
- name: DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID
value: "3f7a3df4-f85b-4ca8-98d0-08b1034e6567"
# Azure AD Client Secret (from Key Vault)
- name: DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET
valueFrom:
secretKeyRef:
name: defectdojo
key: DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET
Group Synchronization Variables
extraEnv:
# Enable group sync from Azure AD
- name: DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GET_GROUPS
value: "True"
# Clean up empty groups
- name: DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_CLEANUP_GROUPS
value: "True"
# Filter groups by regex pattern
- name: DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GROUPS_FILTER
value: "^G-Usuarios-DefectDojo-.*"
SSL/Security Variables
Required when behind a TLS-terminating proxy:
extraEnv:
# Secure cookies
- name: DD_SESSION_COOKIE_SECURE
value: "True"
- name: DD_CSRF_COOKIE_SECURE
value: "True"
# Trust proxy headers
- name: DD_SECURE_PROXY_SSL_HEADER
value: "True"
# IMPORTANT: Set to False behind NGINX Ingress to avoid redirect loops
- name: DD_SECURE_SSL_REDIRECT
value: "False"
Optional SSO Behavior Variables
extraEnv:
# Auto-redirect to Azure AD login (skip username/password form)
- name: DD_SOCIAL_LOGIN_AUTO_REDIRECT
value: "True"
# Hide traditional login form
- name: DD_SOCIAL_AUTH_SHOW_LOGIN_FORM
value: "False"
Azure AD Groups for DefectDojo Roles
Recommended Group Structure
| Azure AD Group Name | DefectDojo Role | Description |
|---|---|---|
G-Usuarios-DefectDojo-Superuser |
Superuser | Full admin access (is_superuser=true) |
G-Usuarios-DefectDojo-Owner |
Owner | Can delete products, manage members |
G-Usuarios-DefectDojo-Maintainer |
Maintainer | Edit settings, delete findings |
G-Usuarios-DefectDojo-Writer |
Writer | Add/edit engagements, tests, findings |
G-Usuarios-DefectDojo-Reader |
Reader | View-only, add comments |
G-Usuarios-DefectDojo-APIImporter |
API Importer | CI/CD pipeline scan imports |
Setting Up Group-Role Mapping
Create Azure AD Groups:
- Go to Azure Portal > Azure Active Directory > Groups
- Create groups matching the naming pattern above
- Add users to appropriate groups
Enable Group Sync in DefectDojo:
- name: DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GET_GROUPS value: "True" - name: DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GROUPS_FILTER value: "^G-Usuarios-DefectDojo-.*"Create Matching Groups in DefectDojo:
- Go to DefectDojo > Configuration > Groups
- Create groups with exact same names as Azure AD groups
- Assign appropriate Global Role to each group
User Login:
- Users log in via Azure AD SSO
- Groups are synced during login
- Users inherit roles from their group memberships
Troubleshooting SSO Issues
Error: ADSTS50011 - Redirect URI Mismatch
Cause: Azure AD requires HTTPS, but DefectDojo sending HTTP redirect
Solution:
Verify redirect URI in Azure AD is exactly:
https://defectdojo.dev.cafehyna.com.br/complete/azuread-tenant-oauth2/Set SSL environment variables:
- name: DD_SESSION_COOKIE_SECURE value: "True" - name: DD_CSRF_COOKIE_SECURE value: "True" - name: DD_SECURE_PROXY_SSL_HEADER value: "True"
Error: Groups Not Syncing
Symptoms: User logged in but shows "No group members found"
Checklist:
-
DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GET_GROUPS=True - Azure AD App has
Group.Read.Allpermission (Application type) - Admin consent granted for API permissions
- Token configuration has Groups claim (not role claims)
- "Emit groups as role claims" is NOT enabled
- User logged out and back in after configuration change
- Matching groups exist in DefectDojo UI
Error: 403 Forbidden from Graph API
Cause: Missing or incorrect API permissions
Solution:
- Go to Azure AD > App Registration > API Permissions
- Add
Group.Read.Allas Application permission - Click "Grant admin consent"
- Restart DefectDojo pods
Emergency Access
If SSO is broken and you're locked out:
https://defectdojo.dev.cafehyna.com.br/login?force_login_form
This bypasses SSO redirect and shows the standard login form.