Skip to content

Commit b232432

Browse files
authored
chore: add warning log if misconfigured groups oidc (#7874)
* chore: add warning log if misconfigured groups oidc This is not perfect, but if we find a 'groups' claim and it is not configured, put out a warning log to give some information
1 parent 4794674 commit b232432

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

cli/testdata/coder_server_--help.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ can safely ignore these settings.
296296
OIDC claim field to use as the email.
297297

298298
--oidc-group-field string, $CODER_OIDC_GROUP_FIELD
299-
Change the OIDC default 'groups' claim field. By default, will be
300-
'groups' if present in the oidc scopes argument.
299+
This field must be set if using the group sync feature and the scope
300+
name is not 'groups'. Set to the claim to be used for groups.
301301

302302
--oidc-group-mapping struct[map[string]string], $CODER_OIDC_GROUP_MAPPING (default: {})
303303
A map of OIDC group IDs and the group in Coder it should map to. This

cli/testdata/server-config.yaml.golden

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ oidc:
238238
# Ignore the userinfo endpoint and only use the ID token for user information.
239239
# (default: false, type: bool)
240240
ignoreUserInfo: false
241-
# Change the OIDC default 'groups' claim field. By default, will be 'groups' if
242-
# present in the oidc scopes argument.
241+
# This field must be set if using the group sync feature and the scope name is not
242+
# 'groups'. Set to the claim to be used for groups.
243243
# (default: <unset>, type: string)
244244
groupField: ""
245245
# A map of OIDC group IDs and the group in Coder it should map to. This is useful

coderd/userauth.go

+6
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,12 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
675675
}
676676
}
677677

678+
// This conditional is purely to warn the user they might have misconfigured their OIDC
679+
// configuration.
680+
if _, groupClaimExists := claims["groups"]; !usingGroups && groupClaimExists {
681+
api.Logger.Debug(ctx, "'groups' claim was returned, but 'oidc-group-field' is not set, check your coder oidc settings.")
682+
}
683+
678684
// The username is a required property in Coder. We make a best-effort
679685
// attempt at using what the claims provide, but if that fails we will
680686
// generate a random username.

codersdk/deployment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ when required by your organization's security policy.`,
953953
},
954954
{
955955
Name: "OIDC Group Field",
956-
Description: "Change the OIDC default 'groups' claim field. By default, will be 'groups' if present in the oidc scopes argument.",
956+
Description: "This field must be set if using the group sync feature and the scope name is not 'groups'. Set to the claim to be used for groups.",
957957
Flag: "oidc-group-field",
958958
Env: "CODER_OIDC_GROUP_FIELD",
959959
// This value is intentionally blank. If this is empty, then OIDC group

docs/admin/auth.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ CODER_TLS_CLIENT_KEY_FILE=/path/to/key.pem
231231
If your OpenID Connect provider supports group claims, you can configure Coder
232232
to synchronize groups in your auth provider to groups within Coder.
233233

234-
To enable group sync, ensure that the `groups` claim is set. If group sync is
234+
To enable group sync, ensure that the `groups` claim is set by adding the correct scope to request. If group sync is
235235
enabled, the user's groups will be controlled by the OIDC provider. This means
236236
manual group additions/removals will be overwritten on the next login.
237237

@@ -242,6 +242,15 @@ CODER_OIDC_SCOPES=openid,profile,email,groups
242242
--oidc-scopes openid,profile,email,groups
243243
```
244244

245+
With the `groups` scope requested, we also need to map the `groups` claim name. Coder recommends using `groups` for the claim name. This step is necessary if your **scope's name** is something other than `groups`.
246+
247+
```console
248+
# as an environment variable
249+
CODER_OIDC_GROUP_FIELD=groups
250+
# as a flag
251+
--oidc-group-field groups
252+
```
253+
245254
On login, users will automatically be assigned to groups that have matching
246255
names in Coder and removed from groups that the user no longer belongs to.
247256

docs/cli/server.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ OIDC claim field to use as the email.
426426
| Environment | <code>$CODER_OIDC_GROUP_FIELD</code> |
427427
| YAML | <code>oidc.groupField</code> |
428428

429-
Change the OIDC default 'groups' claim field. By default, will be 'groups' if present in the oidc scopes argument.
429+
This field must be set if using the group sync feature and the scope name is not 'groups'. Set to the claim to be used for groups.
430430

431431
### --oidc-group-mapping
432432

0 commit comments

Comments
 (0)