Skip to content

Commit c8c30d5

Browse files
Merge pull request #2352 from everettraven/bugfix/oidc-username-claim-required
CNTRLPLANE-337: authentication: oidc: make username claim mapping required
2 parents 2b129d9 + c6e2d73 commit c8c30d5

File tree

23 files changed

+436
-50
lines changed

23 files changed

+436
-50
lines changed

config/v1/tests/authentications.config.openshift.io/ExternalOIDC.yaml

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if w
22
name: "Authentication"
33
crdName: authentications.config.openshift.io
44
featureGates:
5-
- ExternalOIDC
5+
- ExternalOIDC
66
tests:
77
onCreate:
88
- name: Should be able to create a minimal Authentication
@@ -121,6 +121,64 @@ tests:
121121
username:
122122
claim: "preferred_username"
123123
prefixPolicy: NoPrefix
124+
- name: Cannot set OIDC providers with no claim mappings
125+
initial: |
126+
apiVersion: config.openshift.io/v1
127+
kind: Authentication
128+
spec:
129+
type: OIDC
130+
oidcProviders:
131+
- name: myoidc
132+
issuer:
133+
issuerURL: https://meh.tld
134+
audiences: ['openshift-aud']
135+
expectedError: "Required value"
136+
- name: Cannot set OIDC providers with no username claim mapping
137+
initial: |
138+
apiVersion: config.openshift.io/v1
139+
kind: Authentication
140+
spec:
141+
type: OIDC
142+
oidcProviders:
143+
- name: myoidc
144+
issuer:
145+
issuerURL: https://meh.tld
146+
audiences: ['openshift-aud']
147+
claimMappings:
148+
groups:
149+
claim: roles
150+
expectedError: "Required value"
151+
- name: Can set OIDC providers with empty group claim mapping
152+
initial: |
153+
apiVersion: config.openshift.io/v1
154+
kind: Authentication
155+
spec:
156+
type: OIDC
157+
oidcProviders:
158+
- name: myoidc
159+
issuer:
160+
issuerURL: https://meh.tld
161+
audiences: ['openshift-aud']
162+
claimMappings:
163+
username:
164+
claim: "username"
165+
groups:
166+
claim: ""
167+
expected: |
168+
apiVersion: config.openshift.io/v1
169+
kind: Authentication
170+
spec:
171+
type: OIDC
172+
oidcProviders:
173+
- name: myoidc
174+
issuer:
175+
issuerURL: https://meh.tld
176+
audiences: ['openshift-aud']
177+
claimMappings:
178+
username:
179+
claim: "username"
180+
groups:
181+
claim: ""
124182
onUpdate:
125183
- name: Updating OIDC provider with a client that's not in the status
126184
initial: &initConfig |
@@ -133,6 +191,9 @@ tests:
133191
issuer:
134192
issuerURL: https://meh.tld
135193
audiences: ['openshift-aud']
194+
claimMappings:
195+
username:
196+
claim: username
136197
oidcClients:
137198
- componentNamespace: namespace
138199
componentName: preexisting
@@ -158,6 +219,9 @@ tests:
158219
issuer:
159220
issuerURL: https://meh.tld
160221
audiences: ['openshift-aud']
222+
claimMappings:
223+
username:
224+
claim: username
161225
oidcClients:
162226
- componentNamespace: namespace
163227
componentName: preexisting
@@ -189,6 +253,9 @@ tests:
189253
issuer:
190254
issuerURL: https://meh.tld
191255
audiences: ['openshift-aud']
256+
claimMappings:
257+
username:
258+
claim: username
192259
oidcClients:
193260
- componentNamespace: dif-namespace
194261
componentName: tehName
@@ -214,6 +281,9 @@ tests:
214281
issuer:
215282
issuerURL: https://meh.tld
216283
audiences: ['openshift-aud']
284+
claimMappings:
285+
username:
286+
claim: username
217287
oidcClients:
218288
- componentNamespace: namespace
219289
componentName: preexisting
@@ -239,6 +309,9 @@ tests:
239309
issuer:
240310
issuerURL: https://meh.tld
241311
audiences: ['openshift-aud']
312+
claimMappings:
313+
username:
314+
claim: username
242315
oidcClients:
243316
- componentNamespace: namespace
244317
componentName: preexisting
@@ -265,6 +338,9 @@ tests:
265338
issuer:
266339
issuerURL: https://meh.tld
267340
audiences: ['openshift-aud']
341+
claimMappings:
342+
username:
343+
claim: username
268344
oidcClients:
269345
- componentNamespace: namespace
270346
componentName: preexisting
@@ -298,3 +374,89 @@ tests:
298374
- componentNamespace: namespace2
299375
componentName: name3
300376
expected: *removeFromStatus
377+
- name: Should allow updating other fields if existing username claim mapping is empty string
378+
initialCRDPatches:
379+
- op: remove
380+
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/oidcProviders/items/properties/claimMappings/properties/username/properties/claim/minLength
381+
initial: |
382+
apiVersion: config.openshift.io/v1
383+
kind: Authentication
384+
spec:
385+
type: OIDC
386+
oidcProviders:
387+
- name: myoidc
388+
issuer:
389+
issuerURL: https://meh.tld
390+
audiences: ['openshift-aud']
391+
claimMappings:
392+
username:
393+
claim: ""
394+
updated: |
395+
apiVersion: config.openshift.io/v1
396+
kind: Authentication
397+
spec:
398+
type: OIDC
399+
oidcProviders:
400+
- name: myoidc
401+
issuer:
402+
issuerURL: https://huh.tld
403+
audiences: ['openshift-aud']
404+
claimMappings:
405+
username:
406+
claim: ""
407+
expected: |
408+
apiVersion: config.openshift.io/v1
409+
kind: Authentication
410+
spec:
411+
type: OIDC
412+
oidcProviders:
413+
- name: myoidc
414+
issuer:
415+
issuerURL: https://huh.tld
416+
audiences: ['openshift-aud']
417+
claimMappings:
418+
username:
419+
claim: ""
420+
- name: Should allow updating other fields if existing username claim mapping is longer than 256 characters
421+
initialCRDPatches:
422+
- op: remove
423+
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/oidcProviders/items/properties/claimMappings/properties/username/properties/claim/maxLength
424+
initial: |
425+
apiVersion: config.openshift.io/v1
426+
kind: Authentication
427+
spec:
428+
type: OIDC
429+
oidcProviders:
430+
- name: myoidc
431+
issuer:
432+
issuerURL: https://meh.tld
433+
audiences: ['openshift-aud']
434+
claimMappings:
435+
username:
436+
claim: "thisisanincrediblylongclaimnamethatwhileacceptableinjwtsisgenerallyadvisedagainstbecauseitisextremelylongandnoteasilyusablebutmaybethereisausecaseouttherethathasdecidedthattheyneedtousethisextremelylongclaimnameforsomereasoneventhoughtheyreallyshouldreconsiderthis"
437+
updated: |
438+
apiVersion: config.openshift.io/v1
439+
kind: Authentication
440+
spec:
441+
type: OIDC
442+
oidcProviders:
443+
- name: myoidc
444+
issuer:
445+
issuerURL: https://huh.tld
446+
audiences: ['openshift-aud']
447+
claimMappings:
448+
username:
449+
claim: "thisisanincrediblylongclaimnamethatwhileacceptableinjwtsisgenerallyadvisedagainstbecauseitisextremelylongandnoteasilyusablebutmaybethereisausecaseouttherethathasdecidedthattheyneedtousethisextremelylongclaimnameforsomereasoneventhoughtheyreallyshouldreconsiderthis"
450+
expected: |
451+
apiVersion: config.openshift.io/v1
452+
kind: Authentication
453+
spec:
454+
type: OIDC
455+
oidcProviders:
456+
- name: myoidc
457+
issuer:
458+
issuerURL: https://huh.tld
459+
audiences: ['openshift-aud']
460+
claimMappings:
461+
username:
462+
claim: "thisisanincrediblylongclaimnamethatwhileacceptableinjwtsisgenerallyadvisedagainstbecauseitisextremelylongandnoteasilyusablebutmaybethereisausecaseouttherethathasdecidedthattheyneedtousethisextremelylongclaimnameforsomereasoneventhoughtheyreallyshouldreconsiderthis"

0 commit comments

Comments
 (0)