Alibaba Cloud MSE cloud-native gateway authentication

Updated at:

Configure Alibaba Cloud Microservices Engine (MSE) in IDaaS to enable MSE gateway authentication and authorization. Users must complete identity authentication before they can access the addresses that you specify in MSE.

image.png

To simplify configuration, IDaaS provides a pre-integrated MSE application template. Administrators only need to create an MSE application in IDaaS and complete the configuration in MSE based on the OpenID Connect (OIDC) protocol.

Application overview

Microservices Engine (MSE) provides a registry and configuration center and distributed coordination capabilities for mainstream open source microservice projects, with native support for Nacos, ZooKeeper, and Eureka. It also provides a cloud-native gateway, with native support for Ingress and Envoy, and microservice governance, with native support for Spring Cloud, Dubbo, and Sentinel, in compliance with the OpenSergo service governance specification.

Procedure

1. Create an MSE application

  1. Log on to the IDaaS console.

  2. Select an IDaaS instance and, in the Actions column, click Console.

  3. Go to Applications > Add Application > Application Marketplace, search for the Alibaba Cloud - MSE cloud-native gateway. Click Add Application.

  1. Confirm the application name to complete the addition. You are then automatically redirected to Single Sign-On Configuration in application management.

  1. Fill in the form.

  • Form parameters:

    • Grant Types remains unchanged. Select only Authorization Code.

      • Make sure that PKCE is not selected.

      • Logon Redirect URI: Set this parameter to the fixed value <MSE gateway access address>+/oauth2/callback. For example, if the MSE access address is http://a.example.com, the URI must be http://a.example.com/oauth2/callback. Enter the same URI in the Redirect URL field of the MSE gateway authentication and authorization settings. The values of the two fields must be consistent.

    • Scope can temporarily be set to All Users Can Access. To specify the IDaaS accounts that can access the application, see Identity as a Service:Authorization for configuration instructions.

  1. Click Save to complete the application configuration.

  2. You also need to copy several values to enter in MSE during the subsequent configuration.

  • Field parameters:

    • Issuer: Get this value from the application configuration information below.

    • client_id: Get this value from the General Configuration tab on the application management page.

    • client_secret: Get this value from the General Configuration tab on the application management page.

You have completed the IDaaS configuration. Next, go to the MSE console to enable authentication.

2. Configure gateway authentication and authorization in MSE

The MSE configuration consists of the following four steps. Because caching is involved, some configuration changes may take 3 to 5 minutes to take effect.

Enable an Internet NAT gateway

To implement gateway authentication, MSE must communicate with IDaaS. Therefore, make sure that the VPC where your MSE is located has outbound public network access. Without this capability, MSE may use the last cached record in the system by default when it initiates an authentication request, and the request cannot succeed.

Go to the Alibaba Cloud VPC Internet NAT Gateway console to create an Internet NAT gateway and make sure that outbound public network access works properly.

Go to gateway management

Log on to the Alibaba Cloud Microservices Engine (MSE) console.

In the left-side navigation pane, go to Cloud-native Gateway > Gateways.

On the gateway for which you want to enable authentication and authorization, click the gateway name to open the management page. If you have not created a gateway, you can create one to test the authentication configuration.

Create a test route (optional)

For easier testing, first add a test route in the MSE gateway so that you can quickly experience the full gateway authentication capability.

If you already have a route, you can skip this step. In the next step, enter the route address in the blacklist to enable protection.

Configure a mock route

For the configuration procedure, see the MSE documentation: Manage MSE Nacos services with a cloud-native gateway.

After the configuration is complete, you can use the /mock address in the subsequent steps to test the gateway authentication configuration.

Configure a local hosts file

For security reasons, the MSE authentication flow restricts access that uses an IP address as the callback address.

If your MSE does not have a domain name, configure your local hosts file in the subsequent steps and enter the mapped domain name in the MSE and IDaaS forms to avoid entering an IP address.

Assume that the public ingress address of your MSE gateway is 47.96.xxx.xxx. Add the following line to the local hosts file on your device:

47.96.xxx.xxx  a.example.com

Use a.example.com instead of the public IP address of the MSE gateway. In IDaaS, set the Logon Redirect URI of the application to http://a.example.com/oauth2/callback, and set the Redirect URL in the gateway authentication and authorization settings to the same value.

2.4 Configure authentication and authorization

Next, enable the MSE authentication and authorization mechanism.

  1. In the left-side navigation pane of the gateway management page, go to Security Capabilities and select Authentication and Authorization.

  2. Click Create Authentication and fill in the form that appears.

Field name

Description

Authentication Name

Enter a custom name.

Authentication Type

Select the OIDC type. The options also include IDaaS, which corresponds to an earlier version of IDaaS. If you are a customer of the new version of IDaaS, select the OIDC type.

Issuer

Copy it from IDaaS application management.

Redirect URL

If you configured a hosts file in the previous step, enter http://a.example.com/oauth2/callback. Alternatively, enter the public domain name of the MSE gateway.

This address cannot be an IP address. It must be a domain name.

Client-ID

Copy it from IDaaS application management.

Client-Secret

Copy it from IDaaS application management.

Cookie-Domain

If you configured a hosts file in the previous step, enter a.example.com. Alternatively, enter the public domain name of the MSE gateway.

Scope

Set it to the fixed value openid.

Authorization

For testing, first select blacklist mode, which means that only explicitly specified paths require authentication.

Click Add Rule Condition and specify that access to the /mock address requires authentication.

  1. After the authentication is created, click Enable.

  2. Configure the oauth2-proxy route. After you enable gateway authentication and authorization, MSE automatically creates a companion OIDC route to enable the authorization callback.

  3. In the left-side menu, go to Route Configuration and find the oauth2-proxy route that is in the Unpublished state.

  4. On the route, click Edit, click Next without making changes, and then click Save and Publish to complete the route configuration update.

You have completed all the configuration and can now test the authentication result.

3. Test access

1. Access address

In a browser, open the http://a.example.com/mock address or the address that you configured in the preceding steps and that is protected by gateway authentication.

MSE detects that the request requires IDaaS authentication. If you have not logged on to IDaaS, you are automatically redirected to the IDaaS logon page.

The IDaaS logon page is displayed and supports the following logon methods:

  • Log on with an account name, mobile phone number, or email address plus a password.

  • Log on with an SMS verification code.

  • Log on with DingTalk.

  • Log on with AD.

2. Authenticate

You can use one of the multiple logon methods supported and configured in IDaaS, including SMS verification codes, DingTalk QR code scanning, and AD identity logon. Administrators can also enable multi-factor authentication (MFA) in IDaaS to strengthen authentication security.

3. Authentication succeeds

After logon, the browser returns to the address that you just tried to access and displays the result, which indicates that authentication succeeded.

{
    "code": 200,
    "data": {
        "message": "ok"
    },
    "HttpStatusCode": 200,
    "successResponse": 200
}