Skip to content

Commit 6f3f0be

Browse files
fix(authpolicy): use three-way CEL expressions in OIDC patch template
Remove when:null and selector:null from the OIDC merge patch — Kubernetes merge patch does not reliably delete these fields, causing X-MaaS-Username to remain restricted to sk-oai-* tokens and yielding 500 AUTH_FAILURE refId 003 on OIDC DELETE and header-injection requests. The patch template now uses clean three-way CEL expressions without any when clause. The base auth-policy is unchanged (split headers approach for non-OIDC flows). Signed-off-by: Wen Liang <liangwen12year@gmail.com>
1 parent 0e7ef19 commit 6f3f0be

1 file changed

Lines changed: 7 additions & 20 deletions

File tree

scripts/data/maas-api-authpolicy-external-oidc-patch.yaml

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,45 +72,32 @@ spec:
7272
response:
7373
success:
7474
headers:
75-
# Override the base X-MaaS-Username / X-MaaS-Group headers so they
76-
# handle API keys, OIDC JWT, and OpenShift TokenReview.
77-
#
78-
# API keys (Bearer sk-oai-*): identity comes from apiKeyValidation metadata — the
79-
# base policy used plain selectors here. OIDC-only expressions omit that path and
80-
# yield empty username → maas-api HTTP 500 AUTH_FAILURE refId 001 on /v1/models.
81-
# Order: apiKeyValidation → OIDC claims → OpenShift TokenReview.
82-
# No "when" clause — these headers must apply to ALL token types (API keys,
83-
# OIDC JWT, OpenShift TokenReview). The three-way expression handles each case.
84-
# The base policy restricts these to sk-oai-* only; merge patch must explicitly
85-
# null the "when" to clear the base's restriction.
75+
# Merge patch replaces the entire response block, so all headers must
76+
# be re-declared. Use three-way CEL expressions (no "when" clause) so
77+
# headers resolve for all token types: API keys, OIDC JWT, OpenShift
78+
# TokenReview. The base policy's split X-MaaS-Username/OC approach
79+
# with "when" clauses cannot survive a merge patch (when:null does not
80+
# reliably clear fields), causing 500 AUTH_FAILURE refId 003.
8681
X-MaaS-Username:
87-
when: null
8882
plain:
89-
selector: null
9083
expression: >-
9184
(has(auth.metadata) && has(auth.metadata.apiKeyValidation)) ?
9285
auth.metadata.apiKeyValidation.username :
9386
(has(auth.identity.preferred_username) ?
9487
auth.identity.preferred_username :
9588
(has(auth.identity.sub) ? auth.identity.sub : auth.identity.user.username))
96-
# Never call .join on a missing path — that stringifies nil as "<nil>"
97-
# and breaks maas-api JSON parsing.
9889
X-MaaS-Group:
99-
when: null
10090
plain:
101-
selector: null
10291
expression: >-
10392
(has(auth.metadata) && has(auth.metadata.apiKeyValidation)) ?
10493
(size(auth.metadata.apiKeyValidation.groups) > 0 ?
10594
'["' + auth.metadata.apiKeyValidation.groups.join('","') + '"]' :
10695
'["system:authenticated"]') :
10796
(has(auth.identity.groups) && size(auth.identity.groups) > 0 ?
10897
'["system:authenticated","' + auth.identity.groups.join('","') + '"]' :
109-
(has(auth.identity.user.groups) && size(auth.identity.user.groups) > 0 ?
98+
(has(auth.identity.user) && has(auth.identity.user.groups) && size(auth.identity.user.groups) > 0 ?
11099
'["system:authenticated","' + auth.identity.user.groups.join('","') + '"]' :
111100
'["system:authenticated"]'))
112-
# Subscription: from API key validation (must be preserved from base policy).
113-
# /v1/models reads this header to filter by subscription.
114101
X-MaaS-Subscription:
115102
when:
116103
- selector: request.headers.authorization

0 commit comments

Comments
 (0)