Skip to content

Commit 914ee1b

Browse files
Fixed code rabbit comments & docs
Signed-off-by: Dmytro Zaharnytskyi <zdmytro@redhat.com>
1 parent fd34f12 commit 914ee1b

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
lines changed

docs/samples/install/keycloak/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ The easiest way to configure realms is through the web UI:
7171
- **Authorization:** OFF
7272
- **Authentication flow:** Standard flow, Direct access grants
7373
- Click "Next"
74-
- **Valid redirect URIs:** `https://*.{your-cluster-domain}/*`
75-
- **Web origins:** `+` (allows CORS from redirect URIs)
74+
- **Valid redirect URIs:** `https://maas.apps.{your-cluster-domain}/*` (restrict to the MaaS gateway host)
75+
- **Web origins:** `https://maas.apps.{your-cluster-domain}` (restrict to the MaaS gateway host)
7676
- Click "Save"
7777

7878
5. **Configure Group Mapper**

scripts/README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Automated deployment script for OpenShift clusters supporting both operator-base
3535
- `--operator-type <odh|rhoai>` - Which operator to install (default: odh)
3636
- `--deployment-mode <operator|kustomize>` - Deployment method (default: operator)
3737
- `--namespace <namespace>` - Target namespace for deployment
38-
- `--external-oidc` - Enable external OIDC patching for `maas-api`
38+
- `--external-oidc` - Enable external OIDC on the `maas-api` AuthPolicy (kustomize mode only; in operator mode, configure `spec.externalOIDC` on the `ModelsAsService` CR)
39+
- `--enable-keycloak` - Deploy a Keycloak instance for external OIDC testing
3940
- `--enable-tls-backend` - Enable TLS backend (default)
4041
- `--disable-tls-backend` - Disable TLS backend
4142
- `--verbose` - Enable debug logging
@@ -147,10 +148,26 @@ Results:
147148

148149
---
149150

150-
### External OIDC Test Configuration
151-
This repository no longer provisions a temporary Keycloak instance for external OIDC testing.
151+
### External OIDC
152152

153-
Use an externally provisioned OIDC provider and set these variables when running the Prow-style E2E flow with `EXTERNAL_OIDC=true`:
153+
External OIDC can be enabled in two ways:
154+
155+
**Operator mode:** Edit the `ModelsAsService` CR to add `spec.externalOIDC` with
156+
`issuerUrl` and `clientId`. The operator patches the AuthPolicy automatically.
157+
158+
**Kustomize mode:** Use `--external-oidc` with env vars:
159+
```bash
160+
OIDC_ISSUER_URL=https://idp.example.com/realms/my-realm \
161+
OIDC_CLIENT_ID=my-client \
162+
./scripts/deploy.sh --deployment-mode kustomize --external-oidc
163+
```
164+
165+
For a development Keycloak instance, use `--enable-keycloak` or run
166+
`./scripts/setup-keycloak.sh` directly. See
167+
[Keycloak setup](../docs/samples/install/keycloak/README.md) for realm
168+
configuration and test users.
169+
170+
**E2E testing** with `EXTERNAL_OIDC=true` requires these environment variables:
154171

155172
- `OIDC_ISSUER_URL`
156173
- `OIDC_TOKEN_URL`

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ spec:
88
issuerUrl: __OIDC_ISSUER_URL__
99
priority: 1
1010
openshift-identities:
11+
when:
12+
- predicate: '!request.headers.authorization.startsWith("Bearer sk-oai-")'
1113
priority: 2
14+
authorization:
15+
oidc-client-bound:
16+
when:
17+
- predicate: '!request.headers.authorization.startsWith("Bearer sk-oai-") && request.headers.authorization.matches("^Bearer [^.]+\\.[^.]+\\.[^.]+$")'
18+
patternMatching:
19+
patterns:
20+
- selector: auth.identity.azp
21+
operator: eq
22+
value: __OIDC_CLIENT_ID__
23+
priority: 1
1224
response:
1325
success:
1426
headers:

scripts/deploy.sh

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,18 +1425,33 @@ resolve_external_oidc_issuer() {
14251425
printf '%s\n' "$oidc_issuer_url"
14261426
}
14271427

