Skip to content

feat: node shell + pod exec tools, k8s_raw safe defaults; drop runtime server add/remove - #1

Merged
Negashev merged 2 commits into
mainfrom
feat/mcp-node-shell-exec
Oct 6, 2026
Merged

Negashev merged 2 commits into
mainfrom
feat/mcp-node-shell-exec

Conversation

@Negashev

@Negashev Negashev commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Four changes to the MCP server:

  • US1 — drop runtime server management tools. rancher_servers_add / rancher_servers_remove are removed: servers are configured via environment variables only (RANCHER_SERVER_<ID>_<PROP> / RANCHER_SERVERS), and the in-memory store was never persisted. rancher_servers_list stays.
  • US2 — rancher_node_shell (opt-in: ENABLE_NODE_SHELL=true): run one non-interactive command on a node provisioned via a Rancher node driver. The Rancher server dials SSH to the node and proxies the session over a WebSocket (Steve links.shell on the CAPI Machine); the MCP host needs no network path to the node and no SSH keys. Returns stdout + exit code.
  • US3 — safe defaults for k8s_raw (per-call opt-in, no restart):
    • mutating methods (POST/PUT/PATCH/DELETE) are blocked unless the call passes allowWrite: true;
    • Secret data/stringData values are masked as *** (single objects and lists) unless the call passes showSensitiveData: true.
  • US4 — k8s_exec (opt-in: ENABLE_CONTAINER_EXEC=true): run one non-interactive command in a pod container through the Rancher Kubernetes proxy (WebSocket exec, v5.channel.k8s.io→v4); no kubeconfig or external kubectl needed. Returns stdout, stderr and exit code.

Why

  • Server config duplication: the add/remove tools mutated session-only state that vanished on restart.
  • Node diagnostics: there was no way to reach nodes that are only visible to Rancher.
  • k8s_raw was "DANGEROUS" with no floor: accidental mutations and Secret leakage were one typo away.
  • Pod diagnostics previously required rancher_clusters_kubeconfig + a local kubectl.

Safety

  • Both exec tools are off by default and are absent from tools/list unless explicitly enabled (restart required).
  • k8s_raw write access and Secret masking are per-call (allowWrite / showSensitiveData), so no restart is needed to opt in for a single call.
  • Tokens travel only in the Authorization header on the WS handshake; error messages never include tokens.

Testing

  • Unit: 254 passed (was 199) — covers the Steve dot-form URL, machine resolution error mapping, shell markers/subshell, exec frame decoding + exit-status parsing, masking (incl. real SecretList shape without item kind), and flag gating. npm run lint + npm run build clean.
  • Live-verified on Rancher 2.15.2 (dandelion):
    • tools/list: 17 tools by default, 19 with both flags; servers_add/remove gone.
    • rancher_node_shell: hostname → exit 0, correct stdout, 0.3–0.9 s; negatives (unknown node, no-shell node, timeout) return clear errors.
    • k8s_exec: hostname → exit 0; sh -c 'exit 3' → 3; distroless container/404/missing container → clear errors; timeout works.
    • k8s_raw: masked by default, unmasked per-call, mutation blocked (object unchanged), server stays healthy.

Notes

  • Version bumped 0.1.16 → 0.1.17 (patch). Publishing to npm is intentionally not part of this PR.
  • Node shell limitation: only nodes provisioned via a Rancher node driver expose the shell link; stderr is merged into stdout (PTY). Pod exec has separate stdout/stderr channels.
  • Known upstream quirk: rancher/rancher#52003 (WS ping-pong with very large streams) — negligible for one-shot commands.

…r add/remove

US1: remove rancher_servers_add/rancher_servers_remove (env-only config).
US2: rancher_node_shell — one-shot command on a node via Rancher Steve shell
     (links.shell on CAPI Machine; WS base64.channel.k8s.io; START/RC markers;
     subshell + PTY echo/banner stripping). Gated by ENABLE_NODE_SHELL.
US3: k8s_raw safe defaults — mutating methods blocked unless allowWrite: true;
     Secret data/stringData masked unless showSensitiveData: true (per-call,
     no restart; handles SecretList items without kind).
US4: k8s_exec — one-shot pod exec via Rancher WS proxy (v5/v4 channel
     protocol; exit code from channel-3 metav1.Status). Gated by
     ENABLE_CONTAINER_EXEC.

Tests: +55 (254 total) — frames/markers/security/flags; live-verified on
dandelion (node shell, pod exec, k8s_raw security 7/7).
- README: tools overview (no add/remove; node shell + k8s_exec opt-in via
  ENABLE_NODE_SHELL / ENABLE_CONTAINER_EXEC), k8s_raw per-call allowWrite /
  showSensitiveData defaults.
- env.example: the two opt-in flags with usage notes.
- package.json: 0.1.16 -> 0.1.17 (patch).
@Negashev
Negashev merged commit f51913d into main Oct 6, 2026
5 checks passed
@Negashev
Negashev deleted the feat/mcp-node-shell-exec branch October 6, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant