Skip to content
Latest (currently 2026.10.2) has the newest features, bug fixes, and CVE patches of Solo Enterprise for agentgateway.

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Impersonation

Page as Markdown

Configure agentgateway to perform RFC 8693 impersonation, replacing a user’s IdP token with a new STS-signed JWT that carries only the user’s identity.

About impersonation

When an agent calls a downstream service such as an MCP server or API on behalf of a user, the downstream service typically requires a token to verify who is making the request and to decide what that caller is allowed to do.

According to the RFC 8693, impersonation token exchange is a security mechanism where an AI agent or client exchanges a user’s initial authentication token, such as a JWT from Keycloak, for a new, short-lived token with the same sub. The JWT is minted and signed by the STS before the agentgateway proxy forwards the token to the downstream system. The new token allows the agent to act on behalf of the user, accessing downstream APIs and services with the user’s permissions while ensuring auditability and adhering to security boundaries.

Without a valid token, the downstream service rejects the request. The agent cannot simply forward the user’s original IdP token due to the following reasons:

  • The downstream might not trust the IdP that issued the original token.
  • The token might be scoped to a different audience that the downstream does not accept.
  • Passing raw IdP tokens through the MCP stack can create security risks.

On-behalf-of (OBO) token exchange solves these challenges by using the agentgateway STS to validate the user’s IdP token and issue a new token that the downstream service can verify. The new token is signed by the STS’s private key and carries only the user’s identity (sub). No agent identity is included. From the downstream service’s perspective, the request appears to come directly from the user. The agent is indistinguishable from the user within that context as shown in the following flow.

    sequenceDiagram
    participant User
    participant Agent
    participant STS as agentgateway STS
    participant Downstream as MCP server

    User->>Agent: Request with IdP JWT  <br/>(e.g. Keycloak token)
    Agent->>STS: Token exchange request <br/>(grant_type=token-exchange,<br/>subject_token=user JWT,<br/>no actor_token)
    STS->>STS: Validate user JWT signature and claims
    STS->>STS: Mint new JWT<br/>(sub=user subject,<br/>iss = agentgateway STS,<br/>no act claim)
    STS-->>Agent: New STS-signed JWT
    Agent->>Downstream: Request with STS-signed JWT
    Downstream->>Downstream: Check user identity <br/>Agent identity is not tracked<br/>(Agent is indistinguishable from user)
    Downstream-->>Agent: Response
    Agent-->>User: Result
  



Example token without impersonation:

Without impersonation, the downstream service receives the upstream IdP token directly. The upstream token includes the original issuer (iss) and audience (aud) claim. The downstream service does not accept tokens with these claims. It is configured to only accept tokens that are issued by STS and that include an aud claim for the target downstream service.

{
  "iss": "https://keycloak.example.com/realms/my-realm",
  "sub": "user@example.com",
  "aud": "my-app",
  "scope": "read write",
  "exp": 1735678400
}

Example token after impersonation:

After the STS exchanges and mints a new token, the downstream service receives a JWT with the correct issuer and audience claims. The original user claim (sub) is preserved.

{
  "iss": "agentgateway.your-cluster.svc:7777",
  "sub": "user@example.com",
  "aud": "urn:example:target-service",
  "scope": "read write",
  "exp": 1735678400,
  "iat": 1735592000
}

Impersonation can be useful in the following scenarios:

  • The downstream service only needs to know the user’s identity, not which agent acted.
  • Audit requirements at the downstream service do not need agent-level traceability.
  • You want to normalize tokens across identity providers. For example, instead of configuring all downstream systems to trust all the IdPs that you use in your environment, you instead use a standard agentgateway-signed JWT for all downstream requests. The downstreams need to be configured to trust the STS as a token issuer.

Note

Impersonation is intended for internal services that you control. Because the agentgateway STS is the token issuer, the downstream service must be configured to trust it by pointing the downstream’s JWT validator at the STS JWKS endpoint. If you need to call an external SaaS API that is protected by a JWT validator that you cannot configure, use external identity provider exchange instead.

Note

Impersonation does not add an act claim to the issued token. If you need to preserve the identity of the agent that performs the call for auditing purposes, use delegation instead.

Before you begin

Complete the static MCP guide.

Set up Keycloak

Install Keycloak

This example uses Keycloak as the identity provider (IdP). You can use any IdP that supports OpenID Connect (OIDC).

  1. Create a namespace for your Keycloak deployment.

    kubectl create namespace keycloak
  2. Create the Keycloak deployment.

    kubectl -n keycloak apply -f https://raw.githubusercontent.com/solo-io/gloo-mesh-use-cases/main/policy-demo/oidc/keycloak.yaml
  3. Wait for the Keycloak rollout to finish.

    kubectl -n keycloak rollout status deploy/keycloak
  4. Set the Keycloak endpoint details from the load balancer service. If you are running locally in kind and need a local IP address for the load balancer service, consider using cloud-provider-kind.

    export ENDPOINT_KEYCLOAK=$(kubectl -n keycloak get service keycloak -o jsonpath='{.status.loadBalancer.ingress[0].ip}{.status.loadBalancer.ingress[0].hostname}'):8080
    export HOST_KEYCLOAK=$(echo ${ENDPOINT_KEYCLOAK} | cut -d: -f1)
    export PORT_KEYCLOAK=$(echo ${ENDPOINT_KEYCLOAK} | cut -d: -f2)
    export KEYCLOAK_URL=http://${ENDPOINT_KEYCLOAK}
    echo $KEYCLOAK_URL
  5. Open the Keycloak URL and log in with the default admin user. To log in, use the admin username and admin password.

    open $KEYCLOAK_URL

Create a realm and test user

Create an agentgateway realm with a test client and user. The test client gets a JSON Web Token (JWT) for the user with curl, without a browser redirect.

  1. Get an access token for the Keycloak admin user. The following commands use this token to create the realm, client, and user. If you see a parsing error, run the curl command without piping to jq.

    export KEYCLOAK_TOKEN=$(curl -d "client_id=admin-cli" -d "username=admin" -d "password=admin" -d "grant_type=password" "$KEYCLOAK_URL/realms/master/protocol/openid-connect/token" | jq -r .access_token)
    echo $KEYCLOAK_TOKEN
  2. Create a dedicated agentgateway realm. The master realm that Keycloak creates by default has special admin restrictions that can cause 403 errors during logins.

    curl -s -X POST "${KEYCLOAK_URL}/admin/realms" \
     -H "Authorization: Bearer $KEYCLOAK_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"realm":"agentgateway","enabled":true}'
  3. Save the JSON Web Key Set (JWKS) endpoint for the agentgateway realm. The STS validators use this endpoint to verify the user’s JWT.

    export KEYCLOAK_JWKS_URI=${KEYCLOAK_URL}/realms/agentgateway/protocol/openid-connect/certs
    echo $KEYCLOAK_JWKS_URI
  4. Create the fe-client-1 test client. This public client allows the password grant. Use it only for testing.

    curl -s -X POST "${KEYCLOAK_URL}/admin/realms/agentgateway/clients" \
      -H "Authorization: Bearer $KEYCLOAK_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
        "clientId": "fe-client-1",
        "name": "Frontend test client",
        "enabled": true,
        "publicClient": true,
        "directAccessGrantsEnabled": true,
        "standardFlowEnabled": true,
        "redirectUris": ["*"],
        "webOrigins": ["*"]
      }'
  5. Create a user1 user with a permanent password.

    # Create the user
    curl -s -X POST "${KEYCLOAK_URL}/admin/realms/agentgateway/users" \
      -H "Authorization: Bearer $KEYCLOAK_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{"username":"user1","firstName":"Alice","lastName":"Doe","email":"user1@example.com","enabled":true}'
    
    # Get the user ID
    USER1_ID=$(curl -s -H "Authorization: Bearer $KEYCLOAK_TOKEN" \
      "${KEYCLOAK_URL}/admin/realms/agentgateway/users" \
      | python3 -c "import sys,json; print([u['id'] for u in json.load(sys.stdin) if u['username']=='user1'][0])")
    
    # Set a permanent password
    curl -s -X PUT "${KEYCLOAK_URL}/admin/realms/agentgateway/users/$USER1_ID/reset-password" \
      -H "Authorization: Bearer $KEYCLOAK_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{"type":"password","value":"Password1!","temporary":false}'
  6. Get a JWT for user1 and check the issuer and user claims in the decoded payload.

    curl -s -X POST "${KEYCLOAK_URL}/realms/agentgateway/protocol/openid-connect/token" \
     -d 'grant_type=password' \
     -d 'client_id=fe-client-1' \
     -d 'username=user1' \
     -d 'password=Password1!' \
     | python3 -c "
    import sys, json, base64
    d = json.load(sys.stdin)
    payload = d['access_token'].split('.')[1]
    payload += '=' * (4 - len(payload) % 4)
    claims = json.loads(base64.b64decode(payload))
    print(json.dumps({k: claims.get(k) for k in ['iss', 'sub', 'azp', 'preferred_username']}, indent=2))
    "

    Example output:

    {
      "iss": "http://172.18.0.4:8080/realms/agentgateway",
      "sub": "0c5be8c9-8883-4d64-b5f4-2ab73940cc11",
      "azp": "fe-client-1",
      "preferred_username": "user1"
    }
    

Enable the STS

The security token service (STS) runs in the Solo Enterprise for agentgateway controller and serves port 7777. It uses three validator lists to authenticate the callers of its endpoints. The STS requires at least one entry in each list, and it does not start if a list is empty.

Validator listProtectsWhat it validates
subjectValidators/oauth2/token (token exchange)The user’s JWT from your IdP, which identifies the user in the exchange.
actorValidators/oauth2/tokenThe proxy’s Kubernetes service account token, which authenticates the proxy to the STS.
apiValidators/elicitations APICalls to list, create, update, and delete elicitations, such as calls from the Solo Enterprise for agentgateway UI. These calls send the user’s JWT, so a k8s validator rejects them with a 401 response.
  1. Save the current Helm values so that the upgrade keeps your installation settings.

    helm get values enterprise-agentgateway -n agentgateway-system -o yaml > values.yaml
  2. Create a Helm values file with the STS settings. The unquoted heredoc substitutes KEYCLOAK_JWKS_URI before Helm reads the file.

    cat > sts-values.yaml <<EOF
    tokenExchange:
      enabled: true
      issuer: "enterprise-agentgateway.agentgateway-system.svc.cluster.local:7777"
      tokenExpiration: 24h
      subjectValidators:
      - validatorType: remote
        remoteConfig:
          url: "${KEYCLOAK_JWKS_URI}"
      actorValidators:
      - validatorType: k8s
      apiValidators:
      - validatorType: remote
        remoteConfig:
          url: "${KEYCLOAK_JWKS_URI}"
      maintenance:
        enabled: true
    EOF
    Review the following table to understand this configuration.
    SettingDescription
    enabledEnable the STS.
    issuerThe issuer of the tokens that the STS mints, typically the address of the control plane service on port 7777.
    tokenExpirationThe lifetime of the tokens that the STS mints, such as 24h for 24 hours.
    subjectValidatorsValidators for the user’s JWT during token exchange. Set the type to remote and provide the JWKS URL of your IdP. Validators are tried in order.
    actorValidatorsValidators for the proxy’s identity. Set the type to k8s so that the STS validates the proxy’s Kubernetes service account token.
    apiValidatorsValidators for calls to the elicitations API. Set the type to remote and provide the JWKS URL of your IdP.
    maintenance.enabledOptional. Enable the periodic janitor that deletes expired, unused tokens and cleans up their related elicitations. Defaults to false. To tune the cleanup interval and retention periods, see Token maintenance.

    Note

    Earlier releases used the singular subjectValidator, actorValidator, and apiValidator fields. These fields are deprecated. If you set both forms, the STS tries the singular validator first.

  3. Install or upgrade Solo Enterprise for agentgateway with the STS settings.

    helm upgrade -i enterprise-agentgateway oci://us-docker.pkg.dev/solo-public/enterprise-agentgateway/charts/enterprise-agentgateway \
      -n agentgateway-system \
      --create-namespace \
      --version v2026.10.2 \
      -f values.yaml -f sts-values.yaml
  4. Verify that the controller is running and that the control plane service exposes port 7777 for the STS.

    kubectl get deploy -n agentgateway-system enterprise-agentgateway
    kubectl get svc -n agentgateway-system enterprise-agentgateway

    Example output:

    NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
    enterprise-agentgateway   1/1     1            1           2m51s
    
    NAME                      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
    enterprise-agentgateway   ClusterIP   10.96.195.136   <none>        9978/TCP,9093/TCP,7777/TCP   17h
    

Configure the proxy for token exchange

Set up the agentgateway proxy to perform token exchange by using the built-in STS server.

