|
| 1 | +--- |
| 2 | +title: "KeyCloak" |
| 3 | +description: "Configure KeyCloak SSO in Open-Source DefectDojo" |
| 4 | +weight: 14 |
| 5 | +audience: opensource |
| 6 | +--- |
| 7 | + |
| 8 | +Open-Source DefectDojo supports login via KeyCloak. DefectDojo Pro users should refer to the [Pro KeyCloak guide](../PRO__keycloak/). |
| 9 | + |
| 10 | +This guide assumes you already have a KeyCloak Realm configured. If not, see the [KeyCloak documentation](https://wjw465150.gitbooks.io/keycloak-documentation/content/server_admin/topics/realms/create.html). |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +Complete the following steps in your KeyCloak realm before configuring DefectDojo: |
| 15 | + |
| 16 | +1. Add a new client with type `openid-connect`. Note the client ID. |
| 17 | + |
| 18 | +2. In the client settings: |
| 19 | + - Set **Access Type** to `confidential` |
| 20 | + - Under **Valid Redirect URIs**, add your DefectDojo URL, e.g. `https://your-dojo-host/*` |
| 21 | + - Under **Web Origins**, add the same URL (or `+`) |
| 22 | + - Under **Fine Grained OpenID Connect Configuration**: |
| 23 | + - Set **User Info Signed Response Algorithm** to `RS256` |
| 24 | + - Set **Request Object Signature Algorithm** to `RS256` |
| 25 | + - Save the settings. |
| 26 | + |
| 27 | +3. Under **Scope**, set **Full Scope Allowed** to `off`. |
| 28 | + |
| 29 | +4. Under **Mappers**, add a custom mapper: |
| 30 | + - **Name:** `aud` |
| 31 | + - **Mapper Type:** `audience` |
| 32 | + - **Included Audience:** select your client ID |
| 33 | + - **Add ID to Token:** `off` |
| 34 | + - **Add Access to Token:** `on` |
| 35 | + |
| 36 | +5. Under **Credentials**, copy the **Secret**. |
| 37 | + |
| 38 | +6. In **Realm Settings > Keys**, copy the **Public Key** (signing key). |
| 39 | + |
| 40 | +7. In **Realm Settings > General > Endpoints**, open the OpenID endpoint configuration and copy the **Authorization** and **Token** endpoint URLs. |
| 41 | + |
| 42 | +## Configuration |
| 43 | + |
| 44 | +Set the following as environment variables, or without the `DD_` prefix in your `local_settings.py` file (see [Configuration](/get_started/open_source/configuration/)): |
| 45 | + |
| 46 | +{{< highlight python >}} |
| 47 | +DD_SESSION_COOKIE_SECURE=True, |
| 48 | +DD_CSRF_COOKIE_SECURE=True, |
| 49 | +DD_SECURE_SSL_REDIRECT=True, |
| 50 | +DD_SOCIAL_AUTH_KEYCLOAK_OAUTH2_ENABLED=True, |
| 51 | +DD_SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY=(str, 'YOUR_REALM_PUBLIC_KEY'), |
| 52 | +DD_SOCIAL_AUTH_KEYCLOAK_KEY=(str, 'YOUR_CLIENT_ID'), |
| 53 | +DD_SOCIAL_AUTH_KEYCLOAK_SECRET=(str, 'YOUR_CLIENT_SECRET'), |
| 54 | +DD_SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL=(str, 'YOUR_AUTHORIZATION_ENDPOINT'), |
| 55 | +DD_SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL=(str, 'YOUR_TOKEN_ENDPOINT') |
| 56 | +{{< /highlight >}} |
| 57 | + |
| 58 | +For Helm deployments, add the following to the `extraConfig` section: |
| 59 | + |
| 60 | +```yaml |
| 61 | +DD_SESSION_COOKIE_SECURE: 'True' |
| 62 | +DD_CSRF_COOKIE_SECURE: 'True' |
| 63 | +DD_SECURE_SSL_REDIRECT: 'True' |
| 64 | +DD_SOCIAL_AUTH_KEYCLOAK_OAUTH2_ENABLED: 'True' |
| 65 | +DD_SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY: '<your realm public key>' |
| 66 | +DD_SOCIAL_AUTH_KEYCLOAK_KEY: '<your client id>' |
| 67 | +DD_SOCIAL_AUTH_KEYCLOAK_SECRET: '<your keycloak client credentials secret>' |
| 68 | +DD_SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL: '<your authorization endpoint>' |
| 69 | +DD_SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL: '<your token endpoint>' |
| 70 | +``` |
| 71 | +
|
| 72 | +Optionally, set `DD_SOCIAL_AUTH_KEYCLOAK_LOGIN_BUTTON_TEXT` to customize the login button text. |
| 73 | + |
| 74 | +Restart DefectDojo. A login button will appear on the login page with your configured text. |
0 commit comments