Skip to content

fix(k8s): refuse the project-review label on Service Jobs #7402

Done

Description

@dan-petty

Problem

The NetworkPolicies of dan-petty/homelab#276 (plan PR dan-petty/homelab#510) admit the pods with app.kubernetes.io/name: devops-cli-job and app.kubernetes.io/component: project-review in namespace devops to Prometheus (TCP 9090) and Loki (TCP 3100). Loki has no authentication.

The admission policy of the roadmap Service (k8s/devops/roadmap-service/admissionpolicy.yaml:259-268) requires app.kubernetes.io/component: roadmap-stage on the pod of a stage Job and refuses it on other pods. For a Job that is not a stage Job, it accepts every other component value. So ServiceAccount roadmap-service can create a Job whose pod carries project-review and reads all logs of the cluster through Loki.

The project review pods come from the Argo WorkflowTemplate project-review of #4736, not from a Job of the Service.

Done when

  • The admission policy refuses a Job of roadmap-service whose pod template carries app.kubernetes.io/component: project-review.
  • The policy test proves the refusal, and a stage Job and an implement Job are still admitted.

Alternatives check of 2026-11-27: in-use.
The repository already uses this tool.
Tool: kubernetes/kubernetes (https://github.com/kubernetes/kubernetes), Apache-2.0, last activity 2026-11-27, maintained.
Reason: Searches surfaced only container images and docs pages, no separate tool for a label-scoped Job refusal; the built-in CEL admission policy the project already uses closes the gap with one added conjunct, so the issue names the tool.

Covers:

  • CEL expression refuses a named component value on non-stage Job templates
  • Rule sits in the existing policy that already gates Service Jobs
  • Runs in the API server, so no extra controller, CRD or agent

Lacks:

  • No built-in test harness for the denial; the test case is project code
  • Refuses only enumerated values, not unknown component labels
  • No knowledge of NetworkPolicy exposure; the Loki path closes only for this label

Proposed design

Problem statement

The roadmap-service admission policy admits a non-stage Job whose pod template carries app.kubernetes.io/component: project-review. The NetworkPolicies of dan-petty/homelab#276 admit that label to Prometheus and Loki. Loki has no authentication, so the ServiceAccount reads all cluster logs. The change refuses that label on Service Jobs and keeps stage and implement Jobs admitted.

Acceptance criteria

Requirement: Refuse project-review on non-stage Service Jobs

The roadmap-service admission policy SHALL refuse a Job whose pod template sets app.kubernetes.io/name: devops-cli-job and app.kubernetes.io/component: project-review, when the Job is not a stage Job.

Scenario: Non-stage project-review Job is refused

  • WHEN uv run devops ci --check --only k8s runs the policy test case for the non-stage Job with app.kubernetes.io/component: project-review
  • THEN The k8s check passes and the policy test reports that the policy refuses the Job.

Requirement: Keep stage Jobs admitted

The roadmap-service admission policy SHALL admit a stage Job whose pod template sets app.kubernetes.io/name: devops-cli-job and app.kubernetes.io/component: roadmap-stage.

Scenario: Stage Job is admitted

  • WHEN uv run devops ci --check --only k8s runs the policy test case for the stage Job
  • THEN The k8s check passes and the policy test reports that the policy admits the stage Job.

Requirement: Keep implement Jobs admitted

The roadmap-service admission policy SHALL admit a non-stage Job whose pod template sets app.kubernetes.io/name: devops-cli-job and does not set app.kubernetes.io/component to roadmap-stage or project-review.

Scenario: Implement Job with no component label is admitted

  • WHEN uv run devops ci --check --only k8s runs the policy test case for a non-stage Job whose pod template sets only app.kubernetes.io/name: devops-cli-job
  • THEN The k8s check passes and the policy test reports that the policy admits the Job.

Existing Tool Considered

Verdict in-use for kubernetes/kubernetes (ValidatingAdmissionPolicy with CEL), from the alternatives check in the issue body. That block gives what the tool covers and lacks. The change adds one conjunct to the existing non-planner expression in k8s/devops/roadmap-service/admissionpolicy.yaml. It also adds the policy test case that the tool lacks.

Key questions

  • What does the current policy admit for a non-stage Service Job?: The non-planner branch requires app.kubernetes.io/name: devops-cli-job. It then requires variables.stage to equal the presence of app.kubernetes.io/component: roadmap-stage. For a non-stage Job it refuses roadmap-stage and accepts every other component value, including project-review. [sources: k8s/devops/roadmap-service/admissionpolicy.yaml:259-268]
  • Which mechanism enforces the policy?: A Kubernetes ValidatingAdmissionPolicy with CEL. The expression reads variables.planner and variables.stage, which the policy defines. [sources: k8s/devops/roadmap-service/admissionpolicy.yaml:259-268]
  • Where does the change refuse the project-review component?: Add one conjunct to the non-planner CEL expression in k8s/devops/roadmap-service/admissionpolicy.yaml. The conjunct requires variables.stage to be true, or the component to be absent or not project-review. The planner branch, the name check and the stage rule stay unchanged. (best practice) [sources: k8s/devops/roadmap-service/admissionpolicy.yaml:259-268]
    • Chosen: Extend the existing CEL expression. The policy already gates Service Jobs. One conjunct closes the gap and keeps the other paths.
    • Rejected: Add a separate ValidatingAdmissionPolicy. A second policy repeats the same match and adds ordering and maintenance.
    • Rejected: Replace the policy with Kyverno. The project uses the built-in CEL policy. A new controller adds a dependency and no benefit.
  • Should the policy refuse every unknown non-stage component or only project-review?: Refuse only project-review. The issue names that value. The stage and implement paths stay admitted. An allowlist needs proof of every legitimate component and can refuse a valid Job. (best practice) [sources: k8s/devops/roadmap-service/admissionpolicy.yaml:259-268]
    • Chosen: Refuse only project-review. It closes the named Loki path and leaves the stage and implement paths unchanged.
    • Rejected: Allowlist known component values. The issue names no full list. A missing value would block valid Jobs.
    • Rejected: Change the NetworkPolicy only. The issue assigns the fix to the admission policy. The policy gap stays for other consumers.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor
  3. added
    priority/p1-high
    on Nov 27, 2026
  4. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  5. devops-cli-service commented on Nov 27, 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 (7)

    Tools considered:

    Searches run:

    • Kubernetes ValidatingAdmissionPolicy CEL expression deny label on pod template, results: 5
    • Kyverno vs ValidatingAdmissionPolicy built-in admission control no controller, results: 5
    • ValidatingAdmissionPolicy kubernetes documentation, results: 5
    • kubernetes ValidatingAdmissionPolicy cel admission control, results: 5
    • Kyverno policy engine admission controller github, results: 5
    • open-policy-agent gatekeeper validating admission policy alternative, results: 5
    • kubernetes.io docs reference validating admission policy, results: 5

    Sources:

  6. added
    status/ready
    and removed
    status/new
    on Nov 27, 2026
  7. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  8. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  9. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  10. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 06:56 UTC

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/lowpriority/p1-highscope/k8ssource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions