Skip to content

fix(k8s): enforce restricted Pod Security in the llm namespace #5012

Open

Description

@dan-petty

Update 2026-11-26 (infra move): the llm manifests, gateway config and network policies moved to dan-petty/homelab.

This issue keeps the product part: the default Ollama URLs, gpu_matrix.json, the devcontainer template, the llm port-forward of Ollama in commands/k8s/, and the specs and tests that name the Services in llm. The namespace move, the Open WebUI securityContext and restricted llm are in the homelab follow-up. Both must land together.

Follow-up: dan-petty/homelab#290.


Problem Description

The gateway, with the provider keys and the spend database, runs in a privileged namespace only because of the Ollama hostPath. All other llm pods already meet the restricted Pod Security profile. This item is rank 22 of the cluster integration plan #4989.

Reproduction Steps

  1. kubectl get namespace llm --show-labels shows the Pod Security level.
  2. kubectl -n llm get pods and read the securityContext and volumes of each pod.

Expected vs Actual Behavior

Expected: the namespace that holds the provider keys enforces restricted Pod Security.

Actual: the Ollama DaemonSets need a hostPath model store and a CAP_CHOWN initContainer, so llm is privileged.

Proposed Fix

  1. Move the Ollama DaemonSets and Services to a new privileged namespace (hostPath model store, CAP_CHOWN initContainer).
  2. Give Open WebUI a restricted securityContext in values-open-webui.yaml.
  3. Set llm to enforce restricted.
  4. Change the 24 tracked files that name the Ollama Services in llm (gateway config, config/defaults.py, gpu_matrix.json, the devcontainer template, specs and tests) and the gateway perimeter.

Do it after #3583, or fold #3583 in.

Environment Diagnostics

Homelab k3s cluster; Ollama DaemonSets on the GPU nodes. Study: read-only kubectl get, 2026-11-12.

Acceptance Criteria

  • The llm namespace enforces restricted, and every llm pod runs.
  • The Ollama pods run in their own namespace, and the gateway reaches them.
  • git grep finds no Ollama Service name in the llm namespace.

Dependencies

#3583 (admit only the gateway to the Ollama pods).

Source: #4989

Alternatives check of 2026-12-01: none.
Tool: none found.
Reason: Searches found only policy engines and codemod tools; Kyverno cannot admit the hostPath and CAP_CHOWN Ollama pods, and no tool rewrites the tracked llm DNS names, so the edits stay manual.

Lacks:

  • No tool moves the Ollama DaemonSets to a privileged namespace
  • No tool rewrites the Ollama Service names in 24 tracked files
  • No tool updates the port-forward, specs and tests together
  • A policy engine blocks the hostPath and CAP_CHOWN pods instead of moving them

Proposed design

Problem statement

The llm Namespace holds the gateway with the provider keys and the spend database. The Ollama DaemonSets need a hostPath model store and a CAP_CHOWN initContainer, so llm cannot enforce restricted Pod Security. dan-petty/homelab#290 moves Ollama to an ollama Namespace and sets llm to restricted. This item changes the product files that name the Ollama Services in llm: the default URLs, gpu_matrix.json, the devcontainer endpoint, the port-forward, the specs and the tests. Both changes must land together.

Acceptance criteria

Requirement: CLI default Ollama URLs name the ollama Namespace

DEFAULT_OLLAMA_CLUSTER_URL and DEFAULT_OLLAMA_EMBEDDING_CLUSTER_URL SHALL name the ollama Namespace.

Scenario: Default URL test

  • WHEN uv run pytest tests/ai/rag/test_rag_embedding_urls.py -q runs
  • THEN The run passes, and the new test asserts that each default URL ends with .ollama.svc.cluster.local:11434.

Requirement: Ollama port-forward targets the ollama Namespace

The Ollama port-forward of the k8s command group MUST target the ollama Namespace.

Scenario: Port-forward target test

  • WHEN uv run pytest tests/commands/k8s/test_k8s.py -q runs
  • THEN The run passes, and the new test asserts that the Ollama port-forward holds the namespace ollama.

Requirement: Devcontainer Ollama endpoint names the ollama Namespace

.devcontainer/devcontainer.json MUST set ollama.endpoint to the ollama Namespace URL in the vscode and antigravity settings.

Scenario: Devcontainer endpoint lines

  • WHEN git grep -c 'ollama-48gib.ollama.svc.cluster.local' -- .devcontainer/devcontainer.json runs at the head of the branch
  • THEN The command prints .devcontainer/devcontainer.json:2 and exits 0.

Requirement: No tracked file names an Ollama Service in the llm Namespace

No tracked file SHALL name an Ollama Service with the llm Namespace.

Scenario: Repository invariant

  • WHEN git grep -nE 'ollama-[0-9]+gib\.llm\.svc\.cluster\.local' -- . ':!CHANGELOG.md' ':!openspec/changes/archive' runs at the head of the branch
  • THEN The command prints no line and exits 1.

