Authentication
Components Provisioned for This Phase
The following resources have been set up for you so you can focus on the policy configuration:
| Resource | Purpose |
|---|---|
GatewayClass, Gateway, HTTPRoute |
The Gateway API stack that routes traffic from the chat interface to the LLM API. The LLM API could be an internal or external endpoint — the gateway abstracts this away and provides a consistent point to apply policies. |
Kuadrant Operator & System |
The Connectivity Link operator, installed in the |
User Secrets |
API key secrets for two tiers: |
Verify Your Environment
Confirm everything is ready before starting the labs:
-
From the terminal in your Dev Spaces IDE, run the following command to check that gateway is up and running:
-
You should see output confirming the gateway exists and is in a ready state, similar to:
NAME CLASS ADDRESS PROGRAMMED AGE internal-ai-gateway openshift-default internal-ai-gateway-openshift-default.ai-gateway.svc.cluster.local True 14h
-
A dedicated HTTPRoute named
ai-proxy-routehas been created in your namespaceusername-devspaces, targeting the LLM API. This is the Gateway API resource you’ll attach authentication and rate limiting policies to.Run the following command to verify it is present:
This command lists the HTTPRoute details including the backend reference to the LLM API and the gateway it is attached to (which is the
internal-ai-gatewaythat you verified earlier). -
Look for output confirming the HTTPRoute exists and is correctly configured, similar to:
Name: ai-proxy-route Name: internal-ai-gateway Backend Refs: Name: ai-api-external Name: Host Controller Name: openshift.io/gateway-controller/v1 Name: internal-ai-gateway
You should see both the internal-ai-gateway Gateway and ai-proxy-route HTTPRoute in the output. If either is missing, contact the workshop facilitator.
|
Auth Policy Powered by Connectivity Link
Now that you understand the concepts and the intended architecture, it’s time to lock down the LLM endpoint. In this exercise you will create an AuthPolicy that is applied to the HTTPRoute (ai-proxy-route) and enforces a key-based authentication scheme. This will ensure that only authorized users with a valid API key can access the LLM, and it will extract identity information that we can use for rate limiting in the next step.
| We are using simple API key authentication for this workshop to keep things straightforward and simple, but Connectivity Link supports a wide range of authentication methods, including JWT, OAuth2 and more. |
Understanding the User Secrets
Two API key secrets have already been pre-created. Understanding their structure is important because both policies reference the labels and annotations on these secrets.
Silver tier user:
apiVersion: v1
kind: Secret
metadata:
name: trlp-tutorial-api-key-silver-username
namespace: kuadrant-system
labels:
authorino.kuadrant.io/managed-by: authorino
app: my-llm-username
annotations:
kuadrant.io/groups: silver
secret.kuadrant.io/user-id: username
stringData:
api_key: [some_random_string]
type: Opaque
Key fields in this secret:
-
authorino.kuadrant.io/managed-by: authorino— Marks this secret as managed by Authorino (the auth engine behind Connectivity Link). -
app: my-llm-username— Label selector — the AuthPolicy uses this to discover valid API keys. -
kuadrant.io/groups: silver— Group membership (Silver tier) — determines which rate limit tier applies. -
secret.kuadrant.io/user-id: username— Unique user ID — used as a counter key for per-user rate limiting.
The Gold tier secret follows the same structure but with:
-
kuadrant.io/groups: gold
Review and Apply the AuthPolicy
Examine the AuthPolicy and apply it by pasting the following command in your terminal:
Key fields in this policy:
-
namespace: username-devspaces— The policy is created in your namespace. -
name: ai-proxy-route— Targets theai-proxy-routeHTTPRoute — any request matching this route must pass authentication. -
app: my-llm-username— Looks for Kubernetes Secrets with this label to find valid API keys. -
prefix: Bearer— Expects the API key in theAuthorizationheader. -
kuadrant\.io/groups— Extracts the group annotation from the matched secret and exposes it asgroupsin the response filter. -
secret\.kuadrant\.io/user-id— Extracts the user ID annotation and exposes it asuserid. -
rego— OPA (Open Policy Agent) rule that only allows users whose group isgoldorsilver.
Verify the AuthPolicy
-
From the devspaces terminal, run the following command to check that the AuthPolicy was created successfully:
-
You should see output confirming the AuthPolicy exists, is targeting the correct HTTPRoute, and is in an enforced state, similar to:
Name: ai-proxy-auth Target Ref: Name: ai-proxy-route Status: Status: True Type: Accepted Status: True Type: Enforced