Workbench CLI — Use ACK clusters

Updated at:

Use the Workbench command-line interface (CLI) to run clients such as kubectl and Helm on your local machine against Alibaba Cloud Container Service for Kubernetes (ACK) clusters. Traffic reaches the target API server through a Workbench private tunnel, without exposing the cluster to public network access or requiring you to manage kubeconfig credentials manually.

For general installation, credential modes, and management of multiple profiles, see Install and configure Workbench CLI credentials. This document covers only ACK scenarios.

What it does and does not do

  • Does — Obtains a short-lived kubeconfig for the specified cluster, points the client to a local, temporary tunnel address, and provides and refreshes cluster credentials on demand.

  • Does not — Download or install Kubernetes clients, control client output formats, or grant permissions for Kubernetes operations within the cluster. Those permissions are managed through role-based access control (RBAC) on the ACK side.

Quick start

Follow these steps to run a Kubernetes client against an ACK cluster from your local machine.

1. Prerequisites

  • Install Workbench CLI (v1.0.6 or later supports the ACK scenario) and configure your credentials with workbench config. Run workbench version to check the installed version; if it is earlier than v1.0.6, run workbench upgrade.

  • Install the client that you want to use locally, such as kubectl or helm, and make sure that it is in PATH. Workbench does not install it for you.

  • Grant the current Resource Access Management (RAM) identity the minimum permissions for ACK usage: cs:GetClusters, cs:DescribeClusterUserKubeconfig, and ecs-workbench:*. For the complete policy and the command-to-permission mapping, see Permission configuration.

  • Grant the same RAM identity Kubernetes RBAC permissions for the target cluster in the ACK console.

2. Find the cluster ID

List the ACK clusters that the current profile can view:

workbench list ack                     # All regions
workbench list ack -r cn-shanghai      # One region only
workbench list ack --output json       # Includes page_info for scripted pagination

The text output lists the columns CLUSTER_ID NAME REGION TYPE STATE VERSION. If another page is available, a pagination message appears below the table, such as Showing N of T clusters. This message includes a command that you can copy to retrieve the next page.

Parameter Required Default Description
-r / --region No All regions Lists clusters only in the specified region. Does not fall back to the profile region.
--page-number No 1 Page number, starting from 1.
--page-size No 50 Number of clusters per page.

3. Run a client

Run a client command against an ACK cluster:

# Basic usage: the command to run follows --
workbench ack exec --cluster-id c8f1a2b3c4d5e -- kubectl get nodes

# Specify a profile. The region is resolved automatically from the cluster.
workbench ack exec --cluster-id c8f1a2b3c4d5e --profile prod -- kubectl get pods -A

# Helm works the same way
workbench ack exec --cluster-id c8f1a2b3c4d5e -- helm list -A

# Client output is passed through unchanged and can be piped directly
workbench ack exec --cluster-id c8f1a2b3c4d5e -- kubectl get pods -o json | jq -r '.items[].metadata.name'
Parameter Required Default Description
--cluster-id Yes ACK cluster ID.
--profile / -P No Currently active profile The ACK session belongs to this profile. Different profiles do not reuse the same tunnel.
-- <command> Yes The command and its arguments follow --. Workbench does not parse them.

To confirm that the tunnel was established, run workbench session list. The session for the cluster appears in the output with ack in the TYPE column. If the command returns an error instead, see Troubleshooting.

Key behavior

Limits

  • The client must be installed locally. If the client cannot be found, Workbench prompts you to install it and does not create a cloud session. For the error message and exit code, see Troubleshooting.

  • Transferring files 1 MB or larger through kubectl cp / kubectl exec is not supported. Use Object Storage Service (OSS) or another transfer method for these scenarios.

Session and credential lifecycle

  • Sessions are reused and close automatically. Workbench reuses a session for the same profile and cluster. For the idle timeout and the session commands, see Session management.

  • Credentials are never written to disk. The generated kubeconfig is stored at ~/.workbench/run/ack/<session-id>/kubeconfig, with directory permissions 0700 and file permissions 0600, and contains no usable credentials. The entire directory is deleted when the session closes.

  • Cluster credentials live only in daemon memory. The workbench ack credential exec plugin declared in the kubeconfig retrieves them on demand. They are refreshed in memory when less than 5 minutes of validity remain.