Requirement: Pending a person after the merge

A person MUST merge this change in the same window as dan-petty/homelab#290, and the Ollama Service MUST answer in the ollama Namespace.

Scenario: Ollama Service answers in ollama

  • WHEN kubectl -n ollama run ollama-probe --rm -i --restart=Never --image=curlimages/curl -- curl -fsS http://ollama-48gib:11434/api/tags runs after both merges
  • THEN The command prints the JSON model list and exits 0.

Existing Tool Considered

The alternatives check of 2026-11-25 in the issue body gives verdict none and names no tool; its Lacks: list holds the file edits that no tool does. The product part is a set of string edits in tracked files, so this change builds no code and has no build cost and no elapsed time beyond those edits.

Key questions

  • Which tracked files name an Ollama Service in the llm Namespace?: src/devops_cli/config/defaults.py:159 and src/devops_cli/config/defaults.py:166 hold the two default cluster URLs. .devcontainer/devcontainer.json sets ollama.endpoint to http://ollama-48gib.llm.svc.cluster.local:11434 in the vscode and antigravity settings. tests/ai/rag/test_rag_embedding_urls.py compares the settings with the defaults, and openspec/specs/configured-service-urls/spec.md holds the requirement text. The issue body also names gpu_matrix.json, the Ollama port-forward in commands/k8s/ and the specs and tests. The git grep criterion covers each tracked file that this answer does not name. [sources: src/devops_cli/config/defaults.py:159, src/devops_cli/config/defaults.py:166, .devcontainer/devcontainer.json, tests/ai/rag/test_rag_embedding_urls.py, openspec/specs/configured-service-urls/spec.md]
  • Which DNS form do the default Ollama URLs and the devcontainer endpoint use after the move?: Keep each Service name and change the namespace segment to ollama, so each name is <service>.ollama.svc.cluster.local:11434. (best practice) [sources: .devcontainer/devcontainer.json, src/devops_cli/config/defaults.py:159]
    • Chosen: Namespace-qualified DNS in ollama. The cluster DNS name form is <service>.<namespace>.svc.cluster.local, and the homelab change moves the Services to ollama.
    • Rejected: Keep the llm names. The Services leave llm, so the names stop resolving, and llm must enforce restricted.
    • Rejected: Short Service name with no namespace. The gateway runs in llm and the Ollama pods run in ollama, so a short name resolves in the wrong Namespace.
  • Does the devcontainer change apply to both customization blocks?: Yes. .devcontainer/devcontainer.json holds ollama.endpoint in the vscode settings and in the antigravity settings, and both hold the llm URL. [sources: .devcontainer/devcontainer.json]
  • Does this item fold in fix(k8s): admit only the gateway to the Ollama pods #3583, or keep it as a dependency?: Keep fix(k8s): admit only the gateway to the Ollama pods #3583 as a dependency and do not fold it in. One item delivers one change, and fix(k8s): admit only the gateway to the Ollama pods #3583 holds its own acceptance criteria. (best practice) [sources: CONTEXT.md]
  • Does the git grep invariant cover the historical changelog and the archived changes?: No. Exclude CHANGELOG.md and openspec/changes/archive/ with pathspecs. A changelog line and an archived change record the past, and this change edits neither. (best practice) [sources: CHANGELOG.md, CONTEXT.md]
    • Chosen: Exclude the history files with pathspecs. A historical changelog line or an archived change would fail the criterion, and this change must not edit them.
    • Rejected: Grep the whole tree. It fails on a historical record that this change must not edit.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#3583

Activity

  1. added
    source/agent
    on Nov 12, 2026
  2. added
    type/bug
    scope/k8s
    status/new
    value/high
    effort/high
    on Nov 12, 2026
  3. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 12, 2026
  5. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Owner question: Who confirms on the homelab cluster that llm enforces restricted and that every llm pod runs after the change? (a person decides)

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  6. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (9)

    Tools considered:

    Searches run:

    • Kubernetes Pod Security Admission enforce restricted namespace label, results: 5
    • Kyverno enforce restricted pod security standards namespace policy, results: 5
    • kyverno policy engine github, results: 5
    • Pod Security Admission restricted profile documentation kubernetes.io, results: 5
    • kube-linter check pod securityContext restricted, results: 5
    • pod-security-admission restricted, results: 5
    • Kyverno kubernetes policy engine pod security restricted, results: 5
    • kubernetes.io documentation pod security standards restricted profile, results: 5
    • kube-linter static analysis kubernetes yaml manifests, results: 5

    Sources:

  7. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Owner question: See the first point of Open questions in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  8. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies and Watched files in the section Proposed design of the body.

  9. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p2-mediumscope/k8ssource/agentstatus/newtype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions