Skip to content

Phase 9: External OIDC Authentication (Optional)

Integrate MaaS authentication with corporate OIDC identity providers like Keycloak, Okta, or Azure AD so users can access MaaS with their corporate credentials.
Note

This phase requires a completed MaaS installation (through Phase 4) and at least one model deployed (Phase 5) to verify the OIDC flow end-to-end.

By default, MaaS authenticates users via OpenShift tokens (TokenReview). External OIDC lets you integrate with identity providers like Keycloak, Okta, or Azure AD so users can access MaaS with their corporate credentials - no OpenShift accounts needed.

Tip

All file paths and oc apply commands in this guide are relative to the CAI-Field-Manual-MaaS repository root. Make sure you have cloned it and are working from its root directory (see Getting Started).

Important

This guide is not a replacement for the official Red Hat OpenShift AI Models as a Service documentation (3.5 | 3.4). It is a companion resource with opinionated Kustomize manifests and automation scripts to accelerate deployment.

How It Works

MaaS uses a two-tier authentication model with external OIDC:

  1. Platform API access - Users get an OIDC token from the identity provider and use it as a Bearer token to call the MaaS API (list models, create API keys, manage subscriptions).

  2. Model inference - Users create an API key through the MaaS API using their OIDC token. The API key is then used for inference requests (/v1/chat/completions). API keys capture the user’s group memberships at creation time.

Group-based access control works through OIDC token claims:

  1. The OIDC provider defines user groups (e.g., data-scientists, ml-engineers)
  2. The OIDC token includes a groups claim with the user’s group memberships
  3. MaaS subscriptions and authorization policies reference these group names
  4. MaaS validates group memberships directly from the OIDC token - no OpenShift group sync needed
Note

Group names in MaaS subscriptions must match the group names in the OIDC token groups claim exactly.

Important

When using external OIDC, users create API keys through the MaaS API using curl or other HTTP clients. The Red Hat OpenShift AI dashboard uses OpenShift OAuth and does not support API key creation for external OIDC users.

Automated Setup

To deploy Keycloak, configure OIDC, and run verification in one go:

# Deploy Keycloak + configure MaaS for OIDC
./manifests/09-external-oidc/setup-keycloak.sh

# Verify the OIDC flow
./manifests/09-external-oidc/test-external-oidc.sh

To tear everything down:

./manifests/09-external-oidc/setup-keycloak.sh --cleanup

The rest of this page walks through each step manually.

Step 1: Deploy Keycloak

This section deploys Red Hat Build of Keycloak (RHBK) as the OIDC provider. If you already have an external identity provider, skip to Step 3.

Install the RHBK operator

oc create namespace maas-keycloak --dry-run=client -o yaml | oc apply -f -
oc apply -k manifests/09-external-oidc/keycloak/operator/

Wait for the operator to install:

# Watch until PHASE shows "Succeeded"
oc get csv -n maas-keycloak -w

Deploy Keycloak and PostgreSQL

oc apply -k manifests/09-external-oidc/keycloak/instance/

This creates:

  • A PostgreSQL database for Keycloak storage
  • A Keycloak instance connected to PostgreSQL
  • A KeycloakRealmImport that creates the maas realm with test users and groups

Set the Keycloak hostname. Without it, the RHBK operator creates a host-less Ingress that OpenShift cannot convert into a Route, and Step 2 will find no route:

CLUSTER_DOMAIN=$(oc get ingresses.config/cluster -o jsonpath='{.spec.domain}')
KEYCLOAK_HOSTNAME="keycloak-maas-keycloak.${CLUSTER_DOMAIN}"

oc patch keycloak keycloak -n maas-keycloak --type merge \
    -p "{\"spec\": {\"hostname\": {\"hostname\": \"${KEYCLOAK_HOSTNAME}\", \"strict\": false, \"strictBackchannel\": false}}}"

Wait for Keycloak to be ready:

# Wait for PostgreSQL
oc rollout status deployment/keycloak-pgsql -n maas-keycloak --timeout=120s

# Wait for Keycloak (check Ready condition)
oc get keycloak keycloak -n maas-keycloak -w

The READY column should show True. Then check the realm import:

oc get keycloakrealmimport maas -n maas-keycloak \
    -o jsonpath='{.status.conditions[?(@.type=="Done")].status}'

Should return True.

Step 2: Discover the Keycloak Issuer URL

Get the Keycloak route hostname and construct the issuer URL:

KEYCLOAK_HOST=$(oc get route -n maas-keycloak -o jsonpath='{.items[0].spec.host}')
KEYCLOAK_ISSUER="https://${KEYCLOAK_HOST}/realms/maas"
echo "Issuer URL: ${KEYCLOAK_ISSUER}"

Verify the OIDC discovery endpoint is accessible:

curl -sSk "${KEYCLOAK_ISSUER}/.well-known/openid-configuration" | jq .

You should see a JSON document with issuer, authorization_endpoint, token_endpoint, and other OIDC metadata.

Test users and groups

The imported realm includes two test users:

UsernamePasswordGroups
maas-usermaas-userdata-scientists, ml-engineers
restricted-userrestricted-userdata-scientists

You can verify the groups claim by getting a token:

# Get a token for maas-user
TOKEN=$(curl -sSk -X POST "${KEYCLOAK_ISSUER}/protocol/openid-connect/token" \
    -d "grant_type=password" \
    -d "client_id=maas-oidc" \
    -d "username=maas-user" \
    -d "password=maas-user" \
    -d "scope=openid groups" | jq -r '.access_token')

# Decode the JWT payload and check groups
echo "$TOKEN" | cut -d. -f2 | base64 -d 2>/dev/null | jq '{groups, preferred_username}'

Expected output:

{
  "groups": [
    "data-scientists",
    "ml-engineers"
  ],
  "preferred_username": "maas-user"
}

Step 3: Configure MaaS for External OIDC

Patch the MaaS tenant resource with the OIDC provider configuration:

oc patch aitenants.maas.opendatahub.io models-as-a-service -n ai-tenants \
    --type merge \
    -p "{\"spec\": {\"oidc\": {\"clientId\": \"maas-oidc\", \"issuerUrl\": \"${KEYCLOAK_ISSUER}\", \"ttl\": 300}}}"

Verify the patch was applied:

oc get aitenant models-as-a-service -n ai-tenants -o jsonpath='{.spec.oidc}' | jq .

Expected output:

{
  "clientId": "maas-oidc",
  "issuerUrl": "https://keycloak-maas-keycloak.apps.<cluster-domain>/realms/maas",
  "ttl": 300
}

The fields:

  • clientId - The Keycloak client ID registered for MaaS (maas-oidc)
  • issuerUrl - The OIDC issuer URL. MaaS fetches JWKS keys from <issuerUrl>/.well-known/openid-configuration to verify token signatures
  • ttl - How long (seconds) MaaS caches the OIDC provider’s signing keys before refreshing (default: 300, minimum: 30)
oc patch tenants.maas.opendatahub.io default-tenant -n models-as-a-service \
    --type merge \
    -p "{\"spec\": {\"externalOIDC\": {\"clientId\": \"maas-oidc\", \"issuerUrl\": \"${KEYCLOAK_ISSUER}\"}}}"

Verify the patch was applied:

oc get tenant default-tenant -n models-as-a-service -o jsonpath='{.spec.externalOIDC}' | jq .

Expected output:

{
  "clientId": "maas-oidc",
  "issuerUrl": "https://keycloak-maas-keycloak.apps.<cluster-domain>/realms/maas"
}

Step 4: Create Subscriptions for OIDC Groups

MaaS subscriptions control which groups can access which models and at what rate limits. Create subscriptions that reference the OIDC group names:

oc apply -k manifests/09-external-oidc/maas-oidc/

This creates:

  • Two MaaSSubscription resources targeting the data-scientists and ml-engineers groups
  • Two MaaSAuthPolicy resources granting those groups access to the simulator model
Note

The group names in subscriptions (data-scientists, ml-engineers) must match exactly the group names in the OIDC token groups claim. MaaS validates group memberships directly from the token without any OpenShift group sync.

Verify the resources were created:

oc get maassubscription,maasauthpolicy -n models-as-a-service

You should see the OIDC subscriptions and auth policies alongside any existing ones.

If you have models other than the simulator deployed, you can edit the subscription and auth policy manifests to reference your model names and namespaces before applying.

Step 5: Verify External OIDC

Automated verification

./manifests/09-external-oidc/test-external-oidc.sh

Expected output:

=========================================
  External OIDC Test Summary
=========================================
  MaaS URL:    https://maas.<cluster-domain>
  Keycloak:    https://keycloak-maas-keycloak.apps.<cluster-domain>
  Passed:      6
  Failed:      0
  Status:      ALL CHECKS PASSED
=========================================

Manual verification

Get an OIDC token

