wardn exec
Open a terminal, or run one command, in a pod of a deployment from your own terminal, under the same rules as the web app's Terminal.
wardn exec opens a shell in a pod of a deployment, or runs a single command there, and connects it to your terminal. It is the CLI's twin of the web app's Terminal: the same permission, the same checks, the same Activity entries and the same recording. Use it for the quick look inside a running container that logs and the diff cannot give you. Set up the CLI first (CLI).
You name a deployment, not a cluster or a pod, because that is what Wardn's permissions attach to. Wardn opens the session in the deployment's namespace, as the deployment's own service account, and refuses any pod that does not belong to it.
Exec is the most powerful thing Wardn lets a person do: it runs arbitrary code inside a workload, next to its secrets. It is off until someone turns it on for a cluster, nobody holds the permission by default, and every session is attributed to one person and recorded in Activity. Read what you need before you ask for it.
Usage
wardn exec <deployment> [pod] [-c <container>] [--reason <text>] [-- <command> [args...]]| Argument | Meaning |
|---|---|
<deployment> | Required. The deployment's name or id. A name must match exactly. |
[pod] | The pod's name. Leave it out to use a running pod of the deployment. |
-- <command> [args...] | The command to run. Everything after -- goes to the container as is. Leave it out to open /bin/sh with a terminal. |
Put the flags before the --.
Flags
| Flag | Default | Meaning |
|---|---|---|
-c, --container | the pod's default container | The container to run in. |
--cluster | found for you | The id of the cluster, for a deployment that runs on several. See Which pod and cluster. |
--reason | none | Why you need it, 10 to 500 characters. Required on a production-tier cluster. It goes in the Activity entry and on the session. |
-t, --tty | false | Allocate a terminal. Always on for the default shell. |
-i, --stdin | true | Send your standard input to the command. --stdin=false sends none. |
--api, --token | The global flags. |
Examples
wardn exec checkout --reason "Investigating the stuck checkout queue, ticket 4821"Opens /bin/sh with a terminal in a running pod of checkout. Type exit, or press Ctrl-D, to end the session. Your terminal is put in raw mode while it runs and its size is passed on, so full-screen programs work, and restored when the session ends.
What you need
Every one of these has to hold, or the session is refused before it opens. The message says which.
| Need | Detail |
|---|---|
| Deploy access, or a name on the list | You can manage the deployment (you made it, own it with your team, or were given deploy rights on it, its cluster or its environment, or you are an Owner). If the environment is set to Named people only, you need pod:exec granted by name instead (Terminal). |
| A token that names it | An API token never gets a terminal from deploying: it may use pod:exec only if its ceiling lists it by name, and only for its owner. Agents and service accounts never get one. |
| The cluster's exec switch on | The cluster's operator setting Open terminals in pods. It is off by default; turning it on needs cluster:exec and is recorded in Activity. The cluster's operator must be connected, and new enough to support exec. |
| A reason on production | On a production-tier cluster, --reason is required. |
| Kubernetes rights for the service account | The deployment's service account wardn-deployer, in the deployment's namespace, needs the Role below. Kubernetes checks it, not Wardn. Without it the session ends with the API server's message. Granting it is the cluster owner's decision, namespace by namespace. |
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata: {name: wardn-exec, namespace: shop}
rules:
- apiGroups: [""]
resources: [pods]
verbs: [get]
- apiGroups: [""]
resources: [pods/exec]
verbs: [create]
- apiGroups: [apps]
resources: [replicasets]
verbs: [get]
- apiGroups: [batch]
resources: [jobs]
verbs: [get]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata: {name: wardn-exec, namespace: shop}
roleRef: {apiGroup: rbac.authorization.k8s.io, kind: Role, name: wardn-exec}
subjects:
- {kind: ServiceAccount, name: wardn-deployer, namespace: shop}The replicasets and jobs rules let Wardn walk a pod up to the deployment's own objects, to confirm the pod is theirs. Wardn also refuses a terminal in a pull request preview, in the system namespaces (kube-system, kube-public, kube-node-lease) and in the operator's own namespace, and in a pod that is not owned by one of the deployment's objects. Check that you can manage the deployment before you try:
wardn can-i deployment:manage --scope deployment --on <deployment-id>Which pod and cluster
- No pod named: Wardn lists the deployment's pods and uses a running one. If there are several, it takes the first, so name the pod when it matters.
- A pod named: Wardn finds it in the list. If it exists on more than one cluster, the command stops and asks for
--cluster. - Both a pod and
--cluster: Wardn skips the lookup and asks for that pod on that cluster directly.
Several clusters
A deployment that targets an environment runs on each of the environment's clusters. Pass --cluster <id> to pick one; get the ids from wardn clusters. If the deployment has no running pod, the command stops with the deployment has no running pod; name one.
What is recorded
| What | Detail |
|---|---|
| Activity | exec.started and exec.ended entries: who, the reason, cluster, namespace, pod, container, command, how long, how it ended and the exit code. They are part of the tamper-evident audit trail. |
| Output | Standard output and standard error are recorded on production-tier clusters by default, or on all or none according to the organization's terminal settings. When a session is recorded, the CLI prints This session's output is recorded. on standard error before it starts. Recordings are kept for 90 days by default. |
| Input | Never stored. With a terminal, what you type is echoed in the output and so recorded as it would appear on screen. A password typed at a prompt that does not echo is not. |
Recording fails closed: if the recording cannot be stored, or reaches 64 MiB, the session is ended.
How a session ends
| End | What you see | Exit status |
|---|---|---|
| The command exits | Its output stops. | The command's own status (0 for success). |
You close the window or stop wardn | Wardn ends the session and the operator stops the command. | n/a |
| Idle for too long | error: the session ended (idle_timeout) | 1 |
| Longer than the maximum length | error: the session ended (max_duration) | 1 |
| An admin ended it | error: the session ended (terminated) | 1 |
| The connection to the cluster or Wardn was lost | error: the session ended (operator_lost), gateway_lost or server_lost | 1 |
By default a session ends after 15 minutes without input or output, or after an hour, whichever is first. An organization can change these within hard limits (1 minute to 2 hours idle, 5 minutes to 8 hours maximum) with its terminal settings. By default a person may hold 2 sessions at once, a cluster 10, and a person may ask for 10 sessions a minute.
Errors
The API explains each refusal in its message. The codes below are stable.
| Code | HTTP | Cause |
|---|---|---|
pod.not_found | 404 | The pod does not exist, or you may not see it. A refusal never confirms that a pod exists. |
exec.not_deployer | 403 | You do not manage this deployment. Ask someone who does, or an admin. |
exec.named_only | 403 | The environment allows named people only. Ask an admin. |
exec.pod_foreign | 403 | The pod is not one Wardn applied for this deployment. |
exec.reason_required | 400 | A production-tier cluster needs --reason, 10 to 500 characters. |
exec.namespace_reserved | 400 | The deployment's namespace is one Wardn never opens a terminal in. |
exec.capability_off | 409 | The cluster's Open terminals in pods switch is off. Its owner turns it on. |
exec.cluster_paused | 409 | The cluster is paused. |
exec.operator_unsupported | 409 | The cluster's operator does not support exec. Upgrade it (Upgrading). |
exec.preview | 409 | The deployment is a pull request preview. |
exec.no_inventory | 409 | Wardn has not applied anything of this deployment on that cluster yet, so it cannot tell which pods are its own. |
exec.limit_person, exec.limit_cluster | 409 | Too many sessions open for you, or on the cluster. |
exec.rate_limited | 409 | More than 10 session requests in a minute. |
exec.operator_offline | 503 | The cluster's operator is not connected. |
From the CLI itself: no deployment with that name or id (no match), the deployment has no running pod; name one, and the deployment runs pods on several clusters; name the cluster with --cluster.
Under the hood
The CLI asks the API for a session, which returns a single-use ticket valid for 30 seconds. It then opens a WebSocket to the API with that ticket in the subprotocols, never in the URL, and relays your input and the pod's output over it. This is the same path the web app's Terminal takes. Nothing about the pod is reachable from your machine directly, and the cluster still accepts no inbound connection: the session travels over the operator's existing connection to the gateway.