Output and exit codes

  • The exit code is the client's exit code. ack exec passes the client exit code through unchanged. Ctrl+C is forwarded to the child process, and a second termination signal forcibly ends it. For the Workbench-specific codes, see Exit codes.

  • --output json affects only Workbench's own error output. It does not wrap or modify client stdout.

Implementation details

  • No region is required. When Workbench first connects to a cluster, the daemon looks up the region by cluster ID. The lookup is not repeated when a session is reused. Any --region or -r value is ignored. If the cluster ID does not exist or the current profile cannot view the cluster, Workbench reports ClusterNotFound and does not create a cloud session.

  • The private cluster API address is used. Workbench sets PrivateIpAddress=true when it obtains the kubeconfig. It then rewrites server to the local listening address on 127.0.0.1 and preserves the original private API server hostname in tls-server-name, so that TLS still validates the actual server.

  • Only one environment variable is replaced for the child process. Workbench inherits the complete parent process environment and replaces only KUBECONFIG with the path of the temporary kubeconfig generated for this session. All other parent process variables, including an existing SecurityToken, remain unchanged. No additional cloud credential environment variables are injected. The parent process and global configuration are unaffected.

Session management

Use the following commands to inspect and close ACK tunnels:

workbench session list                              # List all sessions; ACK sessions have TYPE ack
workbench session close <session-id>                # Close the specified tunnel
workbench session close --all                       # Close all sessions
workbench session stats <session-id>                # ACK sessions only: live throughput sampling
workbench session stats <session-id> --interval 1s --count 10
workbench session stats <session-id> --output json  # NDJSON: one line per sampling interval

Sessions are reused by profile and cluster, and close automatically after 15 minutes of inactivity. After the command ends, the session remains visible in workbench session list, with ack in the TYPE column.

session stats samples an ACK tunnel at each --interval (default: 2s) until you press Ctrl+C, the session ends, or --count samples have been output. The default count of 0 means continuous monitoring. It reads only local daemon counters and does not call cloud APIs.

  • Text output prints the session limits once, followed by sample rows with the columns TIME UP/s DOWN/s THROTTLE BURST STREAMS OPENING WAITING QUEUED REJECTED.

  • THROTTLE is the percentage of the sampling interval spent waiting for the upload rate limiter. WAITING, QUEUED, and REJECTED help assess pressure on stream slots. Limits are shared by the session: all kubectl processes using the same profile and cluster share them.

  • --output json produces newline-delimited JSON (NDJSON). Each line contains up_bytes_per_sec, down_bytes_per_sec, throttle_percent, and a cumulative stats object. When the session is no longer OPEN, a final object containing state and close_reason is output, and the command exits with code 0. After a manual session close, the session record is removed immediately and the command returns exit code 3.

  • An Elastic Compute Service (ECS) session ID results in exit code 2, an unknown session results in 3, and a daemon that is not running results in 6.

Permission configuration

For ACK-only usage, the minimum RAM policy is as follows. No ecs: or swas-open: permissions are required.

{
  "Version": "1",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["ecs-workbench:*"],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": ["cs:GetClusters", "cs:DescribeClusterUserKubeconfig"],
      "Resource": "*"
    }
  ]
}

The following table maps each command or stage to the cloud API that it calls and the RAM permission that it requires:

Command / stage Cloud API RAM permission
list ack CS DescribeClustersV1 cs:GetClusters
ack exec: new session CS DescribeClustersV1 (region lookup) and DescribeClusterUserKubeconfig; Workbench LoginCSCluster cs:GetClusters, cs:DescribeClusterUserKubeconfig, ecs-workbench:*
ack exec: reused session with less than 5 minutes of credential validity remaining CS DescribeClusterUserKubeconfig cs:DescribeClusterUserKubeconfig
ACK session closure (session close, idle cleanup, daemon stop) Workbench EndSessions ecs-workbench:*
session list / session stats / daemon status None; accesses only the local daemon None

