Skip to content

User guide: Authentication with Kubernetes tokens (TokenReview API)

Validate Kubernetes Service Account tokens to authenticate requests to your protected hosts.

Authorino capabilities featured in this guide:

Authorino can verify Kubernetes-valid access tokens (using Kubernetes TokenReview API).

These tokens can be either ServiceAccount tokens or any valid user access tokens issued to users of the Kubernetes server API.

The audiences claim of the token must include the requested host and port of the protected API (default), or all audiences specified in spec.identity.kubernetes.audiences of the AuthConfig.

For further details about Authorino features in general, check the docs.


  • Kubernetes server with permissions to install cluster-scoped resources (operator, CRDs and RBAC) and to create TokenRequests (to consume the protected service from outside the cluster)
  • jq

If you do not own a Kubernetes server already and just want to try out the steps in this guide, you can create a local containerized cluster by executing the command below. In this case, the main requirement is having Kind installed, with either Docker or Podman.

kind create cluster --name authorino-tutorial

The next steps walk you through installing Authorino, deploying and configuring a sample service called Talker API to be protected by the authorization service.

Using Kuadrant

If you are a user of Kuadrant and already have your workload cluster configured and sample service application deployed, as well as your Gateway API network resources applied to route traffic to your service, skip straight to step ❺.

At step ❺, instead of creating an AuthConfig custom resource, create a Kuadrant AuthPolicy one. The schema of the AuthConfig's spec matches the one of the AuthPolicy's, except, which is not available in the Kuadrant AuthPolicy. Host names in a Kuadrant AuthPolicy are inferred automatically from the Kubernetes network object referred in spec.targetRef and route selectors declared in the policy.

For more about using Kuadrant to enforce authorization, check out Kuadrant auth.

❶ Install the Authorino Operator (cluster admin required)

The following command will install the Authorino Operator in the Kubernetes cluster. The operator manages instances of the Authorino authorization service.

curl -sL | bash -s

❷ Deploy Authorino

The following command will request an instance of Authorino as a separate service1 that watches for AuthConfig resources in the default namespace2, with TLS disabled3.

kubectl apply -f -<<EOF
kind: Authorino
  name: authorino
      enabled: false
      enabled: false

❸ Deploy the Talker API

The Talker API is a simple HTTP service that echoes back in the response whatever it gets in the request. We will use it in this guide as the sample service to be protected by Authorino.

kubectl apply -f

❹ Setup Envoy

The following bundle from the Authorino examples deploys the Envoy proxy and configuration to wire up the Talker API behind the reverse-proxy, with external authorization enabled with the Authorino instance.4

kubectl apply -f

The command above creates an Ingress with host name If you are using a local Kubernetes cluster created with Kind, forward requests from your local port 8000 to the Envoy service running inside the cluster:

kubectl port-forward deployment/envoy 8000:8000 2>&1 >/dev/null &

❺ Create an AuthConfig

Create an Authorino AuthConfig custom resource declaring the auth rules to be enforced:

Kuadrant users – Remember to create an AuthPolicy instead of an AuthConfig. For more, see Kuadrant auth.
kubectl apply -f -<<EOF
kind: AuthConfig
  name: talker-api-protection

  - envoy.default.svc.cluster.local
        - talker-api

❻ Consume the API protected by Authorino

Create a ServiceAccount

Create a Kubernetes ServiceAccount to identify the consumer application that will send requests to the protected API:

kubectl apply -f -<<EOF
apiVersion: v1
kind: ServiceAccount
  name: api-consumer-1

Consume the API from outside the cluster

Obtain a short-lived access token for the api-consumer-1 service account:

export ACCESS_TOKEN=$(echo '{ "apiVersion": "", "kind": "TokenRequest", "spec": { "audiences": ["talker-api"], "expirationSeconds": 600 } }' | kubectl create --raw /api/v1/namespaces/default/serviceaccounts/api-consumer-1/token -f - | jq -r .status.token)

Consume the API with a valid Kubernetes token:

curl -H "Authorization: Bearer $ACCESS_TOKEN" -i
# HTTP/1.1 200 OK

Consume the API with the Kubernetes token expired (10 minutes):

curl -H "Authorization: Bearer $ACCESS_TOKEN" -i
# HTTP/1.1 401 Unauthorized
# www-authenticate: Bearer realm="authorized-service-accounts"
# x-ext-auth-reason: Not authenticated

Consume the API from inside the cluster

Deploy an application that consumes an endpoint of the Talker API, in a loop, every 10 seconds. The application uses a short-lived service account token mounted inside the container using Kubernetes Service Account Token Volume Projection to authenticate.

kubectl apply -f -<<EOF
apiVersion: v1
kind: Pod
  name: api-consumer

  - name: api-consumer
    command: ["./run"]
      - --endpoint=http://envoy.default.svc.cluster.local:8000/hello
      - --token-path=/var/run/secrets/tokens/api-token
      - --interval=10
    - mountPath: /var/run/secrets/tokens
      name: talker-api-access-token
  serviceAccountName: api-consumer-1
  - name: talker-api-access-token
      - serviceAccountToken:
          path: api-token
          expirationSeconds: 7200
          audience: talker-api

Check the logs of api-consumer:

kubectl logs -f api-consumer
# Sending...
# 200
# 200
# 200
# 200
# ...


If you have started a Kubernetes cluster locally with Kind to try this user guide, delete it by running:

kind delete cluster --name authorino-tutorial

Otherwise, delete the resources created in each step:

kubectl delete pod/api-consumer
kubectl delete serviceaccount/api-consumer-1
kubectl delete authconfig/talker-api-protection
kubectl delete -f
kubectl delete -f
kubectl delete authorino/authorino

To uninstall the Authorino Operator and manifests (CRDs, RBAC, etc), run:

kubectl delete -f

  1. In contrast to a dedicated sidecar of the protected service and other architectures. Check out Architecture > Topologies for all options. 

  2. namespaced reconciliation mode. See Cluster-wide vs. Namespaced instances

  3. For other variants and deployment options, check out Getting Started, as well as the Authorino CRD specification. 

  4. For details and instructions to setup Envoy manually, see Protect a service > Setup Envoy in the Getting Started page. If you are running your ingress gateway in Kubernetes and wants to avoid setting up and configuring your proxy manually, check out Kuadrant