kubectl apply -f- <<EOF
apiVersion: enterpriseagentgateway.solo.io/v1alpha1
kind: EnterpriseAgentgatewayParameters
metadata:
  name: agw-params
  namespace: agentgateway-system
spec:
  env:
    - name: STS_URI
      value: http://enterprise-agentgateway.agentgateway-system.svc.cluster.local:7777/oauth2/token
    - name: STS_AUTH_TOKEN
      value: /var/run/secrets/xds-tokens/xds-token
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: agentgateway-proxy
  namespace: agentgateway-system
spec:
  gatewayClassName: enterprise-agentgateway
  infrastructure:
    parametersRef:
      group: enterpriseagentgateway.solo.io
      kind: EnterpriseAgentgatewayParameters
      name: agw-params
  listeners:
    - name: http
      port: 80
      protocol: HTTP
      allowedRoutes:
        namespaces:
          from: All
EOF

Optional: Test the STS server locally

You can optionally test the STS locally to verify that your JWT is minted as expected. These steps serve as confirmation that the JWT is correctly issued by the STS and contains the claims that your downstream services expect. The following example assumes that you set up Keycloak as the IdP.

  1. Generate a JWT token for the user1 user that you set up. You use this JWT token to trigger the OBO token exchange flow.

    export USER_TOKEN=$(curl -d 'client_id=fe-client-1' \
     -d 'username=user1' \
     -d 'password=Password1!' \
     -d 'grant_type=password' "$KEYCLOAK_URL/realms/agentgateway/protocol/openid-connect/token" | jq -r .access_token)
    echo $USER_TOKEN
  2. Review the JWT that you got.

    echo "$USER_TOKEN" | python3 -c "
    import base64, json, sys
    payload = sys.stdin.read().strip().split('.')[1]
    payload += '=' * (4 - len(payload) % 4)
    print(json.dumps(json.loads(base64.urlsafe_b64decode(payload)), indent=2))
    "
  3. Port-forward the STS server on port 7777.

    kubectl port-forward -n agentgateway-system svc/enterprise-agentgateway 7777:7777
    export STS_URL="http://localhost:7777"
  4. Send a token exchange request to the STS server. Provide the JWT that you created earlier. Note that this step serves as a confirmation that your STS is configured correctly. The token exchange request to the STS is automatically sent if the request passes through the agentgateway proxy. No user interaction is required.

    export STS_RESPONSE=$(curl -s -X POST "${STS_URL}/token" \
      -H "Content-Type: application/x-www-form-urlencoded" \
      -H "Accept: application/json" \
      -H "Authorization: Bearer ${USER_TOKEN}" \
      -d "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
      -d "subject_token=${USER_TOKEN}" \
      -d "subject_token_type=urn:ietf:params:oauth:token-type:jwt")
    echo "$STS_RESPONSE" | jq '.' 2>/dev/null || echo "$STS_RESPONSE"

    Example output:

    {
      "access_token": "eyJ...",
      "issued_token_type": "urn:ietf:params:oauth:token-type:jwt",
      "token_type": "Bearer"
    }
    
  5. Extract the access token from the STS token and decode it. Verify that your token has the same sub as your original Keycloak token and that the issuer is set to agentgateway.

    export NEW_TOKEN=$(echo "$STS_RESPONSE" | jq -r '.access_token')
    echo "$NEW_TOKEN" | python3 -c "
    import base64, json, sys
    payload = sys.stdin.read().strip().split('.')[1]
    payload += '=' * (4 - len(payload) % 4)
    print(json.dumps(json.loads(base64.urlsafe_b64decode(payload)), indent=2))
    "

    Example output:

    {
      "exp": 1775270769,
      "iat": 1775184369,
      "iss": "enterprise-agentgateway.agentgateway-system.svc.cluster.local:7777",
      "nbf": 1775184369,
      "scope": "groups profile email",
      "sub": "e07b0795-6192-441a-ae9a-d8cf37b3e790"
    }
    

