mcp-server-kubernetes
- Type
- MCP server
- Scanned
- Nov 13, 2026
- Version
- 17bfafa6ac6c
- Files read
- 153
This MCP server lets AI coding agents inspect and manage Kubernetes clusters and Helm releases using your local kubectl, helm, and kubeconfig credentials. Its biggest risk is that prompt injection from untrusted cluster logs or external text can steer the agent into destructive cluster actions or abuse kubectl_generic (such as kubectl kustomize) to run code and overwrite files on your computer.
What it can reach
- Secrets
- Reads Kubernetes cluster credentials from ~/.kube/config, KUBECONFIG paths, environment variables, or in-cluster service-account tokens, and can read or create cluster Secrets and ConfigMaps.
- Shell commands
- Executes kubectl and helm child processes on your computer and can run arbitrary commands inside Kubernetes pods via exec_in_pod.
- Files
- Reads local YAML manifests, patch files, ConfigMap/Secret source files, and Helm values files in stdio mode, writes temporary files in the OS temp folder, and updates the active context in kubeconfig.
- Network
- Connects to Kubernetes API servers, remote Helm chart repositories, and optional OpenTelemetry endpoints, opens local port forwards via kubectl port-forward, and can expose an HTTP or SSE server when enabled.
Findings
-
HighHost code execution and file overwrite via kubectl kustomize in kubectl_generic
src/security/kubectl-flags.ts:533
The server is designed to confine tool calls to Kubernetes cluster operations rather than running code or writing files on the host computer. However, assertAllowedGenericCommand only blocks the kustomize subcommand on remote HTTP/SSE transports, leaving it enabled in the default stdio mode used by Claude Code, Cursor, and Codex. If prompt injection in pod logs, issues, or web pages tricks the AI agent into calling kubectl_generic with command set to kustomize, an attacker can pass --enable-alpha-plugins and --enable-exec with a remote Git repository URL (or --enable-helm with --helm-command) to download and execute arbitrary programs directly on the user's machine even without a cluster connection. In addition, kubectl kustomize treats -o and --output as a local output file or directory path, and assertSafeArgv only blocks -o values ending in file, allowing arbitrary local files to be overwritten.
Fix: Move kustomize into GENERIC_DENIED_VERBS for all transports, or explicitly block --enable-exec, --enable-alpha-plugins, --helm-command, and -o/--output when the verb is kustomize.
-
HighArbitrary local file overwrite on Windows via kubectl cp in kubectl_generic
src/security/kubectl-flags.ts:549
To stop a prompt-injected agent from copying files out of a pod onto the host computer, assertAllowedGenericCommand rejects any kubectl cp destination argument that does not contain a colon, assuming a colon always marks a remote pod:path target. On Windows, absolute paths such as C:\Users\name\... contain a drive-letter colon, and kubectl cp explicitly treats Windows drive-letter paths as local filesystem destinations. A prompt-injected agent on a Windows machine can therefore use kubectl_generic with command set to cp to overwrite local configuration files or drop executables into startup folders.
Fix: Reject cp destination operands that start with a Windows drive letter (such as /^[A-Za-z]:[\\/]/) or add cp to GENERIC_DENIED_VERBS across all transports.
-
LowDefault secret masking (MASK_SECRETS) bypassed in kubectl_get and kubectl_generic
The server enables MASK_SECRETS by default to replace sensitive Kubernetes Secret values with *** before returning them to the AI agent. However, kubectl_get only checks whether resourceType mentions a Secret and ignores the name parameter. Calling kubectl_get with resourceType set to configmap/kube-root-ca.crt and name set to secret/target-secret (valid kubectl multi-resource syntax) skips maskSecretsData completely and returns raw Secret values, even when ALLOW_ONLY_READONLY_TOOLS=true is enabled. Furthermore, when maskSecretsData does run, maskSecretObject leaves the kubectl.kubernetes.io/last-applied-configuration annotation unmasked (exposing Secrets created with kubectl apply), and kubectl_generic does not apply secret masking at all.
Fix: Run maskSecretsData on all JSON and YAML responses whenever MASK_SECRETS is not false (since maskDataValues already checks for Secret and SecretList kinds), apply the same masking in kubectl_generic, and mask or strip kubectl.kubernetes.io/last-applied-configuration on Secret objects.
-
LowRemote transport file-read protection misses --cert, --key, and --custom in kubectl_generic
src/security/kubectl-flags.ts:132
When the server runs over HTTP or SSE (ENABLE_UNSAFE_STREAMABLE_HTTP_TRANSPORT or ENABLE_UNSAFE_SSE_TRANSPORT), assertNoRemoteFileReads blocks flags like -f, --from-file, and --patch-file so remote clients or prompt-injected agents cannot read files from the MCP server host. However, FILE_READ_FLAGS omits --cert and --key (used by kubectl create secret tls with --dry-run=client -o yaml, which reads PEM certificates and private keys from the server disk with no cluster needed and returns them base64-encoded) as well as --custom (used by kubectl debug to read a local profile file).
Fix: Add cert, key, and custom (as well as output-directory for cluster-info dump) to FILE_READ_FLAGS in src/security/kubectl-flags.ts.
-
LowHTTP and SSE transports accept unauthenticated requests when MCP_AUTH_TOKEN is unset
When HTTP or SSE transport is enabled via environment variables (including the Helm chart's default transport.mode of http, which binds to 0.0.0.0), createAuthMiddleware allows all requests through with no password or token unless MCP_AUTH_TOKEN is also configured. Any local user or process on the machine—or any network or cluster peer when HOST is bound beyond loopback and the client sends a localhost Host header—can invoke every enabled Kubernetes and Helm tool without authentication.
Fix: Require MCP_AUTH_TOKEN to be set whenever an HTTP or SSE transport is enabled (especially when HOST is not a loopback address), refusing to start unless an explicit unauthenticated override flag is provided.
-
LowPredictable non-exclusive temporary kubeconfig file in shared OS temp directory
src/utils/kubernetes-manager.ts:423
When cluster credentials are supplied via KUBECONFIG_YAML, KUBECONFIG_JSON, or K8S_SERVER and K8S_TOKEN, createTempKubeconfigFromYaml writes the kubeconfig (including bearer tokens or private keys) directly into os.tmpdir() using Math.random() in the filename and fs.writeFileSync without exclusive creation (flag wx). On a shared multi-user computer without kernel temp-file protections, another local user who pre-creates the predicted filename could read or redirect the credentials.
Fix: Use writeTempFile from src/utils/temp-file.ts so temporary kubeconfig files are created inside a private 0700 mkdtempSync directory with flag wx and mode 0600.
-
LowUnpinned Helm installation script executed during Docker image build
The Dockerfile downloads and executes the get-helm-3 shell script directly from the mutable main branch on GitHub without pinning a commit hash, release version, or SHA-256 checksum. Anyone building or deploying the container image depends on that upstream script and latest release remaining uncompromised at build time.
Fix: Download a specific versioned Helm archive from get.helm.sh and verify its SHA-256 checksum in the Dockerfile before extracting the binary.