1428+
resolve_external_oidc_client_id() {
1429+
local oidc_client_id="${OIDC_CLIENT_ID:-}"
1430+
if [[ -z "$oidc_client_id" ]]; then
1431+
oidc_client_id=$(get_odh_overlay_param "oidc-client-id" 2>/dev/null || echo "")
1432+
fi
1433+
1434+
if [[ -z "$oidc_client_id" ]]; then
1435+
return 1
1436+
fi
1437+
1438+
printf '%s\n' "$oidc_client_id"
1439+
}
1440+
14281441
patch_authpolicy_from_template() {
14291442
local authpolicy_name="$1"
14301443
local template_file="$2"
14311444
local maas_namespace="$3"
14321445
local oidc_issuer_url="${4:-}"
1446+
local oidc_client_id="${5:-}"
14331447

14341448
local rendered_patch
14351449
rendered_patch="$(mktemp)"
14361450

14371451
sed \
14381452
-e "s|__MAAS_NAMESPACE__|${maas_namespace}|g" \
14391453
-e "s|__OIDC_ISSUER_URL__|${oidc_issuer_url}|g" \
1454+
-e "s|__OIDC_CLIENT_ID__|${oidc_client_id}|g" \
14401455
"$template_file" > "$rendered_patch"
14411456

14421457
kubectl patch authpolicy "$authpolicy_name" -n "$NAMESPACE" --type=merge --patch-file "$rendered_patch"
@@ -1481,8 +1496,8 @@ configure_maas_api_authpolicy() {
14811496
local api_keys_patch="$project_root/scripts/data/maas-api-authpolicy-api-keys-patch.yaml"
14821497
log_info " Patching AuthPolicy to ensure API key support..."
14831498
if ! patch_authpolicy_from_template "$authpolicy_name" "$api_keys_patch" "$NAMESPACE"; then
1484-
log_warn " Failed to patch AuthPolicy with API key configuration"
1485-
return 0
1499+
log_error " Failed to patch AuthPolicy with API key configuration"
1500+
return 1
14861501
fi
14871502

14881503
if [[ "$EXTERNAL_OIDC" != "true" ]]; then
@@ -1496,11 +1511,17 @@ configure_maas_api_authpolicy() {
14961511
return 1
14971512
}
14981513

1514+
local oidc_client_id
1515+
oidc_client_id="$(resolve_external_oidc_client_id)" || {
1516+
log_error "External OIDC requested but no oidc-client-id or OIDC_CLIENT_ID was configured"
1517+
return 1
1518+
}
1519+
14991520
local oidc_patch="$project_root/scripts/data/maas-api-authpolicy-external-oidc-patch.yaml"
1500-
log_info " Enabling OIDC JWT validation with issuer: $oidc_issuer_url"
1501-
if ! patch_authpolicy_from_template "$authpolicy_name" "$oidc_patch" "$NAMESPACE" "$oidc_issuer_url"; then
1502-
log_warn " Failed to patch AuthPolicy with external OIDC configuration"
1503-
return 0
1521+
log_info " Enabling OIDC JWT validation with issuer: $oidc_issuer_url, clientId: $oidc_client_id"
1522+
if ! patch_authpolicy_from_template "$authpolicy_name" "$oidc_patch" "$NAMESPACE" "$oidc_issuer_url" "$oidc_client_id"; then
1523+
log_error " Failed to patch AuthPolicy with external OIDC configuration"
1524+
return 1
15041525
fi
15051526

15061527
log_info " AuthPolicy patched successfully"

scripts/setup-keycloak.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#
2626
# Access Keycloak Admin Console:
2727
# 1. Get admin password:
28-
# kubectl get secret -n keycloak-system keycloak-initial-admin \
28+
# kubectl get secret -n keycloak-system maas-keycloak-initial-admin \
2929
# -o jsonpath='{.data.password}' | base64 -d
3030
# 2. Navigate to: https://keycloak.{cluster-domain}
3131
# 3. Login as: admin / {password-from-step-1}
@@ -92,6 +92,7 @@ spec:
9292
name: keycloak-operator
9393
source: community-operators
9494
sourceNamespace: openshift-marketplace
95+
startingCSV: keycloak-operator.v26.5.6
9596
installPlanApproval: Automatic
9697
EOF
9798

0 commit comments

Comments
 (0)