Agent Sandbox network planning and scaling

Updated at:

Learn about the network partition architecture of Agent Sandbox, and how to scale the sandbox network by adding vSwitches and security groups.

Background information

Agent Sandbox sandboxes run user-submitted code and are untrusted by default. To prevent sandboxes from accessing internal cluster components or other tenants, Agent Sandbox divides cluster workloads into three network partitions by trust level (managed-side and unmanaged-side system components, and sandbox compute). (Recommended) Use dedicated vSwitches and security groups to isolate sandboxes.

An advanced security group supports a maximum of 65,536 associated elastic network interfaces (ENIs). If a single security group nears this limit, or a vSwitch runs out of available IP addresses, create a new set of vSwitches and security groups for the additional sandboxes.

Network partition

Trust level

Typical components

vSwitch configuration

Security group configuration

Managed-side system components

High

Kube API Server, Cloud Controller Manager, ack-agent-sandbox-controller, ack-agent-identity

Control plane vSwitch

Control plane security group

Unmanaged-side system components

Medium

ack-sandbox-manager

Control plane vSwitch 

Control plane security group

Sandbox compute

Untrusted

Sandbox Pod

(Recommended) Configure a dedicated vSwitch for sandboxes

(Recommended) Configure a dedicated advanced security group for sandboxes

Important

In Agent Sandbox scenarios, assign a dedicated security group to sandboxes to provide network-layer fallback isolation. To achieve defense in depth, also combine GlobalTrafficPolicy Ingress rules with inbound security group rules to prevent sandboxes from accessing non-sandbox workloads. For information about how to use GlobalTrafficPolicy, see Manage agent network access with TrafficPolicy.

Create a vSwitch

  1. In the , click the name of the target cluster to go to the Cluster Information page.

  2. On the Cluster Information tab, in the Network section, click the VPC name to go to the VPC console.

  3. In the VPC console, switch to the Resource Management tab, and click Add to add a vSwitch. For instructions, see Create a VPC and a vSwitch.

    • (Recommended) Create at least one vSwitch in each zone to ensure high availability across zones.

    • Assign a CIDR block allocated sequentially after the existing CIDR blocks, and avoid blocks that are already in use.

In the VPC console, choose vSwitch in the left-side navigation pane and check the remaining Available IPv4 before they run out.

Add an SNAT entry for NAT

A newly created vSwitch is not automatically added to the SNAT table of the NAT gateway. If you do not add an SNAT entry, pods on the vSwitch cannot access the public network (image pulls and calls to external APIs time out).

  1. Go to the Cluster Information page of the target cluster. On the Cluster Information tab, in the Network section, click the name of the NAT gateway to go to the NAT gateway console.

  2. In the NAT gateway console, switch to the SNAT tab, and for the new vSwitch, click Create SNAT Entry and bind the Elastic IP Address (EIP) of the NAT gateway. For instructions, see Create an SNAT entry .

Reuse or create a sandbox security group

  1. In the Security Group console , check whether existing sandbox security groups can be reused.

    Based on security group best practices, keep the IP usage of a single security group at 80% or lower (approximately 52,000 IP addresses).
  2. In the Security Group console, configure the allow rules one at a time: sandbox outbound rules, sandbox inbound rules, and target-side inbound rules. For instructions, see Security groups.

    The intra-group connectivity policy of an advanced security group is internal isolation, which means that instances in the same group cannot communicate with each other by default.

    Query the CIDR blocks of the components mentioned below in the following ways:

    • Cluster-managed components

      • ACS/ACK: Go to the Cluster Information page of the target cluster. On the Cluster Information tab, in the Network section, view the Control Plane vSwitch information.

    • Non-cluster-managed components

      • ACS: Go to the Cluster Information page of the target cluster. On the Cluster Information tab, in the Network section, view the Control Plane vSwitch information.

      • ACK: Go to the Node Pools page of the target cluster. Query the vSwitch information of the node pool.

    Inbound rules of the sandbox security group

    Source

    Protocol/port

    Purpose

    Policy

    CIDR blocks of cluster-managed components

    TCP/9090, TCP/9100, TCP/10254

    Prometheus / node-exporter / Ingress metrics

    Allow

    TCP/49983

    ack-agent-sandbox-controller

    Allow

    ICMP

    Health checks

    Allow

    CIDR blocks of non-cluster-managed components

    TCP/49983, TCP/49999

    sandbox-manager, sandbox-gateway → sandbox pods (envd / jupyter)

    Allow

    Outbound rules of the sandbox security group

    Destination

    Protocol/port

    Purpose

    Policy

    Priority

    100.100.100.200/32

    TCP/80, TCP/443

    ECS metadata service

    Deny

    1

    CIDR blocks of cluster-managed components

    TCP/6443

    API Server

    Allow

    1

    TCP/9082

    Poseidon managed components

    Allow

    1

    TCP/53, UDP/53

    Internal DNS (PrivateZone) / upstream DNS

    Allow

    1

    TCP/49983

    Services provided by the ack-agent-sandbox-controller component

    Allow

    1

    TCP/8443

    Services provided by the ack-agent-identity component

    Allow

    1

    CIDR blocks of cluster-managed or non-cluster-managed components

    TCP/53, UDP/53

    Sandboxes access CoreDNS pods

    Allow

    1

    The vSwitch CIDR block where the ack-sandbox-manager component resides

    TCP/15008

    TCP/15012

    The enhanced-traffic-policy network proxy connects to the gateway

    Allow

    1

    Addresses of services such as OSS and NAS

    ALL

    Access addresses of the ossfs and NAS services

    Allow

    1

    10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16

    ALL

    Private networks (prevents sandboxes from probing the internal network)

    Deny

    10

    0.0.0.0/0

    ALL

    Public network egress

    Open as needed.

    Allow

    20

    For security group rules, a smaller priority value indicates a higher priority. When rules have the same priority, deny rules take effect first.

    Inbound rules of the target-side security group

    After you add a vSwitch, add inbound rules to the security groups of the target components that sandbox pods access, such as CoreDNS and API Server. The rules must allow the CIDR block of the new vSwitch.

    When enhanced-traffic-policy is enabled, the security group of the target component must allow the CIDR block of the new sandbox vSwitch to access TCP/15008 and TCP/15012. The outbound rules of the sandbox security group must also allow the corresponding destinations and ports.

    Source

    Protocol/port

    Purpose

    Required

    CIDR block of the new sandbox vSwitch

    TCP/53, UDP/53

    Optional. Sandboxes access CoreDNS for domain name resolution.

    No

    TCP/6443

    ACS instances access the cluster API Server

    Yes

    TCP/9082

    ACS instances access the Poseidon managed components

    No

    TCP/15008

    TCP/15012

    The enhanced-traffic-policy network proxy connects to the gateway

    Required when enhanced-traffic-policy is enabled

Configure vSwitches and security groups for pods

ACS cluster

Add the configuration in the metadata.annotations of the pod, or in the spec.template.metadata.annotations of its workload (such as SandboxSet), as shown in the following example:

After the configuration is changed, the vSwitch and security group associated with an already allocated sandbox do not change. The change takes effect only after the sandbox is recreated.
apiVersion: agents.kruise.io/v1alpha1
kind: SandboxSet
metadata:
  name: code-interpreter
  namespace: default
spec:
  template:
    metadata:
      annotations:                       
        # The vSwitch ID. Separate multiple IDs with commas (,)
        network.alibabacloud.com/vswitch-ids: "vsw-uf6h*********oy7n,vsw-uf6vx********9c"
        # The security group ID. Separate multiple IDs with commas (,)
        network.alibabacloud.com/security-group-ids: "sg-uf6g**********i0dn"
 # ...

ACK cluster

ECS compute

In an ACK cluster, the vSwitch and security group of sandbox pods that run on self-managed nodes (ECS) are managed by Terway. The following two configuration granularities are supported:

After you modify eni-config, the changes take effect only for newly created ENIs. The ENIs of existing nodes are not affected.
  • Cluster-level eni-config (ConfigMap): Edit the eni-config ConfigMap in the kube-system namespace. In eni_conf, append the new vSwitch ID to the vswitches field, and change the security_group field to the ID of the sandbox security group.

    This method applies when all pods in the same node pool share a vSwitch and a security group.

  • Node-level network configuration: Use the terway-config label of a node pool to associate different eni-config instances, so that different node pools use different vSwitches and security groups.

    This method applies when different sandbox groups are distributed across different node pools. For instructions, see Node-level network configuration.

ACS compute

Sandbox pods that run on ACS compute do not go through Terway. Their vSwitches and security groups are configured in the same way as in an ACS cluster.

Adjust TrafficPolicy / NetworkPolicy

After scaling, check whether the rules of the existing TrafficPolicy (apiVersion: network.alibabacloud.com/v1alpha1) cover the new CIDR blocks. For configuration details, see Manage agent network access with TrafficPolicy and Manage enhanced egress traffic for Agent Sandbox.

Verify network connectivity

After scaling is complete, use a sandbox pod or a temporary test pod to verify network connectivity item by item.

Verify that the pod IP address falls within the new CIDR block

Run hostname -i in the pod and confirm that the IP address is within the CIDR range of the new vSwitch.

Verify public network access

Run the following command in the sandbox pod:

curl https://httpbin.org/ip

If the NAT EIP is returned, the SNAT configuration is correct. If the request times out, check whether an SNAT entry has been added for the new vSwitch, and whether the outbound rules of the sandbox security group allow TCP/443.

Verify DNS resolution

Run the following command in the sandbox pod:

# Query the domain name of a service inside the cluster
getent hosts kubernetes.default.svc.cluster.local

If resolution fails, check whether the outbound rules of the sandbox security group allow TCP/53 and UDP/53. Also check whether the security group of the CoreDNS component allows inbound access on port 53 from the new CIDR block.

References