Resources

OpenShift Credentials

  • username: username
  • password: user-password

Dev Spaces

Developer Console

Matrix

Rocket.Chat

BGCreated with Sketch.

Tasks to complete

Get Started
BGCreated with Sketch.

Congratulations!

Return to the dashboard to continue your journey.

Go to home

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 kuadrant-system namespace.

User Secrets

API key secrets for two tiers: silver and gold. Details below.


Verify Your Environment

Confirm everything is ready before starting the labs:

  1. From the terminal in your Dev Spaces IDE, run the following command to check that gateway is up and running:

    oc get gateway internal-ai-gateway -n ai-gateway


  2. 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


  3. A dedicated HTTPRoute named ai-proxy-route has been created in your namespace username-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:

    oc describe httproute -n username-devspaces | grep -E "Name:|Backend|Hostnames"

    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-gateway that you verified earlier).


  4. 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.


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:

oc apply -f - <<EOF apiVersion: kuadrant.io/v1 kind: AuthPolicy metadata: name: ai-proxy-auth namespace: username-devspaces spec: targetRef: group: gateway.networking.k8s.io kind: HTTPRoute name: ai-proxy-route rules: authentication: api-key-users: apiKey: selector: matchLabels: app: my-llm-username credentials: authorizationHeader: prefix: Bearer response: success: filters: identity: json: properties: groups: selector: auth.identity.metadata.annotations.kuadrant\.io/groups userid: selector: auth.identity.metadata.annotations.secret\.kuadrant\.io/user-id headers: authorization: plain: selector: auth.identity.metadata.annotations.secret\.kuadrant\.io/upstream-token unauthenticated: headers: "content-type": value: application/json body: value: | { "error": "Unauthenticated", "message": "Invalid or missing API Key." } unauthorized: headers: "content-type": value: application/json body: value: | { "error": "Forbidden", "message": "Access denied. Your account does not have the required permissions (gold/silver)." } authorization: allow-groups: opa: rego: | groups := split(object.get(input.auth.identity.metadata.annotations, "kuadrant.io/groups", ""), ",") allow { groups[_] == "gold" } allow { groups[_] == "silver" } EOF

Key fields in this policy:

  • namespace: username-devspaces — The policy is created in your namespace.

  • name: ai-proxy-route — Targets the ai-proxy-route HTTPRoute — 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 the Authorization header.

  • kuadrant\.io/groups — Extracts the group annotation from the matched secret and exposes it as groups in the response filter.

  • secret\.kuadrant\.io/user-id — Extracts the user ID annotation and exposes it as userid.

  • rego — OPA (Open Policy Agent) rule that only allows users whose group is gold or silver.


Verify the AuthPolicy

  1. From the devspaces terminal, run the following command to check that the AuthPolicy was created successfully:

    oc describe authpolicy -n username-devspaces | grep -v "Content" | grep -E "Name:|Target Ref:|Type:|Status:"

  2. 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


Does the ai-proxy-auth AuthPolicy show status True and Type Enforced ?

The AuthPolicy is enforced. Proceed to test authentication.

Check that you pasted the correct YAML and that the namespace is set to username-devspaces.