Skip to content

fix(k8s): deploy-stack applies the monitoring namespace perimeter #913

Closed

Description

@dan-petty

Problem

k8s/monitoring/networkpolicy.yaml defines monitoring-default-perimeter. It is the default-deny ingress and egress policy for every pod in namespace monitoring (podSelector: {}, lines 9-12). Its exceptions are:

  • the namespace's own pods;
  • Traefik in kube-system on the UI and API ports (lines 17-47);
  • the otel namespace on 9090 and 4040 (lines 48-57);
  • scrape, push and API egress to kube-system, llm, otel, cloudflared and logging, and to the internet on 80 and 443 (lines 58-147).

devops k8s deploy-stack never applies it.

The same was true at the v0.2.23 and v0.2.24 tags. Neither root kustomization lists the policy, and neither _MANIFESTS_BY_STACK names it.

On a cluster built by deploy-stack alone, no policy selects the monitoring pods. Every pod in the cluster can reach them, including:

  • Prometheus, which has no authentication and accepts remote writes (k8s/monitoring/prometheus-values.yaml:8-9);
  • Grafana, which admits anonymous Viewers (k8s/monitoring/grafana-values.yaml:32-34);
  • Alloy;
  • Pyroscope.

The LLM gateway's policy has the same gap (#795).

When this item was filed, homelab-k3s ran a monitoring-default-perimeter. It did not come from deploy-stack, because no deploy-stack path names the file, so a person applied it by hand. The original body cited the missing app.kubernetes.io/managed-by label as proof. The label proves nothing either way: the file sets only app.kubernetes.io/part-of, and kubectl apply adds no managed-by. Because the policy was applied by hand, it can differ from the file.

What changed since this item was filed (2026-10-01)

Acceptance criteria

Key questions

  1. Root kustomization or _MANIFESTS_BY_STACK["infra"]? Proposed: the root kustomization. The original reason, that the root kustomization is "the infra stack's base", is not accurate: deploy-stack applies it for every --stack value (stack_lifecycle.py:770-772). It is still the better place. It creates namespace monitoring (k8s/namespaces.yaml) on every run, so the perimeter is created in the same kubectl apply as the namespace, before any chart installs into it. fix(k8s): deploy-stack applies the monitoring services alloy, grafana and port-forward use #912 also put its monitoring resources there. The trade-off is that the llm and logging perimeters stay in _MANIFESTS_BY_STACK (:153, :162), so perimeters live in two places. The guard test accepts either place. Moving those two is out of scope.
  2. Does this item also deploy fix(k8s): deploy-stack applies the llm gateway policy and narrows its egress #795's gateway policy? No (proposed). fix(k8s): deploy-stack applies the llm gateway policy and narrows its egress #795 must first change that policy, by dropping the ollama-volta-1 selector and deriving the egress test from the configmap, and it is in v0.2.29 too. The guard test exempts the gateway policy under fix(k8s): deploy-stack applies the llm gateway policy and narrows its egress #795, and whichever of the two items lands second deletes that exemption.
  3. What about the argocd and otel perimeters, which deploy-stack also never applies? Not in this item (proposed). Neither can be applied as written. ArgoCD would lose the API server, and the otel-metrics route would break. Each also needs its own live check, and a mistake in ArgoCD's policy stops GitOps sync. They go into one follow-up P1 issue, filed when this body is adopted, and the guard test exempts both under that issue. The owner chooses its milestone.
  4. Order against fix(k8s): monitoring ingress admits 0.0.0.0/0, qdrant ignores its security context, and single-ollama leftovers remain #953, feat(k8s): the roadmap service runs in the cluster's devops namespace, reachable from outside only on /webhooks/github #1083 and fix(k8s): pod logs reach loki once and labelled, with alloy as the only shipper (remove fluent-bit) #548? This item lands after all three (proposed). fix(k8s): monitoring ingress admits 0.0.0.0/0, qdrant ignores its security context, and single-ollama leftovers remain #953 and feat(k8s): the roadmap service runs in the cluster's devops namespace, reachable from outside only on /webhooks/github #1083 edit this file, and fix(k8s): pod logs reach loki once and labelled, with alloy as the only shipper (remove fluent-bit) #548 adds a test that reads it. fix(k8s): monitoring ingress admits 0.0.0.0/0, qdrant ignores its security context, and single-ollama leftovers remain #953 is in v0.2.25 and the other two are in v0.2.26, so the release order already gives this. Landing before fix(k8s): monitoring ingress admits 0.0.0.0/0, qdrant ignores its security context, and single-ollama leftovers remain #953 would make deploy-stack apply a policy that still admits every pod through the 0.0.0.0/0 peer. The person-run diff has to run against the file after fix(k8s): monitoring ingress admits 0.0.0.0/0, qdrant ignores its security context, and single-ollama leftovers remain #953's and feat(k8s): the roadmap service runs in the cluster's devops namespace, reachable from outside only on /webhooks/github #1083's edits. If feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741 or feat(k8s): the roadmap service runs in the cluster's devops namespace, reachable from outside only on /webhooks/github #1083 slips past this item, it adds its own exemption to the guard test.
  5. If the live policy and the file differ, which one wins? The file (proposed). The repository is the source. Which copy is live depends on whether a person has run feat(k8s): the roadmap service runs in the cluster's devops namespace, reachable from outside only on /webhooks/github #1083's setup step that applies this file by the time this item is built. If so, the live copy matches the file as of that apply, including port 4040, fix(k8s): monitoring ingress admits 0.0.0.0/0, qdrant ignores its security context, and single-ollama leftovers remain #953's removal of the 0.0.0.0/0 peer and feat(k8s): the roadmap service runs in the cluster's devops namespace, reachable from outside only on /webhooks/github #1083's devops rule. If not, it is the older hand-applied copy, which may lack port 4040 (feat(k8s): integrate grafana pyroscope to the monitoring stack #943) and still carry the 0.0.0.0/0 peer. The person-run diff settles it either way. A live-only rule is carried into the file only if the person-run checks show the stack needs it, with a comment saying why.
  6. Should test_kustomization_includes_networkpolicy (tests/test_k8s_network_policies.py:24-35) change? No (proposed). It guards the per-namespace kustomizations, and whether those stay a deploy path is feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755's decision. The new guard test covers deploy-stack.
  7. What changes when feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755 lands first (v0.2.27)? (proposed)

