All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure an ASM security policy to implement custom authorization

Last Updated:Jan 23, 2024

When you need to customize an access control policy based on your business requirements, you can configure a Service Mesh (ASM) security policy to implement custom authorization. That is, requests are forwarded to a custom authorization service that you specify. The custom authorization service authenticates the requests. This way, you can implement complex authentication logic, reduce development and maintenance costs, and improve development efficiency.

Prerequisites

Procedure

  1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose Mesh Security Center > ASMSecurityPolicy.

  3. On the ASMSecurityPolicy page, click Create. In the Create ASMSecurityPolicy dialog box, click Custom Authorization Service and then click OK.

  4. In the Custom Authorization Service Configuration step of the CreateCustom Authorization Service configuration wizard, click the Custom authorization service (HTTP or gRPC protocol) implemented based on envoy.ext_authz tab, configure the parameters, and then click Next.

    The following figure shows an example of how to configure the parameters. For more information about the parameters, see Implement custom authorization by using the HTTP protocol.基本信息在鉴权请求中携带header鉴权通过/失败时覆盖Header

  5. In the Workload and Match Rules step of the configuration wizard, click Add Workload Group. In the New Workload Group dialog box, configure the parameters and click OK.

    The following table describes how to configure the parameters in this example.

    Parameter

    Description

    Workload Group Name

    Set the name to test-policy.

    Workload List

    1. Click Add Workload.

    2. In the Add Workload dialog box, select Workload Scope. Set the Namespace parameter to default and the Workload Type parameter to Service.

    3. In the Select workloads box, select productpage, click the 添加 icon to add the workload to the selected box, and then click OK.

    Match Rule List

    Set the Match Mode parameter to The selected request must be authenticated. Set Matching Rules to Custom Matching Rules. Turn on the Path switch and set the parameter to /productpage.

    新建工作负载组

    In the Complete step of the configuration wizard, the "ASMSecurityPolicy Creation successfully" message appears, indicating that the ASM security policy is created. You can click YAML to view the created resources, or click Complete to go back to the ASMSecurityPolicy page to view the created security policy.

  6. Check whether the custom authorization configuration takes effect.

    1. Run the following command to initiate a request with the x-ext-authz: allow header to access the productpage service:

      curl -I -H "x-ext-authz: allow" http://${IP address of the ingress gateway}/productpage

      Expected output:

      HTTP/1.1 200 OK
      content-type: text/html; charset=utf-8
      content-length: 5288
      server: istio-envoy
      date: Tue, 17 Jan 2023 07:53:14 GMT
      x-envoy-upstream-service-time: 20

      The output indicates that custom authorization is triggered and the authentication is successful.

    2. Run the following command to initiate a request with the x-ext-authz: deny header to access the productpage service:

      curl -I -H "x-ext-authz: deny" http://${IP address of the ingress gateway}/productpage

      Expected output:

      HTTP/1.1 403 Forbidden
      x-ext-authz-check-result: denied
      date: Tue, 17 Jan 2023 07:55:27 GMT
      server: istio-envoy
      x-envoy-upstream-service-time: 2
      transfer-encoding: chunked

      The output indicates that custom authorization is triggered but the authentication fails.

    The preceding results indicate that the custom authorization configuration takes effect.

References