Skip to content

Commit 7afa3c7

Browse files
Add generic OIDC login option (#10614)
* fixing conflicts and removing code formatting * sha file deleted * remove settings sha * Make some settings optional * Fix ruff * Restore some vuln ids --------- Co-authored-by: Cody Maffucci <46459665+Maffooch@users.noreply.github.com>
1 parent da0321f commit 7afa3c7

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

docs/content/en/open_source/archived_docs/integrations/social-authentication.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,35 @@ Here are suggestion on how to configure Keycloak and DefectDojo:
307307
7. In your realm settings -> general -> endpoints: look into openId endpoint configuration
308308
and look up your authorization and token endpoint (use them below)
309309

310+
### Configure OIDC
311+
Provides the option to authenticate users using a generic OIDC provider.
312+
313+
The minimum configuration requires:
314+
315+
{{< highlight python >}}
316+
DD_SOCIAL_AUTH_OIDC_AUTH_ENABLED=True,
317+
DD_SOCIAL_AUTH_OIDC_OIDC_ENDPOINT=(str, 'https://example.com'),
318+
DD_SOCIAL_AUTH_OIDC_KEY=(str, 'YOUR_CLIENT_ID'),
319+
DD_SOCIAL_AUTH_OIDC_SECRET=(str, 'YOUR_CLIENT_SECRET')
320+
{{< /highlight >}}
321+
322+
The rest of the OIDC configuration will be auto-detected by fetching data from:
323+
- <DD_SOCIAL_AUTH_OIDC_OIDC_ENDPOINT>/.well-known/open-id-configuration/
324+
325+
You can also optionally set the following:
326+
327+
{{< highlight python >}}
328+
DD_SOCIAL_AUTH_OIDC_ID_KEY=(str, ''), #the key associated with the OIDC user IDs
329+
DD_SOCIAL_AUTH_OIDC_USERNAME_KEY=(str, ''), #the key associated with the OIDC usernames
330+
DD_SOCIAL_AUTH_OIDC_WHITELISTED_DOMAINS=(list, ['']), #list of domains allowed for login
331+
DD_SOCIAL_AUTH_OIDC_JWT_ALGORITHMS=(list, ["RS256","HS256"]),
332+
DD_SOCIAL_AUTH_OIDC_ID_TOKEN_ISSUER=(str, ''),
333+
DD_SOCIAL_AUTH_OIDC_ACCESS_TOKEN_URL=(str, ''),
334+
DD_SOCIAL_AUTH_OIDC_AUTHORIZATION_URL=(str, ''),
335+
DD_SOCIAL_AUTH_OIDC_USERINFO_URL=(str, ''),
336+
DD_SOCIAL_AUTH_OIDC_JWKS_URI=(str, ''),
337+
{{< /highlight >}}
338+
310339
### Configure Defect Dojo
311340
Edit the settings (see [Configuration](../../open_source/installation/configuration)) with the following
312341
information:

dojo/context_processors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def globalize_vars(request):
1111
"FORGOT_PASSWORD": settings.FORGOT_PASSWORD,
1212
"FORGOT_USERNAME": settings.FORGOT_USERNAME,
1313
"CLASSIC_AUTH_ENABLED": settings.CLASSIC_AUTH_ENABLED,
14+
"OIDC_ENABLED": settings.OIDC_AUTH_ENABLED,
1415
"AUTH0_ENABLED": settings.AUTH0_OAUTH2_ENABLED,
1516
"GOOGLE_ENABLED": settings.GOOGLE_OAUTH_ENABLED,
1617
"OKTA_ENABLED": settings.OKTA_OAUTH_ENABLED,

dojo/settings/settings.dist.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@
104104
DD_SOCIAL_AUTH_CREATE_USER=(bool, True), # if True creates user at first login
105105
DD_SOCIAL_LOGIN_AUTO_REDIRECT=(bool, False), # auto-redirect if there is only one social login method
106106
DD_SOCIAL_AUTH_TRAILING_SLASH=(bool, True),
107+
DD_SOCIAL_AUTH_OIDC_AUTH_ENABLED=(bool, False),
108+
DD_SOCIAL_AUTH_OIDC_OIDC_ENDPOINT=(str, ""),
109+
DD_SOCIAL_AUTH_OIDC_ID_KEY=(str, ""),
110+
DD_SOCIAL_AUTH_OIDC_KEY=(str, ""),
111+
DD_SOCIAL_AUTH_OIDC_SECRET=(str, ""),
112+
DD_SOCIAL_AUTH_OIDC_USERNAME_KEY=(str, ""),
113+
DD_SOCIAL_AUTH_OIDC_WHITELISTED_DOMAINS=(list, []),
114+
DD_SOCIAL_AUTH_OIDC_JWT_ALGORITHMS=(list, ["RS256", "HS256"]),
115+
DD_SOCIAL_AUTH_OIDC_ID_TOKEN_ISSUER=(str, ""),
116+
DD_SOCIAL_AUTH_OIDC_ACCESS_TOKEN_URL=(str, ""),
117+
DD_SOCIAL_AUTH_OIDC_AUTHORIZATION_URL=(str, ""),
118+
DD_SOCIAL_AUTH_OIDC_USERINFO_URL=(str, ""),
119+
DD_SOCIAL_AUTH_OIDC_JWKS_URI=(str, ""),
107120
DD_SOCIAL_AUTH_AUTH0_OAUTH2_ENABLED=(bool, False),
108121
DD_SOCIAL_AUTH_AUTH0_KEY=(str, ""),
109122
DD_SOCIAL_AUTH_AUTH0_SECRET=(str, ""),
@@ -484,6 +497,7 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
484497

485498
# These are the individidual modules supported by social-auth
486499
AUTHENTICATION_BACKENDS = (
500+
"social_core.backends.open_id_connect.OpenIdConnectAuth",
487501
"social_core.backends.auth0.Auth0OAuth2",
488502
"social_core.backends.google.GoogleOAuth2",
489503
"social_core.backends.okta.OktaOAuth2",
@@ -576,6 +590,31 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
576590
if GITLAB_PROJECT_AUTO_IMPORT:
577591
SOCIAL_AUTH_GITLAB_SCOPE += ["read_repository"]
578592

593+
# Mandatory settings
594+
OIDC_AUTH_ENABLED = env("DD_SOCIAL_AUTH_OIDC_AUTH_ENABLED")
595+
SOCIAL_AUTH_OIDC_OIDC_ENDPOINT = env("DD_SOCIAL_AUTH_OIDC_OIDC_ENDPOINT")
596+
SOCIAL_AUTH_OIDC_KEY = env("DD_SOCIAL_AUTH_OIDC_KEY")
597+
SOCIAL_AUTH_OIDC_SECRET = env("DD_SOCIAL_AUTH_OIDC_SECRET")
598+
# Optional settings
599+
if value := env("DD_SOCIAL_AUTH_OIDC_ID_KEY"):
600+
SOCIAL_AUTH_OIDC_ID_KEY = value
601+
if value := env("DD_SOCIAL_AUTH_OIDC_USERNAME_KEY"):
602+
SOCIAL_AUTH_OIDC_USERNAME_KEY = value
603+
if value := env("DD_SOCIAL_AUTH_OIDC_WHITELISTED_DOMAINS"):
604+
SOCIAL_AUTH_OIDC_WHITELISTED_DOMAINS = env("DD_SOCIAL_AUTH_OIDC_WHITELISTED_DOMAINS")
605+
if value := env("DD_SOCIAL_AUTH_OIDC_JWT_ALGORITHMS"):
606+
SOCIAL_AUTH_OIDC_JWT_ALGORITHMS = env("DD_SOCIAL_AUTH_OIDC_JWT_ALGORITHMS")
607+
if value := env("DD_SOCIAL_AUTH_OIDC_ID_TOKEN_ISSUER"):
608+
SOCIAL_AUTH_OIDC_ID_TOKEN_ISSUER = value
609+
if value := env("DD_SOCIAL_AUTH_OIDC_ACCESS_TOKEN_URL"):
610+
SOCIAL_AUTH_OIDC_ACCESS_TOKEN_URL = value
611+
if value := env("DD_SOCIAL_AUTH_OIDC_AUTHORIZATION_URL"):
612+
SOCIAL_AUTH_OIDC_AUTHORIZATION_URL = value
613+
if value := env("DD_SOCIAL_AUTH_OIDC_USERINFO_URL"):
614+
SOCIAL_AUTH_OIDC_USERINFO_URL = value
615+
if value := env("DD_SOCIAL_AUTH_OIDC_JWKS_URI"):
616+
SOCIAL_AUTH_OIDC_JWKS_URI = value
617+
579618
AUTH0_OAUTH2_ENABLED = env("DD_SOCIAL_AUTH_AUTH0_OAUTH2_ENABLED")
580619
SOCIAL_AUTH_AUTH0_KEY = env("DD_SOCIAL_AUTH_AUTH0_KEY")
581620
SOCIAL_AUTH_AUTH0_SECRET = env("DD_SOCIAL_AUTH_AUTH0_SECRET")
@@ -628,6 +667,7 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
628667
rf"^{URL_PREFIX}api/v2/",
629668
r"complete/",
630669
r"empty_questionnaire/([\d]+)/answer",
670+
r"oauth2/idpresponse",
631671
rf"^{URL_PREFIX}password_reset/",
632672
rf"^{URL_PREFIX}forgot_username",
633673
rf"^{URL_PREFIX}reset/",

dojo/templates/dojo/login.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ <h3>{% trans "Login" %}</h3>
4747
{% endif %}
4848
</div>
4949
<div class="form-group">
50+
{% if OIDC_ENABLED is True %}
51+
<div class="col-sm-offset-1 col-sm-2">
52+
<a href="{% url 'social:begin' 'oidc' %}?next={{ request.GET.next }}" style="color: rgb(255, 255, 255)" class="btn btn-success" type="button">{% trans "Login with OIDC" %}</a>
53+
</div>
54+
{% endif %}
55+
5056
{% if GOOGLE_ENABLED is True %}
5157
<div class="col-sm-offset-1 col-sm-2">
5258
<a href="{% url 'social:begin' 'google-oauth2' %}?next={{ request.GET.next }}" style="color: rgb(255,255,255)" class="btn btn-success" type="button">{% trans "Login with Google" %}</a>

dojo/user/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def login_view(request):
126126
settings.AUTH0_OAUTH2_ENABLED,
127127
settings.KEYCLOAK_OAUTH2_ENABLED,
128128
settings.GITHUB_ENTERPRISE_OAUTH2_ENABLED,
129+
settings.OIDC_AUTH_ENABLED,
129130
settings.SAML2_ENABLED,
130131
]) == 1 and "force_login_form" not in request.GET:
131132
if settings.GOOGLE_OAUTH_ENABLED:
@@ -138,6 +139,8 @@ def login_view(request):
138139
social_auth = "gitlab"
139140
elif settings.KEYCLOAK_OAUTH2_ENABLED:
140141
social_auth = "keycloak"
142+
elif settings.OIDC_AUTH_ENABLED:
143+
social_auth = "oidc"
141144
elif settings.AUTH0_OAUTH2_ENABLED:
142145
social_auth = "auth0"
143146
elif settings.GITHUB_ENTERPRISE_OAUTH2_ENABLED:

0 commit comments

Comments
 (0)