UNPKG

mcp-server-kubernetes

Version:

MCP server for interacting with Kubernetes clusters via kubectl

30 lines (29 loc) 1.67 kB
import { type ExecFileSyncOptionsWithStringEncoding } from "child_process"; /** * Validate user-supplied kubectl flags and args. Throws an McpError if any * dangerous flag is present and the unsafe-flags escape hatch is not set. * * The check covers: * - keys of the `flags` object (e.g. { server: "..." }) * - tokens in the `args` array, in both joined ("--server=x") and split * ("--server", "x") forms, plus short aliases ("-s"). */ export declare function assertNoDangerousFlags(flags?: Record<string, unknown>, args?: string[]): void; /** * Validate a fully-constructed kubectl/helm argv. Unlike assertNoDangerousFlags * (which inspects only the free-form `flags`/`args` inputs of kubectl_generic), * this scans every token in the final argv — including bare positional slots * such as resource names, node names, and resource types that the individual * tools push directly. kubectl's pflag parser treats any token beginning with * "-" as a flag regardless of position, so a tool argument like * name: "--server=https://attacker" would otherwise redirect the API server * and leak the operator's bearer token. Throws an McpError on any dangerous * flag unless ALLOW_KUBECTL_UNSAFE_FLAGS=true. */ export declare function assertSafeArgv(args: readonly string[]): void; /** * Drop-in replacement for child_process.execFileSync that scans the argv for * credential/target-redirecting flags before executing. Tool files import this * as `execFileSync`, so every kubectl/helm call site is guarded at one place. */ export declare function execFileSyncSafe(file: string, args: string[], options: ExecFileSyncOptionsWithStringEncoding): string;