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:
- Identity verification & authentication → Kubernetes TokenReview
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.
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
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)
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.
The next steps walk you through installing Authorino, deploying and configuring a sample service called Talker API to be protected by the authorization service.
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
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.
❷ Deploy Authorino
❸ 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.
❹ 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
The command above creates an
Ingress with host name
talker-api.127.0.0.1.nip.io. 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:
❺ Create an
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.
❻ Consume the API protected by Authorino
Create a Kubernetes
ServiceAccount to identify the consumer application that will send requests to the protected API:
Consume the API from outside the cluster
Obtain a short-lived access token for the
api-consumer-1 service account:
Consume the API with a valid Kubernetes token:
Consume the API with the Kubernetes token expired (10 minutes):
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
- name: api-consumer
- mountPath: /var/run/secrets/tokens
- name: talker-api-access-token
Check the logs of
If you have started a Kubernetes cluster locally with Kind to try this user guide, delete it by running:
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 https://raw.githubusercontent.com/kuadrant/authorino-examples/main/envoy/envoy-notls-deploy.yaml
kubectl delete -f https://raw.githubusercontent.com/kuadrant/authorino-examples/main/talker-api/talker-api-deploy.yaml
kubectl delete authorino/authorino
To uninstall the Authorino Operator and manifests (CRDs, RBAC, etc), run:
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. ↩