OpenID Connect (OIDC) is an identity authentication and authorization protocol built on OAuth 2.0, primarily used to implement single sign-on (SSO). By configuring OIDC SSO in an ASM security policy, you can use Alibaba Cloud IDaaS or other OIDC-compliant identity providers (IdPs) to enable users to log in once to access multiple applications. This approach works without modifying the applications themselves, which enhances application security and simplifies development and management.
Prerequisites
An application is deployed in the cluster that is added to the ASM instance.
-
You have deployed an ingress gateway and obtained its address.
-
You have created a gateway rule and a virtual service to ensure the following paths are accessible. For more information, see Steps 1 to 3 in Use Istio resources to route traffic between versions.
http://${GATEWAY_ADDRESS}/productpage http://${GATEWAY_ADDRESS}/api/v1/products/1 http://${GATEWAY_ADDRESS}/static/jquery.min.js -
You have configured an identity provider (IdP). For instructions, see Step 1 and Step 2 in Integrate ASM with Alibaba Cloud IDaaS to enable SSO for applications in the service mesh.
After the IdP is configured, you will obtain the following information, which is needed for the configuration in Step5.
redirect uri: http://${GATEWAY_ADDRESS}/oauth2/callback issuer: https://eiam-api-cn-hangzhou.aliyuncs.com/v2/idaas_tbn25osdlmz6gtqfq3j2pz****/app_ml5tzapsl7zmfo53wb3nwk****/oidc client id: app_ml5tzapsl7zmfo53wb3nwk**** client secret: CSCfHeZ1nyvfMWyKHtE8ZRdif7j89dv9CvmJLurtGC****
Procedure
This topic uses an IdP from Alibaba Cloud IDaaS as an example. If you use a self-managed OIDC service, see Integrate ASM with Keycloak to enable SSO for applications in the service mesh.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the ASMSecurityPolicy page, click Create.
-
In the Create ASMSecurityPolicy dialog box, click OIDC Single Sign-On, and then click OK.
-
In the OIDC Config wizard, configure the parameters and click Next.
The following table describes the parameters for this example.
Parameter
Description
ASMSecurityPolicyName
Set the name to test-oidc.
Redirect address
You can select Use ingressgateway IP address or Customized Domain. In this example, select Use ingressgateway IP address, and then select http and ingressgateway.
Callback Address
The redirect URI.
OIDC Issuer URL
The URL that identifies and validates the OIDC provider.
Client ID
The client ID provided by the IdP.
Client Secret
The client secret provided by the IdP.
Cookie Secret
A seed for secure cookies. Base64 encoding is supported.
Cookie Expire
The cookie's validity duration. A value of 0 indicates that the cookie never expires.
Cookie refresh interval
The interval at which the cookie is refreshed. A value of 0 disables refresh.
Scopes
Specify the scopes to retrieve. The specified scopes must be supported by the issuer.
For more information about scopes, see Integrate ASM with Alibaba Cloud IDaaS to enable SSO for applications in the service mesh.
In this example, set Cookie expiration to
3600s, set Cookie refresh interval to600s, and select openid and phone for Scopes. -
In the Workload and Match Rules wizard, click Add Workload Group. In the New Workload Group dialog box, configure the parameters, click OK, and then click Submit.
The following table describes the parameters for this example.
Parameter
Description
Workload Group Name
Set the name to test-policy.
Workload List
By default, the gateway configured for the Redirect address in the previous step is selected and cannot be modified. To select a different workload, return to the OIDC Config wizard and modify the Redirect address information.
NoteIf you selected Customized Domain for Redirect address in the OIDC Config wizard, perform the following steps:
-
In the New Workload Group dialog box, click Add Workload, and select Gateway Scope.
-
In the Select workloads section, select the target workload, click the
icon to move it to the selected area, and then click OK.
Match Rule List
The Match Mode has two options:
-
Auth If Matched: Requires authentication for requests that match the specified rules.
-
Bypass Auth If Matched: Requests that match the rules can be accessed without authentication.
In this example, set Match Mode to Auth If Matched and Match Mode to Custom Matching Rules. Then, click Add Match Rule to add rules that require OIDC authentication for paths starting with /static and /api.
-
Rule 1: Enable Path and set the value to /static/*.
-
Rule 2: Enable Path and set the value to /api/*.
After the policy is created, the Complete step shows that the ASM security policy was created successfully. You can click View YAML to view the created resources, or click Complete to return to the ASMSecurityPolicy page and view the new security policy.
-
-
Verify the OIDC SSO configuration.
-
In a web browser, access the following URLs in order.
http://${GATEWAY_ADDRESS}/productpage http://${GATEWAY_ADDRESS}/api/v1/products/1 http://${GATEWAY_ADDRESS}/static/jquery.min.jsThe following results confirm that the OIDC SSO configuration is working:
-
Requests to paths that start with
/productpagecan be accessed without authentication. When you access the productpage of the BookInfo sample application, a summary of the book The Comedy of Errors is displayed. -
Requests to paths that start with
/apiand/staticrequire authentication. When accessing these paths, you are redirected to the Alibaba Cloud IDaaS logon page. You must enter your credentials in the Account, phone, or email and Password text boxes and then click Log On to authenticate.
-
-
Modify the OIDC SSO configuration.
-
On the ASMSecurityPolicy page, find the target OIDC security policy and click edit in the Operator column.
-
In the OIDC Config wizard, click Next.
-
In the Workload and Match Rules wizard, find the target workload group and click edit in the Operator column. Modify the configurations, click OK, and then click Submit.
The following table describes the parameters for this example.
Parameter
Description
Match Mode
Select Bypass Auth If Matched.
Matching Rules
Click Add Match Rule to configure the following rules. This configuration allows requests to paths starting with /productpage and /static to bypass OIDC authentication.
-
Rule 1: Enable Path and set the value to /productpage.
-
Rule 2: Enable Path and set the value to /static/*.
-
-
-
To verify the changes, open a new incognito window in your browser and access the following URLs.
http://${GATEWAY_ADDRESS}/productpage http://${GATEWAY_ADDRESS}/api/v1/products/1 http://${GATEWAY_ADDRESS}/static/jquery.min.jsThe following results confirm the modified configuration is working.
-
Requests to paths that start with
/productpageand/staticcan be accessed without authentication. -
Requests to paths that start with
/apirequire authentication.
-
-
Related documents
-
For more information about OIDC application settings, such as API access, key rotation, IDaaS support for different OIDC modes, and configurations on the IDaaS and application sides, see Basic configurations, General instructions for single sign-on, OIDC SSO configurations, and OIDC id_token extension value specifications.
-
After logging on to an application with IDaaS SSO, you can initiate a global logout from the application to end the main IDaaS session. This process is called Single Log-Out (SLO). For more information, see Single Log-Out (SLO).