Depends on: #953 (v0.2.25) and #1083 (v0.2.26), which change this file first. #741 and #1083 add the devops policies that the guard test exempts. #755 (v0.2.27) lands before this item.
Related: #548 (v0.2.26, test that pins two of this file's egress rules), #795 (gateway policy, v0.2.29), #820 (vLLM profiles policy), #755 (v0.2.27: Argo CD syncs every stack from the current release branch), #912 (root-kustomization precedent and _kustomize_services), #943 and #977 (Pyroscope), the argocd and otel perimeter follow-up (to be filed).

Found while fixing #912 from Copilot's review of release PR #905.

Scope added 2026-10-02: the argocd and otel follow-up in key question 3 has not been filed, and it should own one more defect in each file. Ingress rule 2 of k8s/otel/networkpolicy.yaml admits ipBlock: 0.0.0.0/0 on TCP 16686 (:31-32). It sits next to a kube-system/Traefik peer (:25-30) that already serves the jaeger-ingress route (k8s/ingress/ingress-routes.yaml:436-458). Ingress rule 2 of k8s/argocd/networkpolicy.yaml admits only 0.0.0.0/0, on 8080 and 443 (:17-25). It has no Traefik peer, although argocd-ingress routes Traefik to argocd-server (ingress-routes.yaml:412-434), and the server is a NodePort (k8s/argocd/values.yaml:22-25). kube-router matches the CIDR against pod addresses (#953), so once applied, either rule admits every pod in the cluster. All four branch reviews of release/v0.2.25 (sessions 20261002-142541 to 20261002-200610) reported the otel rule. Neither file is applied today, so both defects are latent. ArgoCD's fix needs the follow-up's live check.

  • (person-run) Before this item merges, the argocd and otel follow-up is filed and the guard test's argocd and otel exemptions cite its number. Its body puts both 0.0.0.0/0 ingress peers in scope: otel keeps its Traefik peer, and ArgoCD gains a Traefik peer plus whatever its NodePort access needs, as its live check settles.

Monitoring cleanup amendment (2026-10-03): live drift

The live monitoring-default-perimeter (created 2026-09-30, from a kubectl last-applied annotation) still has an ingress rule from ipBlock 0.0.0.0/0 plus Traefik. It covers ports 80, 3000, 8080, 8081, 8082, 9090, 9100, 9400 and 12345. That is the state #953 removed from the repo, whose ingress comment says "No ipBlock". Because deploy-stack never applies this file, #953's fix never reached the cluster.

Acceptance criteria (added).

  • Pending a person: after the deploy, kubectl get networkpolicy -n monitoring monitoring-default-perimeter -o yaml has no ingress ipBlock.
  • The k8s-monitoring alloy-operator's pre-delete hook Job still reaches the API server under the deployed perimeter.

Grouping. Related to #1128 (step 1 of its order), not a child. Scope and v0.2.29 placement are otherwise unchanged.

Update 2026-10-08

Delivered on fix/913-deploy-stack-monitoring-perimeter, checked against release/v0.2.29 at 910b823. The delivered scope differs from the body as follows.

Deploy path (replaces AC1, KQ1 and KQ7's ownership bullet)

  • A native devops k8s deploy-stack --stack infra (or all) applies the policy through _KUSTOMIZATIONS_BY_STACK["infra"] = monitoring, previously monitoring/dashboards (fix(k8s): a native deploy-stack applies the grafana dashboards again #1297).
  • It runs right after the root kustomization creates the namespace, before Secrets and any chart. It applies exactly what Argo CD's monitoring Application syncs: the perimeter plus the dashboards.
  • k8s/kustomization.yaml and k8s/monitoring/kustomization.yaml are unchanged:
  • --stack llm|logging|devops do not apply the policy, since they install nothing in monitoring. AC1's "every --stack value" is dropped.

Corrected premises

Guard test (test_every_network_policy_has_a_deploy_stack_path_or_an_owned_exemption)

Teardown

  • No code change. --stack all (kubectl delete -k k8s) and --stack infra (kubectl delete namespace monitoring) remove the policy, and a parametrized test now pins both.

Person-run checks

KQ3

Activity

  1. added
    type/security
    scope/k8s
    priority/p2-medium
    on Oct 1, 2026
  2. added
    priority/p1-high
    and removed
    priority/p2-medium
    on Oct 2, 2026
  3. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Grooming (2026-10-02): Priority p2-medium → p1-high.

    Checked against the code at the release/v0.2.25 tip.

  4. added this to the v0.2.29 milestone on Oct 2, 2026
  5. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Placed in v0.2.29 on 2026-10-02. v0.2.29 holds P1 work that has to land before v0.3.0, which v0.2.25 to v0.2.28 had no room for. Backlog P1 items were ranked by Value, then Effort, with defects and security fixes first at a tie. This item ranked in the top ten, and two of the release's twelve slots stay open for P1 items that surface before then.

  6. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Refined to Ready on 2026-10-02 for v0.2.29. The body was checked claim by claim against release/v0.2.25 at 9c879ae, and a second agent then tried to refute it; every major objection was resolved in a revision. Cited lines were updated for code that moved, and the scope was corrected where merged work changed it. Acceptance criteria were tightened so each fails on the current code, and every key question now has a proposed answer.

  7. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    The roadmap namespace and policy are now devops (#741: devops-default-perimeter; #1083: roadmap-service-ingress). #755 (v0.2.27) gives this file an Argo CD deploy path first and syncs otel's policy (live since 2026-10-02, differing only by port 4040); argocd's stays exempt under the KQ 3 follow-up, which is still unfiled.

  8. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Consolidation note (2026-10-03): #818 is merged into #1104, which adds a repo-only test that no plain manifest declares a Service in a namespace a Helm release installs into. This item adds the repo-wide NetworkPolicy deploy-path guard. Whichever of the two lands second folds the other's check into one manifest-ownership test, with one exemption map. Scope and placement are unchanged.

  9. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1380, merged into release/v0.2.29 as 3e2c489.

    Closes #913

    • Deploy path: a native deploy-stack --stack infra|all now applies all of k8s/monitoring (the namespace perimeter and the dashboards) right after the root kustomization and before any chart, through _KUSTOMIZATIONS_BY_STACK["infra"] = "monitoring". That matches what Argo CD's monitoring Application syncs. The root kustomization is unchanged, which keeps fix(k8s): resolve argocd application out-of-sync and manifest generation failures #1279's fix for the base/monitoring SharedResourceWarning.
    • Guard test: tests/test_k8s_network_policies.py checks every NetworkPolicy under k8s/ against what deploy-stack --stack all applies, with an exemption map in which each entry names its owner. Before the fix it failed only for monitoring-default-perimeter. The argocd and otel perimeters are exempted under fix(k8s): the argocd and otel perimeters admit 0.0.0.0/0 ingress and deploy-stack applies neither #1371, which also owns their 0.0.0.0/0 ingress peers.
    • Rendering: tests/k8s_manifests.py renders kustomizations with kubectl kustomize, replacing the hand-written service list. A parametrized teardown test pins the delete commands.
    • Docs: k8s/README.md and the monitoring kustomization comments, including a warning that CRD kinds must not be listed in the monitoring kustomization, which is now applied before any chart installs CRDs.

    uv run devops ci passes locally.

    Merge coordination: the guard test exempts ("llm", "llm-gateway-perimeter") under #795 (PR #1369). Whichever of the two PRs merges second deletes that exemption.

    Pending a person: a kubectl diff of the perimeter before merge, and the functio…

    10 file(s) changed.

    How it was verified

    Check runs at 16b59bd:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Service Image: skipping
    • Static Analysis: pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • Analyze (actions): pass
    • DevContainer Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-913-deploy-stack-applies-the-monitoring-perimeter.md:

    • A native deploy-stack --stack infra (and all) applies k8s/monitoring, the perimeter and the dashboards, right after the root kustomization. test_native_deploy_stack_infra_applies_the_monitoring_kustomization pins the kubectl apply -k targets [k8s, k8s/monitoring]. test_deploy_stack_dry_run_lists_the_kustomizations_its_stacks_apply lists k8s/monitoring for infra and all, and nothing for llm. Both are in tests/test_k8s.py. The Argo CD path and the root kustomization are unchanged.

    • teardown-stack removes the perimeter with its namespace without new code. test_teardown_stack_removes_the_monitoring_perimeter_with_its_namespace[all|infra] asserts kubectl delete -k k8s --ignore-not-found and kubectl delete namespace monitoring --ignore-not-found.

    • test_every_network_policy_has_a_deploy_stack_path_or_an_owned_exemption (tests/test_k8s_network_policies.py) reads every NetworkPolicy under k8s/ and compares it with the set deploy-stack applies. One tuple assertion checks three lists, all empty:

      • policies neither applied nor exempted;
      • exempted policies that are applied;
      • exempted policies missing from the file their exemption names.

      Each exemption names its file and the issue or path that owns it:

    • The tests use structural tuple assertions and reach no cluster, DNS or network. The only process they run is kubectl kustomize on repository files.

    • The alloy-operator pre-delete hook's API-server egress is pinned offline by test_monitoring_network_policy_alloy_egress_rules (6443 through the ipBlock, tests/test_k8s_logging_stack.py). The file has no ingress ipBlock (test_monitoring_ingress_admits_no_world_cidr).

    • changelog.d/913.md records the change under ### Security; CHANGELOG.md and docs/ROADMAP.md are not edited.

    • uv run devops ci passes.

    • Pending a person, before merge: kubectl --context homelab-k3s diff -f k8s/monitoring/networkpolicy.yaml prints nothing, because Argo CD's monitoring Application syncs this file with self-heal. Settle any difference: carry it into the file with a comment saying why, or drop it. A live-only rule is carried only if the checks below show the stack needs it.

    • Pending a person, on homelab-k3s under the Argo-synced perimeter:

      • kubectl --context homelab-k3s -n argocd get application monitoring shows Synced and Healthy.
      • kubectl --context homelab-k3s -n monitoring get networkpolicy monitoring-default-perimeter -o jsonpath='{.spec.ingress[*].from[*].ipBlock}' prints nothing.
      • kubectl --context homelab-k3s -n argocd get applications shows Healthy for every Application that installs into monitoring.
      • kubectl --context homelab-k3s -n monitoring logs -l app.kubernetes.io/name=alloy-metrics --since=1h and the same for alloy-logs show no write errors.
      • Grafana's Prometheus, Loki, Jaeger and Pyroscope datasources pass "Save & test".
      • kubectl --context homelab-k3s -n otel logs -l app.kubernetes.io/name=opentelemetry-collector --since=1h shows no failed sends to Alloy on 9090.
      • Traefik's routes to Grafana, Prometheus and Alloy answer.
      • The Prometheus query up == 0 returns no series.
      • devops k8s configure-urls --addressing proxy --context homelab-k3s still reaches Grafana and Prometheus while they run on the control-plane node (fix(k8s): monitoring ingress admits 0.0.0.0/0, qdrant ignores its security context, and single-ollama leftovers remain #953's caveat, k8s/README.md).
      • The next time the k8s-monitoring release is removed, its alloy-operator pre-delete hook Job completes: kubectl --context homelab-k3s -n monitoring get jobs.
    • Pending a person, on a cluster without Argo CD whose CNI enforces NetworkPolicy:

      • Run uv run devops k8s deploy-stack --stack infra --context <context>.
      • kubectl --context <context> -n monitoring get networkpolicy monitoring-default-perimeter lists the policy.
      • The checks above pass, with Helm's --wait completing for every monitoring release.
  10. added a commit that references this issue on Oct 8, 2026
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

    priority/p1-highscope/k8stype/security

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions