Skip to content

fix(k8s): the ollama tier DaemonSets drop privilege escalation and capabilities, use RuntimeDefault seccomp and a read-only root filesystem, and run as non-root where the model directory allows - #1508

Merged
dan-petty merged 1 commit into
release/v0.2.32from
fix/1060-ollama-daemonset-hardening
Oct 9, 2026

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Summary

  • Every ollama tier DaemonSet in k8s/llm/profiles/ollama-profiles.yaml (all 9) now runs ollama as UID/GID 10001, which no host login account uses. The pod sets runAsNonRoot: true and seccompProfile: RuntimeDefault. The ollama container sets allowPrivilegeEscalation: false, readOnlyRootFilesystem: true and capabilities.drop: [ALL], with /tmp on an emptyDir.

  • HOME=/home/ollama, the hostPath is mounted at /home/ollama/.ollama, and OLLAMA_MODELS=/home/ollama/.ollama/models. The hostPath itself is unchanged (/var/lib/ollama, DirectoryOrCreate), so the key and models/ stay where they are and nothing is downloaded again.

  • A new root initContainer, own-model-directory, gives that directory to 10001 at every start with chown -R. It uses the same ollama/ollama:0.34.4 image, holds CAP_CHOWN only, runs with no privilege escalation and a read-only root filesystem, and requests cpu: 10m with a memory: 64Mi limit.

    • A root step is unavoidable: fsGroup does not apply to hostPath, a non-root container loses an added CAP_CHOWN at execve, and a DaemonSet cannot use per-node PVCs.
    • This is the re-scope (Option A) the owner accepted on 2026-10-09, the Grafana chart's initChownData pattern.
    • The manifest header and k8s/README.md ("GPU Placement: Ollama tiers") record it as the one kube-linter exception. There is no ignore annotation.
  • New test_every_ollama_tier_runs_unprivileged in tests/test_k8s_llm_gateway.py names the UID once (OLLAMA_UID). For every DaemonSet it asserts:

    • the security contexts;
    • HOME and OLLAMA_MODELS;
    • the mounts and volumes, with the hostPath pinned;
    • exactly one initContainer, using the ollama image, with its command, security context and mount.

    On the old manifest it failed with an assertion diff for every tier.

  • kube-linter 0.8.3 on k8s/llm/profiles/ollama-profiles.yaml, run locally:

  • changelog.d/1060.md (### Fixed) and the task file docs/agent/tasks/task-1060-ollama-daemonset-hardening.md.

  • Live cluster, read-only, before the change: four tiers are Ready (16gib, 48gib, 48gib-slow, 64gib), each running as root with empty security contexts and the hostPath at /root/.ollama. Argo CD Application llm tracks main with auto-sync, so nothing deploys until the release PR merges, and then every tier rolls at once.

Closes #1060

Test plan

  • Red first: uv run pytest tests/test_k8s_llm_gateway.py -n 0 -k runs_unprivileged failed on the unchanged manifest and passes now.
  • uv run pytest -n 0 passes on:
    • 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.py, tests/test_review_project_conventions.py;
    • tests/test_agent_task_files.py, tests/test_release_changelog_fragments.py.
  • uv run ruff check and uv run ruff format --check on the changed test file. No src/ file changed.
  • uv run devops docs check
  • kube-linter 0.8.3 on k8s/llm/profiles/ollama-profiles.yaml: the reports listed above.
  • Pre-commit hooks, including the covering-tests step for the staged files.
  • uv run devops ci: this PR's CI.
  • Person-run canary on the 16gib node, after this PR merges into release/v0.2.32 and before the release PR merges:
    • Run a bare ollama-canary Pod built from the new template, without the DaemonSet's labels.
    • Check: the init exits 0; id shows uid=10001 gid=10001; ls -ln /dev/nvidia*; the models are unchanged; ollama run gpt-oss:20b answers; ollama ps shows GPU; the log has a CUDA inference compute line and no read-only or permission errors.
    • The exact commands and the failure branches are in the task file.
  • Person-run rollout, after the release merges and Argo CD syncs llm:
    • Argo CD llm is Synced and Healthy, and READY == DESIRED for each scheduled tier (16gib, 48gib, 48gib-slow, 64gib).
    • Per tier: the init exit code is 0 and there are no restarts; uid 10001; nvidia-smi sees the GPU; ollama list is unchanged; there are no read-only or permission errors.
    • rollout restart ds/ollama-16gib comes back Ready.
    • Gateway calls answer for gpt-oss:20b (16gib), devops-coder (48gib), deepseek-r1:70b (64gib), and devops-background and bge-m3:latest (48gib-slow).
    • Record the results per tier on this PR.

…pabilities, use RuntimeDefault seccomp and a read-only root filesystem, and run as non-root where the model directory allows (#1060)
@dan-petty
dan-petty merged commit eeb544b into release/v0.2.32 Oct 9, 2026
8 checks passed
@dan-petty
dan-petty deleted the fix/1060-ollama-daemonset-hardening branch October 9, 2026 16:27
dan-petty added a commit that referenced this pull request Oct 9, 2026
* fix(k8s): k8s-monitoring collectors run in the chart's preset shapes, and node-exporter keeps the series the node dashboards read (#1129) (#1500)

* fix(security): the host sandbox declares a noexec /tmp it never applies (#798) (#1502)

Bubblewrap has no noexec option for a tmpfs, so the host sandbox's
`/tmp` was mounted executable while its policy declared `noexec`. The
host sandbox now defaults to DEFAULT_HOST_SANDBOX_POLICY, which declares
only the 64 MiB size. A policy with a tmpfs option bubblewrap cannot
apply (`noexec`, or a size such as `size=50%` that is not in bytes) fails
when the HostSandbox is constructed, with a SandboxValidationError
naming the option, instead of being dropped. The size is parsed by
docker.utils.parse_bytes in place of the hand-written regex. The
container policy keeps noexec (#698). SECURITY.md says the host
sandbox's `/tmp` allows execution.

The output-cap test now runs a shell loop that ignores SIGPIPE, so
closing the pipes does not end it, and asserts that the run ends within
1 s, under the reap's 1 s grace. The test fails if the kill at the cap
is removed.

* refactor(release): the release no longer pins, bumps or pre-publishes the service image tag; image updater rolls service:latest (#1486) (#1504)

Argo CD Image Updater (#1485) keeps Application devops on the digest
service:latest points at, so the custom tag process is gone:

- The cut no longer bumps newTag in k8s/devops/kustomization.yaml or
  rewrites Argo CD targetRevisions, and stages nothing under k8s/.
  devops release check drops the pin and targetRevision checks;
  tests/test_k8s_argocd_apps.py already holds every git source on main.
- k8s/devops/kustomization.yaml loses its images: pin.
- release.yml has no release/v* trigger, plan or promote step. On main it
  builds, smoke-tests, scans, pushes by digest and attests the image,
  then tags it vX.Y.Z and latest.
- ci.yml's Service Image job builds release pull requests too.
- RELEASE_CYCLE.md, docs/ROUTINE_TASKS.md and k8s/README.md describe the
  new flow; the task files of #1451, #741, #1261 and #755 note what this
  removed.

* fix(ci): ci's trivy scans run the trivy version tools.lock pins, so ci and local scans agree (#1499) (#1503)

* fix(ci): review workflow tests start the logfire SDK's credential check, which the network guard blocks (#965) (#1505)

* fix(security): URL and host:port reads use the sending client's parser (#1112) (#1506)

* fix(ci): ci jobs run on a named ubuntu-24.04 runner and always use uv's managed python, never the runner's own python (#1494) (#1507)

All nine runs-on selections name ubuntu-24.04 instead of ubuntu-latest, each
with a comment linking #1501 (the move to ubuntu-26.04, which waits for
actionlint to accept the label); codeql.yml's becomes a plain label.

ci.yml and release.yml set UV_MANAGED_PYTHON: "1" at workflow level, so uv
runs only its own CPython builds and never takes a runner image's own
Python 3.14 for setup-uv's UV_PYTHON=3.14. UV_PYTHON_PREFERENCE is not also
set: uv refuses to run with both.

test_github_workflows_name_their_runner_and_use_managed_python in
tests/test_ci.py fails on a -latest runner label and on a workflow that
reaches setup-uv, directly or through a local composite action, without
the setting.

* fix(k8s): the ollama tier DaemonSets drop privilege escalation and capabilities, use RuntimeDefault seccomp and a read-only root filesystem, and run as non-root where the model directory allows (#1060) (#1508)

* fix(git): GitHub clones trust GitHub's published host keys through OpenSSH (#1114) (#1510)

* feat(ci): changed-line coverage on pull requests (diff-cover) (#850) (#1511)

* fix(k8s): service URLs bracket IPv6 hosts and proxy boundaries (#1111) (#1509)

* fix(security): URL and host:port reads use the sending client's parser (#1112)

* fix(k8s): service URLs bracket IPv6 hosts and proxy boundaries (#1111)

* feat(ci): shuffled repeat runs of a pull request's changed test files (#852) (#1512)

* feat(ci): on-demand mutation testing of changed functions (`devops ci mutate`) (#853) (#1513)

* feat(release): v0.2.32

* chore(release): collect the v0.2.32 changelog fragments (#1517)

The Service's cut (198a273) bumped v0.2.32 without collecting the 13
fragments (#1450), so CHANGELOG.md's newest section was 0.2.31. This moves
them into the [0.2.32] section before release PR #1516 merges.

---------

Co-authored-by: Daniel Petty <[email protected]>
Co-authored-by: dan-petty-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant