KeyCloak
On this page
Open-Source DefectDojo supports login via KeyCloak. DefectDojo Pro users should refer to the Pro KeyCloak guide.
This guide assumes you already have a KeyCloak Realm configured. If not, see the KeyCloak documentation.
Prerequisites
Complete the following steps in your KeyCloak realm before configuring DefectDojo:
Add a new client with type
openid-connect. Note the client ID.In the client settings:
- Set Access Type to
confidential - Under Valid Redirect URIs, add your DefectDojo URL, e.g.
https://your-dojo-host/* - Under Web Origins, add the same URL (or
+) - Under Fine Grained OpenID Connect Configuration:
- Set User Info Signed Response Algorithm to
RS256 - Set Request Object Signature Algorithm to
RS256
- Set User Info Signed Response Algorithm to
- Save the settings.
- Set Access Type to
Under Scope, set Full Scope Allowed to
off.Under Mappers, add a custom mapper:
- Name:
aud - Mapper Type:
audience - Included Audience: select your client ID
- Add ID to Token:
off - Add Access to Token:
on
- Name:
Under Credentials, copy the Secret.
In Realm Settings > Keys, copy the Public Key (signing key).
In Realm Settings > General > Endpoints, open the OpenID endpoint configuration and copy the Authorization and Token endpoint URLs.
Configuration
Set the following as environment variables, or without the DD_ prefix in your local_settings.py file (see Configuration):
DD_SESSION_COOKIE_SECURE=True,
DD_CSRF_COOKIE_SECURE=True,
DD_SECURE_SSL_REDIRECT=True,
DD_SOCIAL_AUTH_KEYCLOAK_OAUTH2_ENABLED=True,
DD_SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY=(str, 'YOUR_REALM_PUBLIC_KEY'),
DD_SOCIAL_AUTH_KEYCLOAK_KEY=(str, 'YOUR_CLIENT_ID'),
DD_SOCIAL_AUTH_KEYCLOAK_SECRET=(str, 'YOUR_CLIENT_SECRET'),
DD_SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL=(str, 'YOUR_AUTHORIZATION_ENDPOINT'),
DD_SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL=(str, 'YOUR_TOKEN_ENDPOINT')For Helm deployments, add the following to the extraConfig section:
DD_SESSION_COOKIE_SECURE: 'True'
DD_CSRF_COOKIE_SECURE: 'True'
DD_SECURE_SSL_REDIRECT: 'True'
DD_SOCIAL_AUTH_KEYCLOAK_OAUTH2_ENABLED: 'True'
DD_SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY: '<your realm public key>'
DD_SOCIAL_AUTH_KEYCLOAK_KEY: '<your client id>'
DD_SOCIAL_AUTH_KEYCLOAK_SECRET: '<your keycloak client credentials secret>'
DD_SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL: '<your authorization endpoint>'
DD_SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL: '<your token endpoint>'Optionally, set DD_SOCIAL_AUTH_KEYCLOAK_LOGIN_BUTTON_TEXT to customize the login button text.
Restart DefectDojo. A login button will appear on the login page with your configured text.