Set up single sign-on (SSO) for applications in Service Mesh (ASM) using Alibaba Cloud Identity as a Service (IDaaS) as the identity provider (IdP). After this setup, users authenticate once through IDaaS and access all applications behind the ASM ingress gateway -- with zero code changes to your applications.
Although this guide uses IDaaS as the IdP, the same approach works with any OpenID Connect (OIDC)-compatible provider.
How it works
ASM delegates authentication to an external IdP through a custom authorization service based on oauth2-proxy. The following describes the request flow:
A user visits an application URL exposed through the ASM ingress gateway.
The ingress gateway forwards the request to oauth2-proxy, which checks for a valid session cookie.
If no valid session exists, oauth2-proxy redirects the user to the IDaaS login page.
After the user authenticates, IDaaS redirects back to oauth2-proxy with an authorization code.
oauth2-proxy exchanges the code for tokens, sets a session cookie, and forwards the original request -- along with user identity in a JSON Web Token (JWT) -- to the backend application.
Your applications never handle authentication logic. ASM and oauth2-proxy manage the entire OIDC flow at the infrastructure layer.
| Concept | Description |
|---|---|
| IdP (identity provider) | A service that stores and verifies user identities. In this guide, Alibaba Cloud IDaaS serves as the IdP. |
| OIDC (OpenID Connect) | A standard authentication protocol built on OAuth 2.0. For details, see the OpenID Connect specification. |
| Scope | An OIDC parameter that controls which types of user information (such as email or profile) an application can request from the IdP. |
Prerequisites
An ASM instance of Enterprise Edition. See Create an ASM instance.
A Container Service for Kubernetes (ACK) managed cluster. See Create an ACK managed cluster.
The ACK cluster is added to the ASM instance. See Add a cluster to an ASM instance.
Automatic sidecar injection is enabled for the
defaultnamespace. See Enable automatic sidecar proxy injection.
Step 1: Create an IDaaS instance and a test account
Create an IDaaS instance to serve as the identity store, and add a test user account for SSO verification.
Log on to the IDaaS console and create an IDaaS instance. Each IDaaS instance acts as an independent account system.
On the IDaaS tab of the EIAM page, click the ID of the IDaaS instance.
In the left-side navigation pane, choose Accounts > Accounts and Organizations.
On the Accounts tab, click Create User.
In the Create User panel, configure the required fields and click Confirm.
Step 2: Register an OIDC application in IDaaS
Register an OIDC application in IDaaS to expose the IdP interface that oauth2-proxy uses to authenticate users.
In the left-side navigation pane on the IDaaS instance details page, click Applications.
On the Applications page, click Add Application.
Click the Standard Protocols tab, then click Add Application in the OIDC card.
In the Add Application - OIDC dialog box, enter an application name and click Add.
On the OIDC application details page, click Sign-in, then click the SSO tab.
On the SSO tab, set Redirect URIs to: Replace
<ingress-gateway-clb-ip>with the IP address of the Classic Load Balancer (CLB) instance bound to the ingress gateway. Click Show Advanced Settings to select additional scopes, then click Save.http://<ingress-gateway-clb-ip>/oauth2/callbackClick Sign-in, then click the Grant Application Permissions tab. Click Authorize.
In the Authorize dialog box, select the test account created in Step 1 and click Confirm.
Record the OIDC application credentials
After you configure the OIDC application, record the following values. You need them to configure SSO in the ASM console.
| Value | Where to find it |
|---|---|
| Issuer | SSO tab > Application Settings section |
| client_id | General tab on the OIDC application details page |
| client_secret | General tab on the OIDC application details page |
Step 3: Deploy a test application and expose it through the ingress gateway
Deploy the httpbin sample application to verify that SSO correctly injects authenticated user identity into request headers.
Create an Istio gateway
Create a YAML file with the following content and apply it to the ASM instance. For details, see Manage Istio gateways.
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: ingressgateway
namespace: istio-system
spec:
selector:
app: istio-ingressgateway # Selects the default ingress gateway pod
servers:
- hosts:
- '*' # Accepts traffic for all hostnames
port:
name: http
number: 80
protocol: HTTPCreate a virtual service
Create a YAML file with the following content and apply it to the ASM instance. This virtual service routes all inbound traffic to the httpbin application. For details, see Manage virtual services.
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: ingressgateway-vs
namespace: istio-system
spec:
gateways:
- ingressgateway
hosts:
- '*'
http:
- name: default
route:
- destination:
host: httpbin.default.svc.cluster.local # Fully qualified service name
port:
number: 8000Verify the deployment
Run the following command to confirm that httpbin is accessible through the ingress gateway:
curl -I http://<ingress-gateway-ip>:80A successful response returns HTTP status 200.
Step 4: Register the OIDC authorization service in ASM
Register an OIDC-based custom authorization service in ASM to handle authentication for all ingress traffic.
Create the authorization service
Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose Mesh Security Center > Custom Authorization Service.
Click Define Custom Authorization Service.
Click the OIDC Authz and Authn Service tab and configure the following fields with the values from Step 2:
Field Value Issuer The Issuer URL from the OIDC application Client ID The client_idfrom the OIDC applicationClient Secret The client_secretfrom the OIDC applicationRedirect URL http://<ingress-gateway-clb-ip>/oauth2/callbackCookie Secret A randomly generated secret. See Generating a Cookie Secret. Click Create.
Get the authorization service domain name
Connect to the ACK cluster using its kubeconfig file and run:
kubectl get svc -n istio-system | grep oauth2proxy | awk '{print $1}'Record the output. You need it for the next step.
Route authentication requests to the authorization service
Create a virtual service that routes OAuth 2.0 callback traffic from the ingress gateway to the oauth2-proxy service:
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: oauth2-vs
namespace: istio-system
spec:
gateways:
- ingressgateway
hosts:
- '*'
http:
- match:
- uri:
prefix: /oauth2 # Matches all OAuth 2.0 callback paths
name: oauth2
route:
- destination:
host: <oauth2proxy-svc-name> # Replace with the domain name from the previous step
port:
number: 4180 # Default oauth2-proxy listening portDo not use the /oauth2 prefix in routing rules defined by other virtual services. Duplicate prefixes cause routing conflicts.
Step 5: Create an authorization policy
Create an AuthorizationPolicy that applies the custom OIDC authorization service to all requests entering the ingress gateway.
On the ASM instance details page, choose Mesh Security Center > AuthorizationPolicy in the left-side navigation pane. Click Create from YAML.
Select the
istio-systemnamespace and paste the following YAML:
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: oidc
namespace: istio-system
spec:
action: CUSTOM # Delegates authorization to an external service
provider:
name: httpextauth-oidc # Must match the authorization service name from Step 4
rules:
- {} # Matches all requests (no conditions)
selector:
matchLabels:
istio: ingressgateway # Targets the ingress gateway podsThis policy intercepts all requests to the ingress gateway. Every request must pass OIDC authentication before reaching backend applications.
Step 6: Verify SSO
Open
http://<ingress-gateway-ip>:80in a browser. The oauth2-proxy sign-in page appears, which confirms the authorization policy is active.Click Sign in with OpenID Connect. The browser redirects to the Alibaba Cloud IDaaS login page.
Enter the test account credentials created in Step 1 and click Log On. After successful authentication, the browser redirects back to the httpbin application.
In the httpbin UI, click Request inspection, then choose /headers > Try it out > Execute. The response headers include an
Authorizationheader containing a Bearer token (JWT).Copy the JWT value (the string after
Bearer) and decode it at JWT Debugger. The decoded payload contains user information stored in IDaaS, such as email and username. This confirms that ASM verified the token and forwarded the authenticated identity to the backend application.
What's next
Add more applications to SSO: Deploy applications in the mesh and expose them through the same ingress gateway. The AuthorizationPolicy applies to all ingress traffic automatically.
Restrict SSO to specific paths or services: Modify the
rulesfield in the AuthorizationPolicy to target specific paths or services instead of all ingress traffic.Switch to a different OIDC provider: Register a new custom authorization service in the ASM console with the provider's Issuer URL, client ID, and client secret.