Protect applications with Authservice
What you’ll accomplish
Section titled “What you’ll accomplish”You’ll configure operator-managed Authservice protection for an application. Authservice handles the browser OIDC flow at the Istio mesh boundary, validates requests before they reach the application, and requires users to log in through Keycloak before accessing the protected workload. This pattern can be preferable even when an application supports native OIDC because it keeps authentication enforcement outside the application.
Prerequisites
Section titled “Prerequisites”- UDS Core deployed (Authservice is included by default)
- UDS CLI installed
- Application deployed as a UDS Package
- Application pods labeled with a consistent selector that you control
Before you begin
Section titled “Before you begin”Authservice works by matching a label selector on your application’s pods. When a request comes in, Authservice intercepts it, validates the session, and redirects unauthenticated users to Keycloak. The UDS Operator creates the Authservice chain and the required Istio resources automatically. The first redirectUris entry you configure populates the match.prefix hostname and the callback_uri in the Authservice chain.
Authservice forwards the authenticated OIDC ID token to the application, while Istio preserves an inbound bearer token when one is already present. Use groups.anyOf to control which users can reach the workload. After access is granted, application code can use the forwarded identity and, when configured, groups claims for fine-grained authorization. See Register and customize SSO clients for the group membership mapper. Istio and Authservice also provide platform-level telemetry.
-
Add
enableAuthserviceSelectorto thePackageCRSet the selector to match the labels on your application pods:
package.yaml apiVersion: uds.dev/v1alpha1kind: Packagemetadata:name: httpbinnamespace: httpbinspec:sso:- name: Demo SSO httpbinclientId: uds-core-httpbinredirectUris:- "https://httpbin.uds.dev/login"enableAuthserviceSelector:app: httpbinAuthservice will protect all pods labeled
app: httpbinin thehttpbinnamespace. -
Apply the
PackageCRTerminal window uds zarf tools kubectl apply -f package.yamlThe UDS Operator creates a Keycloak client, configures Authservice, and sets up the Istio
RequestAuthenticationandAuthorizationPolicyresources automatically.
-
Use separate SSO clients for different auth rules
If you need different group restrictions or different redirect URIs per service, define multiple SSO clients, one per logical access boundary:
package.yaml apiVersion: uds.dev/v1alpha1kind: Packagemetadata:name: my-appnamespace: my-appspec:sso:- name: Admin ServicesclientId: my-app-adminredirectUris:- "https://admin.example.com/login"enableAuthserviceSelector:app: admingroups:anyOf:- "/UDS Core/Admin"- name: User ServicesclientId: my-app-usersredirectUris:- "https://app.example.com/login"enableAuthserviceSelector:app: usergroups:anyOf:- "/MyApp/Users" -
Apply the
PackageCRTerminal window uds zarf tools kubectl apply -f package.yaml
Verification
Section titled “Verification”Confirm the generated Istio policies and Authservice chain:
# Check that Authservice pods are runninguds zarf tools kubectl get pods -n authservice -l app.kubernetes.io/name=authservice
# Check the generated Istio policies for your appuds zarf tools kubectl get authorizationpolicy -n <app-namespace>uds zarf tools kubectl get requestauthentication -n <app-namespace>
# Linux: inspect the Authservice chain in its managed Secretuds zarf tools kubectl get secret authservice-uds -n authservice \ -o jsonpath='{.data.config\.json}' | base64 -d | jq '.chains[] | select(.name == "<client-id>")'
# macOS: use base64 -D instead of base64 -duds zarf tools kubectl get secret authservice-uds -n authservice \ -o jsonpath='{.data.config\.json}' | base64 -D | jq '.chains[] | select(.name == "<client-id>")'The Istio policies confirm JWT and Authservice enforcement. The Secret check confirms that the matching Authservice chain exists for the client.
End-to-end test:
- Open the application URL in a browser
- You should be redirected to the Keycloak login page
- Log in with valid credentials
- You should be redirected back to the application and see the content
Troubleshooting
Section titled “Troubleshooting”Problem: Package CR is rejected with a redirect URI error
Section titled “Problem: Package CR is rejected with a redirect URI error”Symptoms: kubectl apply fails with an error about invalid redirect URIs.
Solution: The redirect URI must not be a root path. Replace root-path URIs with a specific path:
# Invalid: root path not allowed for Authservice clientsredirectUris: - "https://myapp.example.com/"
# ValidredirectUris: - "https://myapp.example.com/login"Problem: Traffic is blocked with 503 errors in ambient mode
Section titled “Problem: Traffic is blocked with 503 errors in ambient mode”Symptoms: After applying the Package CR with ambient mode, requests to the application return 503.
Solution: Verify that the enableAuthserviceSelector matches both the pod labels AND the spec.selector of the Kubernetes Service for those pods. If the selector matches pod labels but not the service selector, the waypoint proxy is associated with the pods but not the service, so traffic through the service is blocked rather than routed through the SSO flow.
# Compare pod labels with service selectoruds zarf tools kubectl get pods -n <app-namespace> --show-labelsuds zarf tools kubectl get service -n <app-namespace> -o yaml | grep -A5 selectorProblem: Prometheus cannot scrape metrics from a protected pod
Section titled “Problem: Prometheus cannot scrape metrics from a protected pod”Symptoms: Prometheus shows scrape errors for a workload that uses enableAuthserviceSelector.
Solution: The monitor[].podSelector (or monitor[].selector) in the Package CR must include the labels from the protected workload’s sso[].enableAuthserviceSelector. The monitor selector may include additional labels. When the selectors match, the operator creates an authorization exception that allows Prometheus to scrape metrics directly without going through the SSO flow.
spec: monitor: - selector: app: httpbin # Must include the enableAuthserviceSelector labels portName: metrics targetPort: 9090 sso: - name: Demo SSO clientId: uds-core-httpbin redirectUris: - "https://httpbin.uds.dev/login" enableAuthserviceSelector: app: httpbin # Selects the protected application podsRelated documentation
Section titled “Related documentation”- Identity & Authorization concepts - compare operator-managed Authservice protection with native SSO
- Authservice repository - upstream configuration reference
PackageCR reference - full SSO andenableAuthserviceSelectorfield specification- Enforce group-based access controls - Restrict which Keycloak groups can access your Authservice-protected application.
- Configure Keycloak authentication methods - Enable or disable X.509/CAC, OTP, WebAuthn, and social login for users accessing your protected apps.
- Register and customize SSO clients - register native OIDC or SAML clients for applications that handle their own authentication flow