All Products
Search
Document Center

Alibaba Cloud Service Mesh:Enable the forced injection of Sidecar security policy for the cluster

Last Updated:Mar 11, 2026

When a Container Service for Kubernetes (ACK) cluster joins a Service Mesh (ASM) instance, each pod needs a sidecar proxy to participate in the mesh. However, automatic sidecar injection is not enabled by default at the namespace level. Without enforcement, pods can deploy without a sidecar, leaving gaps in traffic management and security coverage.

The ASMSidecarInjectionEnforced policy closes this gap. It blocks pod creation or raises alerts when a namespace lacks automatic sidecar injection. This ensures every workload in the mesh runs a sidecar proxy.

How the policy works

ACK uses OPA Gatekeeper as an admission controller for policy governance. After Kubernetes deprecated Pod Security Policy (PSP) in version 1.21, ACK replaced PSP-based controls with Gatekeeper-based policies. These policies add status monitoring, log collection, and log retrieval.

ACK organizes policies into four categories:

CategoryPurpose
InfraEnforce security controls on infrastructure resources
ComplianceMeet Kubernetes compliance standards such as Alibaba Cloud Kubernetes Security Hardening
PSPReplace deprecated PSP resources
K8s-generalApply Alibaba Cloud security best practices to Kubernetes resources

The ASMSidecarInjectionEnforced policy belongs to the Infra category. When enabled, it checks whether automatic sidecar injection is active for the target namespace before allowing pod creation.

Enforcement modes

The policy supports two enforcement modes:

ModeBehaviorUse case
BlockRejects pod creation in non-injected namespacesProduction enforcement after injection is fully configured
AlertAllows pod creation but generates an alertAudit phase to identify namespaces that still need injection

Sidecar injection overview

A sidecar proxy runs as a separate container inside each pod. It intercepts all inbound and outbound HTTP traffic and communicates with the Pilot component on the ASM Istio control plane.

After a cluster joins an ASM instance, namespace-level automatic injection is not enabled by default. Enable injection for each namespace before enabling the enforcement policy.

Important

If you enable the enforcement policy before enabling automatic injection for a namespace, all pod creation in that namespace is blocked (Block mode) or triggers alerts (Alert mode).

Prerequisites

Before you begin, make sure you have:

If you manage security policies as a Resource Access Management (RAM) user, grant the following permissions:

PermissionDescription
cs:DescribePoliciesQuery policies
cs:DescribePoliceDetailsQuery policy details
cs:DescribePolicyGovernanceInClusterQuery policies in a cluster
cs:DescribePolicyInstancesQuery policy instances deployed in a cluster
cs:DescribePolicyInstancesStatusQuery policy instance status in a cluster
cs:DeployPolicyInstanceDeploy a policy instance in a cluster
cs:DeletePolicyInstanceDelete policy instances in a cluster
cs:ModifyPolicyInstanceModify a policy instance in a cluster

For details, see Create a custom RAM policy.

Enable the policy

The following diagram shows the configuration flow:

image

Two methods are available. Choose the one that fits your workflow.

Option 1: Enable from the security policy list

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, find the target cluster and click its name. In the left-side pane, choose Security > Policy Governance.

  3. On the Policy Governance page, install or upgrade the component if prompted.

  4. Click the My Policies tab.

  5. Find ASMSidecarInjectionEnforced in the Policy Name column and click Enable in the Actions column.

  6. Configure the following parameters, then click Create:

    ParameterDescription
    ActionBlock: Reject pod creation that does not comply with the policy. Alert: Allow pod creation but generate an alert.
    Applicable ScopeSelect the namespaces to apply the policy to. Selecting all namespaces is not recommended.
    ParametersLeave blank.

Option 2: Create a policy instance

  1. On the Policy Governance page, click the My Policies tab, then click Create Policy Instance.

  2. In the Create Policy Instance dialog box, configure the following parameters:

    ParameterDescription
    Policy TypeSelect infra. For details, see Predefined security policies of ACK.
    Policy NameSelect ASMSidecarInjectionEnforced.
    ActionBlock: Reject pod creation that does not comply with the policy. Alert: Allow pod creation but generate an alert.
    Applicable ScopeSelect the namespaces to apply the policy to. Selecting all namespaces is not recommended.
    ParametersLeave blank.

Verify the policy

After you enable the policy, test it with a sample application to confirm it behaves as expected.

Test Block mode

This test uses the default namespace with automatic sidecar injection not enabled and Action set to Block.

  1. Deploy the HTTPBin application to the default namespace.

  2. Check the workload status. The pod fails to create because the namespace does not have automatic injection enabled.

    Pod creation blocked

  3. Click the Overview tab. In the Actions within Last 7 Days section, a blocking record appears.

    Blocking records

Test Alert mode

  1. Edit the policy and change Action to Alert.

  2. Redeploy the HTTPBin application.

  3. Check the workload status. The application deploys successfully, but an alert is generated.

    Successful deployment with alert

  4. Click the Overview tab. In the Actions within Last 7 Days section, an alerting record appears.

    Alerting records