Wasm is an effective and portable binary instruction format. You can use Wasm to extend
the data plane of an ASM instance with new features. However, building, deploying,
and running Wasm filters in an ASM instance are complex. This topic shows you how
to use OCI Registry as Storage (ORAS) to simplify Wasm-based ASM instance extension.
Prerequisites
- An ASM instance is created, and a Container Service for Kubernetes (ACK) cluster is
added to the ASM instance. For more information, see Create an ASM instance and Add a cluster to an ASM instance.
Note The version of the ASM instance must be v1.8.3.17-g1399628c-aliyun or later.
- The kubectl client is used to connect to the ASM instance. For more information, see
Use kubectl to connect to an ASM instance.
- An application is deployed in the ACK cluster that is added to the ASM instance. For
more information, see Deploy an application in an ASM instance.
- A virtual service and an ingress gateway are created. For more information, see Define Istio resources.
- A binary Wasm filter file is created and compiled. In this example, the header of
a Wasm filter is added to the response header.
Background information
ASM supports Wasm. You can deploy Wasm filters in the Envoy that is used to manage
clusters on the data plane. This helps you extend the data plane with new features.
ORAS provides registry storage based on the Open Container Initiative (OCI) Artifacts
project. You can use ORAS to simplify the storage process in OCI registries. When
you use Wasm to extend the data plane of an ASM instance with new features, you can
use ORAS to simplify the extension process.
Push a Wasm filter
Use ORAS CLI to push a Wasm filter to an image repository. In this example, Container
Registry Enterprise Edition is used.
- Create an image repository in Container Registry Enterprise Edition and obtain the
username that is used to log on to the image repository. For more information, see
Use a Container Registry Enterprise Edition instance to push and pull images.
- Run the following command to log on to the image repository:
oras login --username=<Username> acree-1-registry.cn-hangzhou.cr.aliyuncs.com
- Run the following command to push a Wasm filter to the image repository:
oras push acree-1-registry.cn-hangzhou.cr.aliyuncs.com/******/asm-test:v0.1 --manifest-config runtime-config.json:application/vnd.module.wasm.config.v1+json example-filter.wasm:application/vnd.module.wasm.content.layer.v1+wasm
- View the pushed Wasm filter in the Container Registry console.
- Log on to the Container Registry console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Instances.
- On the Instances page, click the required Container Registry Enterprise Edition instance.
- On the management page of the Container Registry Enterprise Edition instance, choose
in the left-side navigation pane.
- On the Repositories page, click the name of the image repository to which you want to log on.
- In the left-side navigation pane of the repository information page, click Tags. On the page that appears, you can view the pushed Wasm filter.
Enable Wasm-based ASM instance extension
Wasm-based ASM instance extension in the ASM console
- Log on to the ASM console.
- In the left-side navigation pane, choose .
- On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM
instance or click Manage in the Actions column.
- On the details page of the ASM instance, choose in the left-side navigation pane. On the Basic Information page, click Settings.
- In the Settings Update panel, select Enable Wasm-based ASM Instance Extension in the Data Plane Extension section and click OK.
Note To disable Wasm-based ASM instance extension, clear Enable Wasm-based ASM Instance Extension.
Use Alibaba Cloud CLI to enable Wasm-based ASM instance extension
You can use Alibaba Cloud CLI to enable Wasm-based ASM instance extension. Run the
following command to enable Wasm-based ASM instance extension:
aliyun servicemesh UpdateMeshFeature --ServiceMeshId=xxxx --WebAssemblyFilterEnabled=true
Run the following command to disable Wasm-based ASM instance extension:
aliyun servicemesh UpdateMeshFeature --ServiceMeshId=xxxx --WebAssemblyFilterEnabled=false
Use the Wasm filter in ASM
ASM provides ASMFilterDeployment resources and related controllers. A controller listens
to the status of its ASMFilterDeployment resource and performs the following operations:
- Creates an Envoy filter and pushes the Envoy filter to the control plane.
- Pulls the Wasm filter image from the image repository and mounts the image to the
pod that is controlled by the specified workload.
Process
- Enable Wasm-based ASM instance extension. After that, the ASM instance automatically
deploys an asmwasm-controller DaemonSet to the ACK cluster that is added to the ASM
instance.
- The asmwasm-controller DaemonSet listens to a ConfigMap. The ConfigMap stores the
address of the image repository from which the Wasm filter image is to be pulled.
- If authorization and authentication are required, the asmwasm-controller DaemonSet
obtains a secret based on the pullSecret parameter.
- The asmwasm-controller DaemonSet calls the ORAS operation to dynamically pull the
Wasm filter from the OCI registry.
- The asmwasm-controller DaemonSet uses a hostPath volume to mount the Wasm filter.
Therefore, the pulled Wasm filter is stored in the corresponding nodes of the ACK
cluster.

