Summary
The /registercrd endpoint in KubePlus kubeconfiggenerator suffers from a command injection flaw where the user-controlled chartName parameter is concatenated directly into a shell command.
Because this command is executed using subprocess.Popen(..., shell=True) without validation or sanitization, an attacker can supply crafted input to execute arbitrary shell commands on the underlying host.
Affected context
This vulnerability appears in KubePlus 4.14 within the kubeconfiggenerator component, specifically when handling HTTP requests to the /registercrd endpoint.
It is relevant in deployments where kubeconfiggenerator is exposed over a network (intra-cluster or external) and where the service accepts client-controlled chartName values.
The risk increases when the process runs with elevated privileges or on hosts with access to sensitive Kubernetes credentials or cluster management interfaces.
Exploit preconditions
- Attack surface: HTTP interface of the kubeconfiggenerator
/registercrdendpoint. - Required access: Ability to send requests to kubeconfiggenerator (e.g., network reachability within the cluster, or externally if published).
- Trigger point: Submission of a crafted
chartNameparameter value that is incorporated into the shell command. - Why exploitation is possible: The implementation constructs a shell command string by directly concatenating user input into it and executes it via
subprocess.Popen()withshell=True, allowing shell metacharacters and sequences to be interpreted as additional commands.
Why this happens
The core issue is the construction of shell commands using untrusted input, combined with the use of shell=True in subprocess.Popen().
This pattern directly maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), as user-controlled data influences executable instructions interpreted by the system shell.
Instead of treating chartName as data, the code treats it as part of the command line, enabling attackers to inject shell operators, additional commands, or argument manipulations that the shell processes as executable logic.
Potential impact
- Execution of arbitrary shell commands with the privileges of the kubeconfiggenerator process.
- Unauthorized access to Kubernetes configuration files or credentials available on the host or in the container.
- Modification, creation, or deletion of files on the system where kubeconfiggenerator runs.
- Lateral movement within the cluster by leveraging host or service account permissions.
- Disruption of KubePlus functionality or broader denial of service in the cluster environment.
- Potential escalation to full cluster compromise if the service account or node has powerful Kubernetes API permissions.
General mitigation guidance
Effective mitigation centers around separating untrusted data from executable commands and minimizing shell usage:
- Replace shell-based command execution with direct invocation of binaries using argument lists (e.g.,
subprocess.Popen([...], shell=False)), ensuring user input is always passed as a data argument. - Implement strict validation and normalization for parameters like
chartName, such as whitelisting acceptable characters and known values or mapping user inputs to internal identifiers. - Avoid constructing command strings dynamically; instead, use parameterized command building that cannot alter control flow.
- Run kubeconfiggenerator with the least privileges necessary, limiting file system access and Kubernetes API permissions.
- Use container hardening (read-only filesystems, restricted capabilities, seccomp profiles) to reduce the blast radius of any command execution.
How teams detect issues like this
Detection typically combines code-centric and operational views:
- Static analysis: Configure SAST tools or linters to flag uses of
subprocess.Popen,os.system, or similar APIs withshell=True, especially when arguments include request parameters or other untrusted data. - Code review: Look for patterns where HTTP request fields (e.g.,
chartName) are concatenated into strings that are passed to command execution functions; enforce policies that require argument-list execution and strong input validation. - Policy enforcement: Integrate secure coding guidelines into CI pipelines to block merges that introduce shell-based execution with user-supplied input.
- Runtime monitoring: Use process and command auditing within containers or hosts to detect unusual command invocations originating from kubeconfiggenerator, especially those that deviate from expected tool usage.

