⚠️ Preview FeatureOIDC/OAuth authentication setup is currently in preview. Configuration flags or fields may change. Use for development and testing only.
This guide shows you how to set up a local development environment with Keycloak for OIDC authentication testing.
The local development environment includes:
- Kind cluster with OIDC-enabled API server
- Keycloak (deployed in the cluster) for OIDC provider
- Kubernetes MCP Server configured for OAuth/OIDC authentication
Set up the complete environment with one command:
make local-env-setupThis will:
- Install required tools (kind) to
./_output/bin/ - Create a Kind cluster with OIDC configuration
- Deploy Keycloak in the cluster
- Configure Keycloak realm and clients
- Build the MCP server binary
- Generate a configuration file at
_output/config.toml
After setup completes, run the server:
# Start the server
./kubernetes-mcp-server --port 8008 --config _output/config.tomlOr use the MCP Inspector for testing:
npx @modelcontextprotocol/inspector@latest $(pwd)/kubernetes-mcp-server --config _output/config.tomlAfter running the inspector, in the Authentication's OAuth 2.0 Flow set the Client ID to be mcp-client and the Scope to mcp-server, afterwards click the "Connect" button.
You'll be redirected to Keycloak. Enter the test credentials:
- Username:
mcp - Password:
mcp
After authentication, you can use the Tools from the Kubernetes-MCP-Server from the MCP Inspector, like below where we run the pods_list tool, to list all pods in the current cluster from all namespaces.
- Runs as a StatefulSet in the
keycloaknamespace - Exposed via Ingress with TLS at
https://keycloak.127-0-0-1.sslip.io:8443 - Uses cert-manager for TLS certificates
- Accessible from both host and cluster pods
- Kubernetes API server configured with OIDC authentication
- Points to Keycloak's
openshiftrealm as the OIDC issuer - Validates bearer tokens against Keycloak's JWKS endpoint
- API server trusts the cert-manager CA certificate
User Browser
|
| 1. OAuth login (https://keycloak.127-0-0-1.sslip.io:8443)
v
Keycloak
|
| 2. ID Token (aud: mcp-server)
v
MCP Server
|
| 3. Token Exchange (aud: openshift)
v
Keycloak
|
| 4. Exchanged Access Token
v
MCP Server
|
| 5. Bearer Token in API request
v
Kubernetes API Server
|
| 6. Validate token via OIDC
v
Keycloak JWKS
|
| 7. Token valid, execute tool
v
MCP Server → User
The setup automatically configures:
- Token lifespan: 30 minutes
- Session idle timeout: 30 minutes
-
mcp-client (public)
- Public client for browser-based OAuth login
- PKCE required for security
- Valid redirect URIs:
*
-
mcp-server (confidential)
- Confidential client with client secret
- Standard token exchange enabled
- Can exchange tokens with
aud: openshift - Default scopes:
openid,groups,mcp-server - Optional scopes:
mcp:openshift
-
openshift (confidential)
- Target client for token exchange
- Accepts exchanged tokens from
mcp-server - Used by Kubernetes API server for OIDC validation
- mcp-server: Default scope with audience mapper
- mcp:openshift: Optional scope for token exchange with audience mapper
- groups: Group membership mapper (included in tokens)
- Username:
mcp - Password:
mcp - Email:
mcp@example.com - RBAC:
cluster-admin(full cluster access)
The generated _output/config.toml includes:
require_oauth = true
oauth_audience = "mcp-server"
oauth_scopes = ["openid", "mcp-server"]
validate_token = false # Validation done by K8s API server
authorization_url = "https://keycloak.127-0-0-1.sslip.io:8443/realms/openshift"
sts_client_id = "mcp-server"
sts_client_secret = "..." # Auto-generated
sts_audience = "openshift" # Triggers token exchange
sts_scopes = ["mcp:openshift"]
certificate_authority = "_output/cert-manager-ca/ca.crt" # For HTTPS validationmake keycloak-statusShows:
- Keycloak pod status
- Service endpoints
- Access URL
- Admin credentials
make keycloak-logsOpen your browser to:
https://keycloak.127-0-0-1.sslip.io:8443
Admin credentials:
- Username:
admin - Password:
admin
Navigate to the openshift realm to view/modify the configuration.
Remove the local environment:
make local-env-teardownThis deletes the Kind cluster (Keycloak is removed with it).