For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Access token validation
Validate access tokens from an external identity provider.
For more information or other OAuth options, see the OAuth about page.
Before you begin
Step 1: Set up your Identity Provider
Set up an OpenID Connect (OIDC) compatible identity provider (IdP).
For example, you can use Keycloak as an IdP.
Step 2: Enforce access token validation
Use AuthConfig and EnterpriseAgentgatewayPolicy resources to apply the auth rules to the routes that you want to secure with access token validation.
Create an AuthConfig resource with your access token validation rules. The following example uses JWT validation and an inline JWKS server to provide the JWT. For more access token validation options, see the Gloo Edge API docs. For more information about JWTs, see the JWT guide.
kubectl apply -f- <<EOF apiVersion: extauth.solo.io/v1 kind: AuthConfig metadata: name: oauth-jwt-validation namespace: agentgateway-system spec: configs: - oauth2: accessTokenValidation: jwt: localJwks: inlineString: >- $KEYCLOAK_CERT_KEYS EOFReview the following table to understand this configuration.
Field Description oauth2.accessTokenValidation.jwtSet up the OAuth policy to validate access tokens that conform to the JSON Web Token (JWT) specification. localJwks.inlineStringEmbed a local JWKS as a string, based on the value that you retrieved when you set up your IdP. Verify that the AuthConfig is in an Accepted state.
kubectl get authconfig oauth-jwt-validation -n agentgateway-system -o yamlIf you see a
REJECTEDerror similar toinvalid character 'k' looking for beginning of object key string, try copying the$KEYCLOAK_CERT_KEYSvalue manually again.Create an EnterpriseAgentgatewayPolicy resource that refers to the AuthConfig that you created earlier. The following policy applies external auth to all routes that the Gateway serves.
kubectl apply -f - <<EOF apiVersion: enterpriseagentgateway.solo.io/v1alpha1 kind: EnterpriseAgentgatewayPolicy metadata: name: oauth-jwt-validation namespace: agentgateway-system spec: targetRefs: - group: gateway.networking.k8s.io kind: Gateway name: agentgateway-proxy traffic: entExtAuth: authConfigRef: name: oauth-jwt-validation namespace: agentgateway-system backendRef: name: ext-auth-service-enterprise-agentgateway namespace: agentgateway-system port: 8083 EOF
Step 3: Verify access token validation
Send various requests to verify that OAuth is enforced for your routes.
Send a request to the OpenAI API without any token. Verify that the request fails with a 403 HTTP response code.
curl -v "${INGRESS_GW_ADDRESS}:80/openai" -H content-type:application/json -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "In the style of Shakespeare, write a series of sonnets that explain the concept of recursion in programming." } ] }'curl -v "localhost:8080/openai" -H content-type:application/json -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "In the style of Shakespeare, write a series of sonnets that explain the concept of recursion in programming." } ] }'Example output:
... * upload completely sent off: 358 bytes < HTTP/1.1 403 Forbidden < content-type: text/plain < content-length: 29 < * Connection #0 to host localhost left intact external authorization failed% ...Generate an access token from your IdP, such as with the following command for Keycloak. If you get a
404response, verify that the Keycloak URL and client credentials are correct. Common errors include using a different realm.export USER1_TOKEN=$(curl -Ssm 10 --fail-with-body \ -d "client_id=${KEYCLOAK_CLIENT}" \ -d "client_secret=${KEYCLOAK_SECRET}" \ -d "username=user1" \ -d "password=password" \ -d "grant_type=password" \ "$KEYCLOAK_URL/realms/master/protocol/openid-connect/token" | jq -r .access_token)echo $USER1_TOKENExample output:
eyJhbGc...Repeat the request with a valid token. Verify that the request now succeeds and returns a response from your LLM provider.
curl -v "${INGRESS_GW_ADDRESS}:80/openai" -H content-type:application/json \ -H "Authorization: Bearer $USER1_TOKEN" -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "In the style of Shakespeare, write a series of sonnets that explain the concept of recursion in programming." } ] }'curl -v "localhost:8080/openai" -H content-type:application/json \ -H "Authorization: Bearer $USER1_TOKEN" \ -d '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "In the style of Shakespeare, write a series of sonnets that explain the concept of recursion in programming." } ] }'Example output:
... < HTTP/1.1 200 OK ...
Cleanup
You can optionally remove the resources that you set up as part of this guide.kubectl delete authconfig oauth-jwt-validation -n agentgateway-system
kubectl delete EnterpriseAgentgatewayPolicy oauth-jwt-validation -n agentgateway-system