Procedure
- Run the following command to enable Wasm-based ASM instance extension:
aliyun servicemesh UpdateMeshFeature --ServiceMeshId=xxxxxx --WebAssemblyFilterEnabled=true
- Create a secret for the ACK cluster to access the image repository.
For more information about the secrets of ACK clusters, see
Secret.
- Create a myconfig.json file that contains the following code:
{
"auths":{
"**********.cn-hangzhou.cr.aliyuncs.com":{
"username":"*****username*****",
"password":"*****password*****"
}
}
}
**********.cn-hangzhou.cr.aliyuncs.com
: the address of the image repository.
username
: the username of the image repository.
password
: the password of the image repository.
- Run the following command to create a secret:
Note The secret must be named asmwasm-cache and belong to the istio-system namespace.
kubectl create secret generic asmwasm-cache -n istio-system --from-file=.dockerconfigjson=myconfig.json --type=kubernetes.io/dockerconfigjson
- Deploy an ASMFilterDeployment resource.
- Create a filter.yaml file that contains the following code:
apiVersion: istio.alibabacloud.com/v1beta1
kind: ASMFilterDeployment
metadata:
name: details-v1-wasmfiltersample
spec:
workload:
kind: Deployment
labels:
app: details
version: v1
filter:
patchContext: 'SIDECAR_INBOUND'
parameters: '{"name":"hello","value":"hello details"}'
image: 'acree-1-registry.cn-hangzhou.cr.aliyuncs.com/asm/asm-test:v0.1'
rootID: 'my_root_id'
id: 'details-v1-wasmfiltersample.default'
- Parameters in
workload
:
kind
: the type of the workload.
labels
: the filter conditions.
- Parameters in
filter
:
patchContext
: the context that takes effect.
parameters
: the parameters that are required to run the Wasm filter.
image
: the address of the image repository to which the Wasm filter is pushed.
rootID
: the root ID of the Wasm filter.
id
: the unique ID of the Wasm filter.
- Run the following command to deploy the ASMFilterDeployment resource:
kubectl apply -f filter.yaml
After the ASMFilterDeployment resource is deployed, ASM automatically generates an
Envoy filter. In the Envoy filter, the match parameter defines an envoy.router filter,
and the patch parameter defines an INSERT_BEFORE operation.
- match parameter

- patch parameter

- Check the definition of the workload to which the Wasm filter is mounted.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
...
spec:
...
template:
metadata:
annotations:
sidecar.istio.io/userVolume: '[{"name":"wasmfilters-dir","hostPath":{"path":"/var/local/lib/wasm-filters"}}]'
sidecar.istio.io/userVolumeMount: '[{"mountPath":"/var/local/lib/wasm-filters","name":"wasmfilters-dir"}]'
The preceding definition indicates that the Wasm filter is mounted to the istio-proxy
container of the destination application by using a hostPath volume.
Check whether the Wasm filter takes effect
Run the following command to log on to the istio-proxy container of the productpage
pod and send a request to access the details service:
kubectl exec -ti deploy/productpage-v1 -c istio-proxy -- curl -v http://details:9080/details/123
Expected output:
* Trying 172.21.9.191...
* TCP_NODELAY set
* Connected to details (172.21.9.191) port 9080 (#0)
> GET /details/123 HTTP/1.1
> Host: details:9080
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
xxxxxxx
< resp-header-demo: added by our filter
xxxxx
* Connection #0 to host details left intact
xxxxx
The response indicates that the header of the Wasm filter is added to the response
header.