Restrict the authorization scope (optional):

  • Restrict cs:DescribeClusterUserKubeconfig to acs:cs:<region>:<account-id>:cluster/<cluster-id>.

  • cs:GetClusters is an account-level cluster discovery permission. Keep the resource as * or acs:cs:*:<account-id>:cluster/*. ack exec also needs this permission to look up the cluster region.

  • If you add a cs:KubeConfigDurationMinutes condition to cs:DescribeClusterUserKubeconfig, allow at least 15 minutes. The CLI requests temporary credentials valid for 15 minutes.

  • Keep the wildcard for ecs-workbench:* for now. LoginCSCluster and EndSessions are not yet listed in the public ECS-Workbench RAM action list. Do not guess individual action names for authorization.

RAM is not RBAC. RAM does not grant permissions for Kubernetes operations within the cluster. If kubectl returns Forbidden, Kubernetes RBAC permissions within the cluster have not been granted. Grant cluster permissions to the RAM identity in the ACK console instead of adding RAM policies.

Common scenarios

The following examples build on the quick start. Use -o wide and -n kube-system to inspect nodes and system components, and helm upgrade --install to deploy or upgrade a release. To run a command against the clusters of another account, use --profile with a profile whose credentials are already configured. In every case, the region is resolved automatically from the cluster.

# View nodes and system components
workbench ack exec --cluster-id c-xxx -- kubectl get nodes -o wide
workbench ack exec --cluster-id c-xxx -- kubectl get pods -n kube-system

# Deploy or upgrade
workbench ack exec --cluster-id c-xxx -- helm upgrade --install myapp ./chart -n prod

# Cross-account: use the prod profile credentials for its clusters; region is resolved automatically
workbench ack exec --cluster-id c-xxx --profile prod -- kubectl get ns

Troubleshooting

The following table lists the errors that you may encounter when you use Workbench CLI with ACK, and how to resolve them:

Error message Resolution
kubectl not found in PATH; install it before using workbench ack exec The client is not installed locally (exit code 127). Install kubectl and retry. Workbench does not download it for you.
ClusterNotFound The cluster ID is incorrect, or the current profile lacks the cs:GetClusters permission for cluster discovery. Verify the cluster ID with workbench list ack or switch to a profile with the required permission.
CredentialRejected / cluster credentials rejected The kubeconfig refresh was rejected because cloud credentials or RAM authorization failed, and the session has closed. Update the profile credentials and ensure that the RAM identity still has cs:DescribeClusterUserKubeconfig permission for the target cluster. Credential expiry can also return the underlying error message directly, such as InvalidAccessKeyId.NotFound, with exit code 4.
ACK session s-xxx disconnected (NetworkLost); re-run the command The tunnel disconnected during command execution, and Workbench wrote this diagnostic to stderr. The message does not change the exit code. Run the command again. If the issue persists, check the reachability and the security groups of the cluster's private API server.
kubectl: Error from server (Forbidden) This is not a RAM permission issue. Grant Kubernetes RBAC permissions within the cluster to the RAM identity in the ACK console.
session stats is only available for ACK sessions An ECS session ID was supplied (exit code 2). Select a session with ack in the TYPE column of workbench session list.
Incomplete download with kubectl cp / unexpected EOF Transferring files 1 MB or larger through kubectl cp / kubectl exec is not supported. Use OSS or another transfer method.
cannot connect to daemon / daemon is not running Run workbench daemon stop and retry.
unknown command "ack" for "workbench", or list ack returns an ECS instance list The CLI version is too old and does not include the ACK subcommand. Run workbench upgrade to upgrade to v1.0.6 or later, and retry.
Invalid cluster state: unavailable (or disconnected, failed) The cluster is not in the running state, so no tunnel can be established. Check the cluster status in the ACK console first (exit code 1).

Debug logs

Enable debug logging

Temporarily enable debug logging to troubleshoot the ACK session connection. After you stop the daemon, the next command automatically starts it again, so the new log level takes effect:

workbench config set log_level debug
workbench daemon stop
workbench ack exec --cluster-id <cluster-id> -- kubectl get nodes
grep -F 'ack ' ~/.workbench/log/daemon.log

CLI ACK debug logs are written to stderr for the current command. Daemon logs are written to ~/.workbench/log/daemon.log. The logs record the cluster, region, session, RequestID, time spent in each stage, temporary kubeconfig path, and file status. They do not record the kubeconfig content, access credentials, complete WebSocket URLs, or Kubernetes client arguments.

Exit codes

The following table lists the exit codes that Workbench CLI returns:

Exit code Meaning
Client exit code ack exec passes through the exit code of clients such as kubectl and helm unchanged.
1 An error of Workbench itself, such as the profile specified by --profile does not exist, or the cluster state is not running.
2 Parameter error, such as ClusterNotFound.
3 Unknown session. Applies to session commands such as session stats.
4 Authentication failure, such as CredentialRejected.
5 Network error.
6 Daemon unreachable.
127 The local client to run does not exist.