nodecode-kubectl
Read-only Kubernetes for Nodecode through the operator's own kubectl:
get, describe, logs, events and top as tools the model calls. Nothing it
runs changes a cluster, Secrets are refused in every spelling, and the
credentials other objects carry are redacted before an answer reaches the
conversation.
Written for Nodecode from kubectl's documented command line; no Kubernetes code is in here. kubectl is your install, run as a child process against your kubeconfig. SPDX-License-Identifier: MIT.
Install
nodecode add nc://kubectl
Install kubectl so kubectl is
on PATH, or set command to its absolute path. The cluster's credentials
stay in your kubeconfig; this cell never reads or copies them.
Tools
| Tool | What it runs |
|---|---|
kubectl_get |
kubectl get - a table, wide, name, or json/yaml (redacted, see below). Takes resource (a type or a comma list), names, namespace, all_namespaces, context, selector, field_selector, output, show_labels, sort_by. |
kubectl_describe |
kubectl describe of one type, by name (or prefix) or selector, with hide_events to leave the events out. |
kubectl_logs |
kubectl logs of a pod, or TYPE/NAME for one pod of a deployment, statefulset, daemonset, job or replicaset: container or all_containers, previous, tail (1 to max_log_lines, its default), since (e.g. 10m, 2h30m), timestamps. Always --tail and --limit-bytes bounded. |
kubectl_events |
kubectl events, oldest first: for (KIND/NAME), types (Normal, Warning), namespace or all_namespaces. |
kubectl_top |
kubectl top pod or node (what): namespace, all_namespaces, selector, containers, sort_by (cpu or memory). Needs metrics-server in the cluster. |
kubectl_contexts |
The kubeconfig's context names (kubectl config get-contexts --output=name), the current one marked *, the ones this cell may use marked (allowed). |
/kubectl answers kubectl's client version and which context and
namespaces runs use; it does not reach the cluster.
Config
A kubectl section in ~/.nodecode/config.jsonc (see
config.example.jsonc). A present section is
enabled; "enabled": false vetoes it.
| Setting | Default | Meaning |
|---|---|---|
command |
["kubectl"] |
The argv prefix that runs kubectl. |
kubeconfig |
"" |
An absolute path of the kubeconfig to use, passed as --kubeconfig; empty leaves kubectl's own choice (KUBECONFIG, then ~/.kube/config). |
contexts |
[] |
The contexts runs may use. Empty: every run uses the kubeconfig's current context and a call may not name one. Listed: every run carries --context, the first one unless the call picks another listed one. |
namespaces |
[] |
The namespaces runs may read. Empty: any namespace, and all_namespaces is allowed. Listed: every namespaced run carries --namespace, the first one unless the call picks another listed one, and all_namespaces is refused. |
request_timeout |
30 |
Seconds one request to the cluster's API may take (--request-timeout). |
timeout_seconds |
60 |
One kubectl run's ceiling; its whole process tree is killed past it. |
max_output_chars |
20000 |
How much one answer carries; logs are also read with --limit-bytes of four times this. |
max_log_lines |
500 |
The most log lines kubectl_logs reads, and its default tail. |
The safest setup is a kubeconfig for a read-only identity (a ServiceAccount
bound to the view ClusterRole, which cannot read Secrets either), with
contexts and namespaces listed.
What is refused
Before anything runs:
- Secrets, in every spelling. A resource type whose base (before the
first dot) is
secretorsecrets, in any case:secret,Secrets,secrets.v1,secret.v1.,secrets.v1.core, inside a comma list likepods,secrets, assecret/NAMEinkubectl_logs, or as the kind inkubectl_events'for. - Any verb but the five reads. No tool builds
apply,create,edit,delete,patch,scale,exec,cp,port-forward,proxy,authorget --raw. - Templates.
outputis one oftable,wide,name,json,yaml;go-template,jsonpath,custom-columnsandtemplateforms are refused, so no output can print a field the redaction did not see.sort_byis a plain field path (letters, digits,.,_). - Flags in values. Every value rides its flag as one
--flag=valueargument. A value opening with a dash, or holding a blank or a control character, is refused; resource types are letters, digits,.and-; names are letters, digits,.,-,_and:; a namespace is a DNS label; selectors take letters, digits,. _ / = ! , : - ( )(and spaces, for label selectors such astier in (web,api));sinceis a duration such as30sor2h30m. - A context or namespace outside the section's lists, and
all_namespaceswhennamespacesis listed. - A kubeconfig that is not an absolute path to an existing file.
What is redacted
Secrets are refused, but credentials also ride other objects:
jsonandyamlare always read from kubectl's--output=json, then redacted as data and written back out (YAML by the cell), so redaction does not depend on how kubectl lays text out. In every object, everyenv[].value(containers, initContainers, ephemeralContainers, and the pod templates of Deployments, Jobs, CronJobs and the like) reads[redacted];valueFromreferences are kept. Thekubectl.kubernetes.io/last-applied-configurationannotation, a full copy of whatever was last applied (a Secret's data included), reads[redacted]. A Secret that reaches an answer anyway has itsdataandstringDatavalues redacted. Output that is not JSON is withheld, never shown raw.kubectl_describe: in everyEnvironment:block a literal value, and every line it spills onto, reads[redacted]; a reference (<set to the key ... in secret ...>,<set to the key ... of config map ...>,(v1:status.podIP),(limits.cpu)) is kept. A block runs over every line indented deeper than itsEnvironment:heading, blank lines included, so a value with an empty line in it (a PEM key, a paragraph) is redacted to its end. The last-applied annotation's value is redacted, with every line describe wraps it onto.- Every literal value taken out (8 characters or more) is also scrubbed
from the rest of that answer, so the same password written into a
container's
argsdoes not survive beside it. The scrub is one pass: a[redacted]already in the answer is never searched again. - Every answer, error included: JSON Web Tokens (a service account token is
one; signed, encrypted, or unsigned with its trailing dot) read
[redacted token], a period after one staying a period, and the credential afterBearer(past any spaces or tabs) reads[redacted]- in logs, events and kubectl's own errors. - Redaction and scrubbing run over the whole output before it is cut to
max_output_chars, so a cut never leaves a piece of a token or a secret that neither could recognize.
ConfigMap data is shown as it is: keep credentials in Secrets.
Tests
bash .github/test-cell.sh tools/nodecode-kubectl
Offline: every run goes through a stub that records the command line and answers the output the test chose, so no test needs kubectl or a cluster.