Set up impersonation

  1. Create an EnterpriseAgentgatewayPolicy resource with your OBO policy. In this example, you protect the MCP server that you set up before you began. Because the policy is set to ExchangeOnly without a specific provider, the STS defaults to the standard OBO flow and uses the STS as the token issuer.

    kubectl apply -f- <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayPolicy
    metadata:
      name: impersonation
      namespace: default
    spec:
      targetRefs:
      - kind: EnterpriseAgentgatewayBackend
        group: enterpriseagentgateway.solo.io
        name: mcp-backend        # works the same for non-MCP routes
      backend:
        tokenExchange:
          mode: ExchangeOnly
    EOF
  2. Configure the downstream service to trust the agentgateway STS. The STS exposes two standard discovery endpoints that you point the downstream service’s JWT validator to, as described in the following table.

    EndpointPurpose
    /.well-known/oauth-authorization-serverOAuth 2.0 server , such as https://enterprise-agentgateway.agentgateway-system.svc.cluster.local:7777/.well-known/oauth-authorization-server.
    /.well-known/jwks.jsonThe STS public key set for JWT signature verification, such as https://enterprise-agentgateway.agentgateway-system.svc.cluster.local:7777/.well-known/jwks.json.
  3. Enable debug logging on the controller.

    kubectl port-forward deploy/enterprise-agentgateway \
     -n agentgateway-system 9095 & PF_PID=$! && sleep 1 && curl -X PUT "http://localhost:9095/logging?level=debug" ; kill $PF_PID
  4. Look at the logs.

    kubectl logs deploy/enterprise-agentgateway -n agentgateway-system | tail -3

    Example output:

    {"time":"2026-04-03T22:12:25.304167298Z","level":"debug","msg":"processing token exchange request","component":"sts/handler","resource":"default/mcp-backend","audience":"","has_actor_token":false}
    {"time":"2026-04-03T22:12:25.304188215Z","level":"debug","msg":"no provider mapping found for resource, falling back to standard OBO","component":"sts/handler","resource":"default/mcp-backend"}
    {"time":"2026-04-03T22:12:25.307276507Z","level":"info","msg":"request","component":"request","method":"POST","path":"/oauth2/token","StatusCode":200,"latency":3143417,"clientIP":"10.244.0.18"}
    
  5. Generate a JWT token for the user1 user that you set up. You use this JWT token to trigger the token exchange flow.

    export USER_TOKEN=$(curl -d 'client_id=fe-client-1' \
     -d 'username=user1' \
     -d 'password=Password1!' \
     -d 'grant_type=password' "$KEYCLOAK_URL/realms/agentgateway/protocol/openid-connect/token" | jq -r .access_token)
    echo $USER_TOKEN
  6. Send a request to the MCP server without an Authorization token. Verify that this request fails. The token exchange policy that you configured enforces JWT authentication to the MCP backend.

    curl -vik -X POST http://localhost:8080/mcp \
     -H "Content-Type: application/json" \
     -H "Accept: application/json, text/event-stream" \
     -H "mcp-protocol-version: 2025-06-18" \
     -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "initialize",
       "params": {
         "protocolVersion": "2025-06-18",
         "capabilities": {},
         "clientInfo": {"name": "curl-client", "version": "1.0"}
       }
    }'

    Example output:

    < HTTP/1.1 500 Internal Server Error
    HTTP/1.1 500 Internal Server Error
    ...
    < 
    
    * Connection #0 to host localhost left intact
    {"jsonrpc":"2.0","id":1,"error":{"code":-32603,"message":"failed to send message: send error: http upstream error: http request failed: invalid request"}}%
    
  7. Send a request to the MCP server with a valid Authorization header. Verify that this time, the request succeeds. The provided token is validated by the Keycloak JWKS and then automatically minted by the STS for a new token.

    curl -vik -X POST http://localhost:8080/mcp \
     -H "Content-Type: application/json" \
     -H "Accept: application/json, text/event-stream" \
     -H "mcp-protocol-version: 2025-06-18" \
     -H "Authorization: Bearer $USER_TOKEN" \
     -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "initialize",
       "params": {
         "protocolVersion": "2025-06-18",
         "capabilities": {},
         "clientInfo": {"name": "curl-client", "version": "1.0"}
       }
    }'

    Example output:

    < HTTP/1.1 200 OK
    HTTP/1.1 200 OK
    
    ...
    data: {"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","capabilities":{"experimental":{},"tools":{"listChanged":false}},"serverInfo":{"name":"mcp-website-fetcher","version":"1.14.1"}}}

Cleanup

You can optionally remove the resources that you set up as part of this guide.
kubectl delete enterpriseagentgatewaypolicy impersonation