/

CVE-2026-34940

Severity:

HIGH RISK

(8.7)

OS Command Injection in KubeAI Ollama Startup Probe Script

CVE-2026-34940

Modified

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote Code Execution within Kubernetes Pods

Severity:

HIGH RISK

(8.7)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

KubeAI's Ollama engine constructs a shell command for a Kubernetes startup probe using unsanitized model URL components and executes it via bash -c.

If an attacker can create or update Model custom resources, they can inject arbitrary shell commands that run inside model server pods.

Affected context

This vulnerability appears in KubeAI deployments that:

  • Use the Ollama-based engine (engine_ollama.go) for model serving
  • Rely on the ollamaStartupProbeScript() helper to build startup probes
  • Allow users, services, or automation to create or update Model custom resources (CRs)

The issue is exposed whenever untrusted or loosely controlled tenants can influence the ref or modelParam fields that feed into the model URL used by the startup probe.

Exploit preconditions

  • Attack surface: Kubernetes API surface for KubeAI Model custom resources
  • Required access: Ability to create or modify KubeAI Model CRs in a namespace where the KubeAI operator runs
  • Trigger point: Pod startup, when the Kubernetes startup probe invokes the generated shell script via bash -c
  • Why exploitation is possible: The ollamaStartupProbeScript() function interpolates unvalidated ref and modelParam values directly into a shell command string using fmt.Sprintf, then executes it through a shell interpreter, allowing crafted input to break out of intended arguments and inject arbitrary commands.

Why this happens

The root cause is a classic OS command injection pattern, mapped to CWE-78: Improper Neutralization of Special Elements used in an OS Command.

Instead of treating user-controlled values (parts of a model URL) as opaque data, the code concatenates them into a shell command line. This string is then executed via bash -c, giving the shell an opportunity to parse metacharacters, separators, and control operators supplied by an attacker.

The bug arises from combining two insecure practices:

  1. Building command lines using string formatting rather than structured argument lists.
  2. Passing those command lines through a general-purpose shell that performs expansion and interpretation.

As a result, users with CR creation privileges can turn what should be a benign health-check probe into an arbitrary command execution mechanism inside the model server pod.

Potential impact

  • Execution of arbitrary commands inside model server containers
  • Reading or modification of data accessible from the pod (model files, tokens, configuration, cached inputs/outputs)
  • Lateral movement within the Kubernetes cluster via network access from the compromised pod
  • Deployment of malware, cryptominers, or backdoors on model-serving infrastructure
  • Abuse of attached credentials (e.g., cloud IAM roles, service accounts) to access external resources
  • Denial of service against the model-serving workload by crashing or halting pods

General mitigation guidance

Effective mitigation focuses on eliminating shell-based command construction and reducing trust in Model CR fields:

  • Prefer structured command execution APIs that pass arguments as arrays (e.g., exec.Command with explicit args in Go), avoiding bash -c and similar shells wherever possible.
  • Treat all data sourced from Model CRs (ref, modelParam, and similar fields) as untrusted input, regardless of the expected format, and avoid embedding them directly in command strings.
  • Where shell usage is unavoidable, apply strict input validation and normalization, restricting values to an allowlist of characters or patterns (e.g., specific model name formats or URL shapes) and rejecting anything outside the expected domain.
  • Separate configuration data from executable logic: design probes and lifecycle hooks so that they do not interpret user-provided strings as part of the command itself.
  • Apply least-privilege to pods spawned by the operator:
  • Minimize filesystem, network, and credential access.
  • Use non-root users and restricted Linux capabilities to limit the blast radius of a successful injection.
  • Implement stronger RBAC boundaries around who can create or modify KubeAI Model CRs, aligning these permissions with trusted roles rather than broad developer groups or tenants.

How teams detect issues like this

Detection should combine static analysis, code review discipline, and runtime controls:

  • Static analysis patterns:
  • Flag uses of bash -c and similar shell invocations in operator code.
  • Detect string interpolation (fmt.Sprintf, concatenation) used to build command lines that include values derived from CR fields or other external sources.
  • Code review signals:
  • Shell commands that contain placeholders for user-configurable values.
  • Health checks, probes, or lifecycle hooks that run scripted logic influenced by CR spec fields.
  • Any use of unvalidated URI/URL components in command execution paths.
  • Policy enforcement:
  • Use admission controllers or policy engines (e.g., Gatekeeper, Kyverno) to restrict risky patterns in CRs, such as disallowing unexpected characters in model identifiers or URLs.
  • Integrate automated code scanning tools in CI pipelines to detect and block merges involving shell-based command construction with external input.
  • Runtime visibility:
  • Log startup probe command executions and anomalies such as unusual arguments or error patterns.
  • Monitor for unexpected outbound connections, process trees, or file modifications originating from model server pods that may indicate command injection abuse.

Sources

SourceLink
github.comgithub.com/kubeai-project/kubeai/security/advisories/GHSA-324q-cwx9-7crr

Frequently asked

questions

It can be, depending on how KubeAI is exposed. If an attacker can reach the Kubernetes API (directly or via a higher-level control plane) and has permissions to create or modify Model custom resources, they can exploit this issue remotely by submitting crafted CR definitions.

The attacker must be able to create or update KubeAI Model CRs in a namespace managed by the operator. This typically corresponds to Kubernetes RBAC permissions such as create or update on the relevant custom resource, which might be granted to specific service accounts, CI pipelines, or developer roles.

The safest fix is to remove shell interpretation from the path entirely: construct commands using structured argument lists (no bash -c) and avoid embedding CR-derived values into a single shell string. If a probe must call a program with dynamic arguments, pass those arguments as explicit parameters, not via a shell command line.

Establish coding guidelines that prohibit building shell commands from untrusted input, require strict validation on all CR-driven configuration fields, and mandate security-focused code review for operators and controllers. Reinforce this with automated checks in CI, and design probes and hooks to be configuration-driven but not command-string-driven.

Find out what's already
exploitable in your codebase.