Repository navigation
Description
Problem
None of the 9 ollama tier DaemonSets in k8s/llm/profiles/ollama-profiles.yaml sets a pod or container securityContext.
- At d6ebe97, the 936-line file has no match for
securityContext,runAsNonRoot,readOnlyRootFilesystem,allowPrivilegeEscalation,seccomporcapabilities. - The containers are at
:50, 150, 251, 353, 455, 560, 663, 776, 879, and the pod specs at:33, 136, 234, 339, 441, 543, 646, 749, 862. - 8 tiers had the gap at the merge base e6ce3db. feat(llm): add speed-tier service aliases, align 48gib slow routing weights and bump max loaded models #1042 (f5fdf40) added the 9th,
ollama-48gib-slow(:413-512).
What that leaves:
- Root. The containers run as root.
idin the live ollama-16gib pod returned uid=0 (measured once, during the S10 evaluation), and the pod'ssecurityContextis{}. - No other controls. Default capabilities, privilege escalation allowed, no seccomp profile and a writable root filesystem.
- A writable host directory. The hostPath
/var/lib/ollama(DirectoryOrCreate) is mounted at/root/.ollama. - An open API. The API listens on
0.0.0.0:11434with no authentication (OLLAMA_HOST,:53-54).llm-default-perimeter(k8s/llm/networkpolicy.yaml) admits every llm-namespace pod, the monitoring namespace and Traefik, with no port restriction.- NetworkPolicies are additive, and
k8s/llm/profiles/networkpolicy.yamlselects onlyprovider=vllm, so nothing narrows this.
- No admission check. Namespace
llmenforces Pod Securityprivileged(k8s/llm/namespace.yaml:7-9), so admission checks nothing.
So a code-execution bug in ollama would run as root, with default capabilities and a writable host directory [inference].
The six first-party workloads in the same stack already set runAsNonRoot: true, allowPrivilegeEscalation: false and readOnlyRootFilesystem: true: cloudflared, llm-gateway, portkey, valkey, valkey-runs and jaeger.
- For example,
k8s/llm/gateway/deployment.yaml:22-28sets UID/GID 1000 and RuntimeDefault seccomp, pinned bytests/test_k8s_llm_gateway.py:77-100. - The Helm values for traefik, qdrant and otel set them too.
- The DCGM exporter is the documented exception: it needs root and
SYS_ADMINfor NVML (docs/SELF_IMPROVEMENT.md:278).
Why ollama runs as root is not recorded. I searched k8s/, docs/, the task files and the manifest's git history and found nothing. Likely reasons [inference]:
- the
ollama/ollamaimage runs as root and keeps its data in/root/.ollama; - kubelet creates a
DirectoryOrCreatehostPath owned by root, so a non-root UID cannot write models there without achown; fsGroupdoes not change hostPath ownership.
The NVIDIA runtime (runtimeClassName: nvidia) injects the device nodes and does not by itself need root inside the container [inference; to confirm on a node].
How the review saw it. Review session 20261003-034353 (S10, release/v0.2.25 at d6ebe97; .data/review-evaluation-20261003-s10.md, section 4). The golden cases are S10 candidates [1], [11] and [2]-[10].
- Semgrep [1] (
:50: noallowPrivilegeEscalation: false, capabilities not dropped) and [11] (:33: norunAsNonRoot) are valid. The scanned-clean dependency check invalidated both as "kubernetes CLEAN" (fix(review): the scanned-clean check invalidates only claims about a dependency's own advisories #1044). - kube-linter's
run-as-non-root×9 was merged away by same-title consolidation (fix(security): kube-linter findings carry their own check, message and manifest file, and scan reports keep each one #1045). - kube-linter's
no-read-only-root-fs×9 was reported LOW and UNVERIFIED, at rows 32-40 of 47.
No open issue covers ollama hardening. #953 covers qdrant's chart securityContext and the single-ollama leftovers only.
Out of scope: memory limits (kube-linter unset-memory-requirements ×9). #209 removed them deliberately.
Acceptance criteria
- Every ollama DaemonSet's container sets:
allowPrivilegeEscalation: false;capabilities.drop: [ALL];seccompProfile.type: RuntimeDefault(pod or container level);readOnlyRootFilesystem: true, with anemptyDirat/tmpand at any other path ollama writes outside its data directory (found by the person-run check).
- Every ollama DaemonSet runs as a fixed non-root UID and GID with
runAsNonRoot: true.- The model directory is owned by that UID, set as the key questions propose.
OLLAMA_MODELSand the data mount move off/root.- If the person-run check shows that the NVIDIA runtime or the hostPath needs root, the DaemonSets keep root with every other control set. A comment in the manifest and
k8s/README.mdthen record the exception and why.
- An offline test in the style of
tests/test_k8s_llm_gateway.py:77-100loads every DaemonSet inollama-profiles.yamland asserts those fields, so a new tier (as feat(llm): add speed-tier service aliases, align 48gib slow routing weights and bump max loaded models #1042 added) cannot ship without them. It fails on the current manifest. - (local, recorded in the PR) kube-linter 0.8.3 over
ollama-profiles.yamlreports nono-read-only-root-fsand norun-as-non-root, unless the documented exception keeps root. The test suite does not run kube-linter. -
changelog.d/1060.mdrecords the change under### Fixed.CHANGELOG.mdis not edited. -
uv run devops cipasses. - (person-run) On the homelab, after the deploy, each scheduled tier's pod becomes Ready, sees its GPU (
nvidia-smior ollama's startup log), and loads and answers a model through the gateway.idin the pod shows the non-root UID, or the documented exception. Record the result per tier in the PR.
Key questions
- Why does ollama run as root, and can it stop? (proposed) Nothing in the repo records a reason. Confirm on one node before changing every tier.
- Run the 16gib tier with the non-root UID and the re-owned directory.
- If it sees its GPU and loads a model, apply the change to all tiers.
- If not, keep root as the documented exception, with the other controls set.
- How does the model directory get its owner? (proposed) Through an initContainer in each DaemonSet.
- The initContainer runs as root with only
CHOWNandFOWNERand re-owns/var/lib/ollamato the fixed UID. Its own controls areallowPrivilegeEscalation: falseand a read-only root filesystem. - The fix then lives in this repo and does not wait on
dan-petty/homelab. fsGroupcannot do it, because it does not apply to hostPath volumes.
- The initContainer runs as root with only
- Which UID? (proposed) 1000/1000, as the gateway uses. Name it once in the manifest and assert it in the test.
- Does the
llmnamespace's Pod Security level change? (proposed) Not in this item. Once nothing inllmneedsprivileged, raisingenforceis a separate change. - Is this a v0.2.25 critical fix? (proposed) No. It is a hardening gap present since the tiers were added (8 of 9 at v0.2.24), not a regression, and the network perimeter limits who can reach port 11434. P2, backlog.
Depends on: none.
Order: #795 (v0.2.29) also edits ollama-profiles.yaml (selectors and comments). Whichever lands second rebases. The change touches k8s/llm/profiles/ollama-profiles.yaml, k8s/README.md and a new or extended manifest test.
Related:
- fix(k8s): monitoring ingress admits 0.0.0.0/0, qdrant ignores its security context, and single-ollama leftovers remain #953: qdrant's
securityContextand the monitoring ingress. - fix(review): the scanned-clean check invalidates only claims about a dependency's own advisories #1044: the scanned-clean check that invalidated the two Semgrep findings.
- fix(security): kube-linter findings carry their own check, message and manifest file, and scan reports keep each one #1045: kube-linter checks merged away.
- fix(k8s): deploy-stack applies the llm gateway policy and narrows its egress #795: ollama tier placement and labels.
- fix(k8s): uncap ollama memory limits and elevate daemonset/deployment resource thresholds #209: memory limits removed deliberately.
- feat(llm): add speed-tier service aliases, align 48gib slow routing weights and bump max loaded models #1042: added the 9th tier.
Update 2026-10-09: re-scope before building (owner decisions)
The v0.2.32 assessment and its challenge found every criterion buildable except AC4 ("kube-linter reports nothing" for these DaemonSets): some container must run as root once to give the model directory to the ollama user, because fsGroup does not apply to hostPath volumes, a non-root container loses an added CAP_CHOWN at execve (containerd sets no ambient capabilities), and a DaemonSet cannot use per-node PVCs. The owner decided:
- AC4 becomes: kube-linter 0.8.3 over
ollama-profiles.yamlreports nono-read-only-root-fsand no new report of any kind, and reportsrun-as-non-rootonly for the root chown initContainerown-model-directory, one per DaemonSet. That initContainer holds only CAP_CHOWN, has no privilege escalation and a read-only root filesystem, and exits before ollama starts; the manifest header comment and k8s/README.md record it as the one exception. No ignore-check annotation. (unset-memory-requirementson the ollama container stays out of scope, fix(k8s): uncap ollama memory limits and elevate daemonset/deployment resource thresholds #209.) This follows the Grafana chart's owninitChownDatapattern. - UID: ollama runs as a dedicated UID and GID, 10001, which no host login account uses, so neither the model directory's owner nor an escaped process maps to a person's account on the GPU nodes.
- AC2 clarification: CAP_CHOWN alone is enough (no FOWNER). HOME is
/home/ollama, which keeps the key and the models on the existing hostPath, so nothing is downloaded again. - Naming the UID once: YAML anchors don't cross
---documents anddeploy-stack'skubectl apply -fwould skip a kustomize patch, so the test names the UID once and asserts it for all 9 tiers. - Every other criterion stands as written.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 8, 2026
Placed in v0.2.32 on 2026-10-08 at the owner's request ("Populate 10 security and ci issues into each v0.2.30, v0.2.31, and v0.2.32 milestone"). This is a person's placement. Release theme: URLs and host keys read by the library that dials, ollama hardening, and pull-request test-quality tooling. Position 6 of 10 in the release's planned merge order. Its board Status is set to Ready, so the release-start fill keeps it.
fix(k8s): the ollama tier DaemonSets drop privilege escalation and ca…
dan-petty-bot commentedon Oct 9, 2026
What changed
#1508, merged into
release/v0.2.32as eeb544b.5 file(s) changed.
How it was verified
Check runs at fe4d74a:
Acceptance Criteria of
docs/agent/tasks/task-1060-ollama-daemonset-hardening.md:Every ollama DaemonSet's
ollamacontainer setsallowPrivilegeEscalation: false,capabilities.drop: [ALL]andreadOnlyRootFilesystem: true, withseccompProfile: RuntimeDefaultat pod level and an emptyDir at/tmp. No other emptyDir is added: the person-run checks below look for "read-only file system" errors, and each such path gets an emptyDir.Every ollama DaemonSet runs as UID and GID 10001 with
runAsNonRoot: true. The model directory is given to that UID byown-model-directory, which holdsCAP_CHOWNalone.OLLAMA_MODELSand the data mount moved off/root, andHOME=/home/ollamakeeps the existing hostPath layout.test_every_ollama_tier_runs_unprivilegedintests/test_k8s_llm_gateway.pyloads every DaemonSet inollama-profiles.yaml. For each one, it asserts:HOMEandOLLAMA_MODELS;/var/lib/ollama(DirectoryOrCreate);own-model-directory, with the ollama container's image, itschowncommand, its security context and its mount.A new tier is covered without editing the test, and
test_ollama_profiles_define_standard_vram_tiersstill pins the 9 names. On the previous manifest the test failed with an assertion diff for every tier, not aKeyError. It runs no kubectl, kube-linter or network call.kube-linter 0.8.3 over
k8s/llm/profiles/ollama-profiles.yaml(run locally; the suite does not run it):no-read-only-root-fsx9,run-as-non-rootx9 andunset-memory-requirementsx9.run-as-non-rootx9, allcontainer "own-model-directory"(the recorded exception), andunset-memory-requirementsx9, allcontainer "ollama"(out of scope: fix(k8s): uncap ollama memory limits and elevate daemonset/deployment resource thresholds #209 removed the memory limits on purpose).no-read-only-root-fsis 0, nothing new appears, and no ignore-check annotation is used.changelog.d/1060.mdrecords the change under### Fixed.CHANGELOG.mdanddocs/ROADMAP.mdare not edited.Locally, these pass:
tests/test_k8s_llm_gateway.py,tests/test_k8s_gpu_matrix.py,tests/test_ai_gateway_portkey.py,tests/test_k8s.py::test_k8s_workload_resource_limits_and_probes,tests/test_k8s_valkey_stack.py,tests/test_k8s_push_secrets.py,tests/test_k8s_manifest_validation.py,tests/test_k8s_network_policies.pyandtests/test_review_project_conventions.py;tests/test_agent_task_files.pyandtests/test_release_changelog_fragments.py;ruff checkandruff format --checkon the test file, anddevops docs check.No
src/file changed, so mypy has nothing new to check.uv run devops ciruns as the pull request's CI check.Pending a person: the canary on one node, after this PR merges into
release/v0.2.32and before the v0.2.32 release PR merges intomain(Argo CD rolls every tier at once frommain):release/v0.2.32, record each scheduled tier's models for the later comparison, and confirm that the 16gib tier has no model loaded (ollama pslists none), so the canary has the GPU to itself:ollama-canary, withrestartPolicy: Never. It must not carry the template's labels: the DaemonSet would adopt and delete a pod matching its selector, and theollama-16gibServices would send gateway traffic to it. If it stays Pending for lack of CPU or memory next to the live pod, the canary cannot run on that node: delete it (kubectl -n llm delete pod ollama-canary) and rely on the rollout checks.CAP_DAC_OVERRIDE).release/v0.2.32before the release PR merges, and change the test with it:/dev/nvidia*is 0660 to a group and the log shows no CUDA line: add podsupplementalGroups: [<that gid>]to all 9 tiers.k8s/README.mdnote. The initContainer must stay and chown to0:0, because root with all capabilities dropped cannot write the 10001-owned directory the canary left.Pending a person: the rollout, after the v0.2.32 release PR merges and Argo CD syncs
llm:0 0(init exit code, restarts),uid=10001 gid=10001, a GPU name, nodiffoutput, and a CUDAinference computeline with no "read-only" or "permission denied":kubectl -n llm rollout restart ds/ollama-16gib && kubectl -n llm rollout status ds/ollama-16gib --timeout=10mcompletes, and the first command of step 2 then prints0 0forollama-16gib.k8s/llm/gateway/configmap.yaml):gpt-oss:20b(16gib),devops-coder(48gib),deepseek-r1:70b(64gib), anddevops-backgroundandbge-m3:latest(48gib-slow). Each call returns achoicesentry (the embedding, a vector length), andkubectl -n llm exec ds/<tier> -c ollama -- ollama psthen shows the model on 100% GPU:dan-petty commentedon Oct 9, 2026
Canary passed (2026-10-09, before the v0.2.32 release PR)
Ran the task file's canary on the 16 GiB tier's node from
release/v0.2.32(after #1508): a bare Podollama-canarybuilt from the mergedollama-16gibtemplate, without the DaemonSet's labels, withrestartPolicy: Never. One deviation: the template's 8Gi memory request did not fit next to the live pod (FailedScheduling, Insufficient memory), so the canary requested 4Gi and 1 CPU; nothing it checks depends on the request.own-model-directoryexit 0;/home/ollama/.ollamaandmodels/now owned by 10001:10001.id: uid=10001 gid=10001./dev/nvidia*arecrw-rw-rw-, so nosupplementalGroupsis needed.ollama listidentical to the live tier's (no re-download).ollama run qwen2.5-coder:7banswered;ollama psshows100% GPU; the log has the CUDAinference computeline (RTX 5070 Ti, driver 13.4) and no "read-only" or "permission denied".ollama-16gibpod kept running throughout.The NVIDIA runtime hook works with the read-only root filesystem. The post-merge rollout checks in the task file still apply when v0.2.32 reaches main.
feat(release): v0.2.32 (#1516)