KEYCLOAK_HOST=$(oc get route -n maas-keycloak -o jsonpath='{.items[0].spec.host}')
KEYCLOAK_ISSUER="https://${KEYCLOAK_HOST}/realms/maas"

TOKEN=$(curl -sSk -X POST "${KEYCLOAK_ISSUER}/protocol/openid-connect/token" \
    -d "grant_type=password" \
    -d "client_id=maas-oidc" \
    -d "username=maas-user" \
    -d "password=maas-user" \
    -d "scope=openid groups" | jq -r '.access_token')

echo "Token: ${TOKEN:0:50}..."

List available models

CLUSTER_DOMAIN=$(oc get ingresses.config/cluster -o jsonpath='{.spec.domain}')

curl -sSk \
    -H "Authorization: Bearer ${TOKEN}" \
    -H "Content-Type: application/json" \
    "https://maas.${CLUSTER_DOMAIN}/maas-api/v1/models" | jq .

If authentication is successful, the API returns a list of models available to the groups in your token. An empty list means the token is valid but the user’s groups have no matching subscriptions.

Create an API key

API_KEY_RESPONSE=$(curl -sSk -X POST \
    -H "Authorization: Bearer ${TOKEN}" \
    -H "Content-Type: application/json" \
    -d '{"name": "my-oidc-key", "expiresInDays": 7}' \
    "https://maas.${CLUSTER_DOMAIN}/maas-api/v1/api-keys")

echo "$API_KEY_RESPONSE" | jq .
API_KEY=$(echo "$API_KEY_RESPONSE" | jq -r '.key')
Important

API keys capture the user’s group memberships at the time of creation. If a user is removed from a group in Keycloak, their existing API keys retain the original group associations until they expire or are manually revoked.

Run inference with the API key

Get the model ID from /v1/models and send a chat completion:

MODEL_ID=$(curl -sSk \
    -H "Authorization: Bearer ${API_KEY}" \
    "https://maas.${CLUSTER_DOMAIN}/v1/models" | jq -r '.data[0].id')

curl -sSk -X POST \
    -H "Authorization: Bearer ${API_KEY}" \
    -H "Content-Type: application/json" \
    -d "{\"model\": \"${MODEL_ID}\", \"messages\": [{\"role\": \"user\", \"content\": \"Hello from OIDC!\"}], \"max_tokens\": 20}" \
    "https://maas.${CLUSTER_DOMAIN}/v1/chat/completions" | jq .
Tip

See the OIDC Authentication demo for a presenter-ready walkthrough with a click-through UI and CLI client. The JWKS Cache demo proves that JWT signatures are verified locally from cached keys. All demos are listed on the Demos page.

Cleanup

To remove the OIDC configuration and Keycloak:

# Automated cleanup
./manifests/09-external-oidc/setup-keycloak.sh --cleanup

Or manually:

# Remove OIDC config from tenant
oc patch aitenants.maas.opendatahub.io models-as-a-service -n ai-tenants \
    --type json \
    -p '[{"op": "remove", "path": "/spec/oidc"}]'

# Remove OIDC subscriptions and auth policies
oc delete maassubscription oidc-data-scientists oidc-ml-engineers -n models-as-a-service
oc delete maasauthpolicy oidc-data-scientists-access oidc-ml-engineers-access -n models-as-a-service

# Remove Keycloak
oc delete namespace maas-keycloak
# Remove OIDC config from tenant
oc patch tenants.maas.opendatahub.io default-tenant -n models-as-a-service \
    --type json \
    -p '[{"op": "remove", "path": "/spec/externalOIDC"}]'

# Remove OIDC subscriptions and auth policies
oc delete maassubscription oidc-data-scientists oidc-ml-engineers -n models-as-a-service
oc delete maasauthpolicy oidc-data-scientists-access oidc-ml-engineers-access -n models-as-a-service

# Remove Keycloak
oc delete namespace maas-keycloak

After removing the OIDC configuration, MaaS falls back to the default OpenShift TokenReview authentication. Existing API keys created by OIDC users will stop working once revoked or expired.

Bring Your Own Identity Provider

If you have an existing OIDC provider (Okta, Azure AD, etc.) instead of Keycloak, you only need:

  1. A public (or confidential) OIDC client registered for MaaS
  2. The client configured to include the groups claim in ID/access tokens
  3. User groups that map to MaaS subscription group names

Skip Steps 1-2 and go directly to Step 3, replacing the clientId and issuerUrl with your provider’s values.