Skip to content

feat(k8s): admission policy for the Service Jobs - #2730

Merged
dan-petty merged 7 commits into
mainfrom
feat/2696-job-admission-policy
Oct 30, 2026
Merged

dan-petty merged 7 commits into
mainfrom
feat/2696-job-admission-policy

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The Role roadmap-service-jobs lets the roadmap Service create any Job in namespace devops. Kubernetes RBAC cannot limit create to a name. Pod Security restricted only warns about a Job and refuses its pod later. So a Job of the Service could name any image, any ServiceAccount of the namespace, any other Secret or any volume that restricted admits.

This change adds a ValidatingAdmissionPolicy and a binding (k8s/devops/roadmap-service/admissionpolicy.yaml). The policy applies only to the user system:serviceaccount:devops:roadmap-service. It never evaluates a Job of another identity. It refuses a Job of the Service unless:

  • the Job has one container, no init container and no command, and the image is the runner repository, alone or with a tag or a digest;
  • the pod uses ServiceAccount devops-cli with no token;
  • envFrom names only Secret devops-cli, and no env entry uses valueFrom;
  • the volumes are only tmp, home and config;
  • the pod has no host namespace, no priorityClassName, no nodeName and no imagePullSecrets;
  • the pod label app.kubernetes.io/name is devops-cli-job, so a Job pod cannot take the label of the Service and the egress to the API server that a NetworkPolicy gives it;
  • the Job has no manualSelector, runs its pod once, never retries, and ends after 7200 seconds at most.

failurePolicy is Fail, and the actions are Deny and Audit. The policy runs in the API server, so no webhook can be down.

A test renders k8s/devops and runs the CEL of the policy with cel-expr-python (a dev dependency) against the Job that CronJob devops-cli-runner makes. It also runs the policy against the same Job changed in one way for each rule. A change of the template that the policy refuses fails in CI. k8s/README.md lists what the policy pins and what it leaves free.

Closes #2696

@dan-petty

Copy link
Copy Markdown
Owner Author

Test results and review record.

  • Full uv run devops ci: all checks pass. The test check took 365 s on a host shared by three agents. The new test file alone runs in about 4 s.
  • devops ci fail-to-pass --base origin/main: 46 tests fail on the base and pass on the branch (tests/test_k8s_job_admission_policy.py and two stack tests).

Review findings fixed:

  • Major: the policy did not pin the pod label. It now requires app.kubernetes.io/name: devops-cli-job. Tests set the label to roadmap-service, to another name, and remove the labels.
  • Minor: priorityClassName, nodeName, imagePullSecrets, container command and manualSelector are now refused. Each has a test.
  • Minor: completions and parallelism must be 1 or not set. Tests cover 2 for each, and the explicit default values pass.
  • Minor: the spec says the actions Deny and Audit. A new test asserts the exact text of the match condition, so the user in the manifest cannot drift from the RoleBinding.

Review points not fixed:

  • hostUsers stays free. The value true is the default, and false only narrows the pod. It is listed as not pinned in k8s/README.md and in the design.

@dan-petty
dan-petty marked this pull request as ready for review October 30, 2026 01:22
@dan-petty
dan-petty merged commit 4be83c2 into main Oct 30, 2026
18 checks passed
@dan-petty
dan-petty deleted the feat/2696-job-admission-policy branch October 30, 2026 01:58
dan-petty pushed a commit that referenced this pull request Oct 30, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.22.0](v0.21.4...v0.22.0)
(2026-10-30)


### Features

* **k8s:** admission policy for the Service Jobs
([#2730](#2730))
([4be83c2](4be83c2)),
closes [#2696](#2696)


### Bug Fixes

* **security:** refuse the uv and npm keys that run a program
([#2749](#2749))
([c5a4596](c5a4596)),
closes [#2673](#2673)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
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.

feat(k8s): an admission policy pins the Jobs the roadmap Service may create

1 participant