Skip to content

feat(k8s): manifest and admission policy for planner sandboxed run job #4003

Closed

Description

@dan-petty

Problem or Motivation

The roadmap planner reads files and runs no commands. As recorded in ADR 0018 (docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, #3242), a plan can rest on a false premise that only a command run shows. The planner needs a sandboxed environment to run read-only commands without touching cluster secrets, writable volumes, or the network.

Proposed Solution & Architectural Design

Add the Kubernetes manifest and admission policy entries for the planner sandboxed run Job according to ADR 0018:

  1. Create a suspended CronJob manifest that holds the pod spec with the seven isolation controls:
    • A temporary HOME on an emptyDir volume with a size limit, plus an emptyDir for /tmp.
    • Mount of a ConfigMap created from devops-cli-config with credentials stripped, and no secret envFrom.
    • Read-only volume mount of the staged commit clone (readOnly: true).
    • NetworkPolicy selecting the Job pod that denies all egress traffic, including DNS.
    • Resource limits: 1 CPU, 2Gi memory limit, and activeDeadlineSeconds: 120.
    • Security context: runAsNonRoot: true, runAsUser: 1000, runAsGroup: 1000, allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, and drop all capabilities.
    • Pod spec setting: automountServiceAccountToken: false.
  2. Grant get permission on the CronJob resource to the roadmap-service-jobs Role.
  3. Add the run Job rules and constraints into the ValidatingAdmissionPolicy roadmap-service-jobs in k8s/devops/roadmap-service/admissionpolicy.yaml and into the admission gate check.

Depends on: #3242 (ADR 0018).

Target Subsystem

Kubernetes & Minikube Automation

Existing Tool Considered

Kubernetes CronJob templates and native Job controllers cover the pod lifecycle. ValidatingAdmissionPolicy enforces the container constraints natively in Kubernetes without extra admission webhooks. The cost to wire the manifest and admission policy is approximately 12,000 tokens and 0.5 elapsed days.

Source: #3958

Proposed design

Problem statement

The planner runs no command, so a plan can rest on a false premise. ADR 0018 gives the planner a run tool that runs one read-only command in a separate Kubernetes Job. That Job needs its manifest and its admission rows before any code creates it. This issue adds the suspended CronJob, the NetworkPolicy, the Role row, the policy rows and the gate check.

Acceptance criteria

Requirement: Suspended CronJob for the planner run Job

The devops stack SHALL hold a suspended CronJob named devops-cli-planner-run that holds the pod spec of the run Job.

Scenario: The CronJob is read from the stack

  • WHEN A test reads k8s/devops/roadmap-service/cronjob-planner-run.yaml
  • THEN The CronJob sets suspend: true, and its Job template sets backoffLimit: 0, restartPolicy: Never, activeDeadlineSeconds: 120 and ttlSecondsAfterFinished.

Requirement: The two emptyDir volumes are the only writable paths

The run Job pod SHALL mount the home and tmp emptyDir volumes with a size limit, and SHALL mount the staged commit claim with readOnly: true.

Scenario: A write outside the read-only copy

  • WHEN A test renders the Job from the CronJob template with build_job of src/devops_cli/k8s/cluster_job.py
  • THEN The pod mounts emptyDir home at /home/devops and emptyDir tmp at /tmp with a size limit, the volume repo is a claim mount with readOnly: true, and no other volume is writable.

Requirement: No credential and no service account token

The run Job container SHALL hold no envFrom of Secret devops-cli and the pod SHALL set automountServiceAccountToken: false.

Scenario: A read of a credential and of the service account token

  • WHEN A test renders the Job and reads its container and pod fields
  • THEN The container holds no envFrom and no valueFrom, the config volume is the ConfigMap devops-cli-config-sandbox, and automountServiceAccountToken is false.

Requirement: The pod runs as UID 1000 with no privilege

The run Job pod SHALL set runAsNonRoot: true, runAsUser: 1000, runAsGroup: 1000, allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, seccompProfile: RuntimeDefault and drop all capabilities.

Scenario: The security context of the pod and of the container

  • WHEN A test renders the Job
  • THEN The pod sets runAsNonRoot, runAsUser, runAsGroup and seccompProfile: RuntimeDefault, and the container sets allowPrivilegeEscalation: false, readOnlyRootFilesystem: true and capabilities.drop: [ALL].

Requirement: The run Job caps CPU and memory

The run Job container SHALL request and limit 1 CPU and 2Gi of memory.

Scenario: The resources of the run container

  • WHEN A test renders the Job
  • THEN The container sets requests.cpu: 1, limits.cpu: 1, requests.memory: 2Gi and limits.memory: 2Gi.

Requirement: The NetworkPolicy denies all egress of the run Job pod

The stack SHALL hold a NetworkPolicy that selects the run Job pod and admits no egress, DNS included.

Scenario: The egress rules of the run Job pod

  • WHEN A test reads k8s/devops/roadmap-service/networkpolicy-planner-run.yaml
  • THEN The policy selects the pod label app.kubernetes.io/name: devops-cli-planner-run, sets policyTypes: [Egress] and holds no egress rule.

Requirement: The Role allows get on the CronJob

The Role roadmap-service-jobs SHALL allow get on cronjobs of the batch group.

Scenario: The rules of Role roadmap-service-jobs

  • WHEN A test reads k8s/devops/roadmap-service/role.yaml
  • THEN A rule with apiGroups: [batch], resources: [cronjobs] and verbs: [get] exists.

Requirement: The admission policy admits the run Job shape

The ValidatingAdmissionPolicy roadmap-service-jobs SHALL admit the run Job that the CronJob template makes, and SHALL refuse a run Job that breaks a control.

Scenario: The gate check runs the expressions against the run Job

  • WHEN A test runs the expressions of the policy against the Job that build_job renders from the CronJob template
  • THEN The run Job passes, and a run Job with an extra volume, a writable repo mount or an envFrom of Secret devops-cli fails with the policy message.

Requirement: The kustomization holds the new manifests

The kustomization of the roadmap Service SHALL list the new CronJob and NetworkPolicy files.

Scenario: A read of the kustomization

  • WHEN A test reads k8s/devops/roadmap-service/kustomization.yaml
  • THEN The resources list holds cronjob-planner-run.yaml and networkpolicy-planner-run.yaml.

Existing Tool Considered

No alternatives check has run on this issue. Kubernetes CronJob, Job, NetworkPolicy and ValidatingAdmissionPolicy cover the need natively, and the cluster already runs them. They lack a kernel boundary around a run: a defect of the host kernel reaches the pod. gVisor or the kubernetes-sigs/agent-sandbox controller would close that gap, and ADR 0018 accepts the risk for now. The manifest, the NetworkPolicy, the Role row, the policy rows and the gate check cost about 12,000 tokens and 0.5 elapsed days, as the body records.

Key questions

  • Which files hold the admission policy and the gate check that runs its expressions?: The policy is k8s/devops/roadmap-service/admissionpolicy.yaml. The gate check is tests/gate/k8s_checks/job_admission_policy.py, row k8s of devops ci. [sources: k8s/devops/roadmap-service/admissionpolicy.yaml, tests/gate/k8s_checks/job_admission_policy.py, k8s/README.md:682]
  • Which Role grants the roadmap Service its permissions, and does it hold a rule for CronJobs?: Role roadmap-service-jobs in k8s/devops/roadmap-service/role.yaml allows create on jobs, list on pods and get on pods/log. It holds no rule for cronjobs, so this issue adds get on cronjobs. [sources: k8s/devops/roadmap-service/role.yaml, docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
  • Which pod label does the run Job carry?: The run Job pod gets app.kubernetes.io/name: devops-cli-planner-run. The stack admits DNS, the gateway, the collector and public HTTPS to the label devops-cli-job, so the run Job needs a label that no allow policy selects. (best practice) [sources: k8s/devops/roadmap-service/admissionpolicy.yaml, k8s/README.md:628, k8s/devops/roadmap-service/networkpolicy-egress.yaml]
    • Rejected: Keep the label devops-cli-job. The egress rules of the stack admit DNS, the gateway, the collector and public HTTPS to that label, so control 4 fails.
    • Chosen: Use a new label devops-cli-planner-run. No allow policy selects it, so the deny-all egress policy alone applies to the pod.
  • Does the run Job admission go into the existing policy or into a second policy?: Into ValidatingAdmissionPolicy roadmap-service-jobs, as ADR 0018 records. Each expression that differs by Job shape becomes a disjunction keyed on the pod label. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, k8s/devops/roadmap-service/admissionpolicy.yaml, k8s/README.md:682]
    • Chosen: Add the rows to the existing policy. ADR 0018 records this choice, and the gate check already runs the expressions of that policy.
    • Rejected: Add a second ValidatingAdmissionPolicy. It deviates from the ADR and adds a second binding and a second gate case to keep in sync.
    • Rejected: Use a validating webhook. An outage of the webhook blocks the create, and the policy runs in the API server.
  • Which volume holds the read-only clone of the staged commit?: The claim that the Service pod mounts (k8s/devops/roadmap-service/pvc.yaml), mounted read-only as volume repo. The policy pins the claim name and readOnly: true. The claim's access mode must admit a second reader, and on the one-node cluster a ReadWriteOnce claim does. (best practice) [sources: k8s/devops/roadmap-service/pvc.yaml, k8s/devops/roadmap-service/deployment.yaml, k8s/devops/roadmap-service/admissionpolicy.yaml, docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
    • Chosen: Mount the Service claim read-only. The clone already exists there, and the ADR mounts the clone of the staged commit.
    • Rejected: Make a claim for each run. It needs a copy step and code that this issue does not hold.
    • Rejected: Clone in an init container. The policy admits one container and no init container.
  • Which ConfigMap does the config volume mount, and who makes it?: devops-cli-config-sandbox, a copy of devops-cli-config with every key that holds a credential removed. The policy pins that name. A separate issue creates the ConfigMap, because ADR 0018 gives its creation to a person. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, k8s/README.md:628, k8s/devops/roadmap-service/deployment.yaml]
    • Chosen: A credential-free copy named devops-cli-config-sandbox. Control 2 needs the configuration and no credential, and a distinct name keeps the policy able to pin it.
    • Rejected: Reuse devops-cli-config. It holds credentials, and control 2 forbids a credential in the pod.
    • Rejected: Mount Secret devops-cli. Control 2 forbids the Secret in the container.
  • Which image and ServiceAccount does the run Job use?: Image ghcr.io/dan-petty/devops-cli/runner and ServiceAccount devops-cli, as the implement runner uses. The policy pins both. (best practice) [sources: k8s/devops/roadmap-service/admissionpolicy.yaml, k8s/README.md:680, docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
    • Chosen: The runner image and ServiceAccount devops-cli. The image holds the devops command, and the policy already pins the image and the ServiceAccount.
    • Rejected: A separate image for the run. It adds a second image to build, scan and keep.
  • What size limits do the home and tmp emptyDir volumes get?: 512Mi for each volume. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, k8s/README.md:680]
    • Chosen: 512Mi for each volume. The 120 s deadline and 1 CPU bound what a run writes.
    • Rejected: 4Gi for home and 1Gi for tmp. The runner values serve a dependency cache that a run does not use.
  • Does the run Job set PYTEST_XDIST_AUTO_NUM_WORKERS?: No. The resource expression requires the worker count only for the runner shape. (best practice) [sources: k8s/devops/roadmap-service/admissionpolicy.yaml, src/devops_cli/roadmap/implement/implement_size.py]
    • Chosen: A disjunction keyed on the pod label. The run Job runs no test, so the worker count does not apply to it.
    • Rejected: The env var on both shapes. It states a false setting on the run Job.
  • How does the gate check get a run Job to run the expressions against?: It renders the Job from the CronJob template with build_job of src/devops_cli/k8s/cluster_job.py, as the runner case does. [sources: src/devops_cli/k8s/cluster_job.py, tests/gate/k8s_checks/job_admission_policy.py, k8s/README.md:682]
  • What does the CronJob template set for the container args?: A placeholder that the Service replaces for each run, as CronJob devops-cli-runner does. The allow-list builder of the next follow-up supplies the command. [sources: k8s/README.md:680, docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
  • Is ADR 0018 in force?: Yes. The record is on the default branch at docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, and its Status section makes that merge the approval. [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#3242

Alternatives check of 2026-11-09: none.
Tool: none found.

Activity

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

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/k8s. The (k8s) scope of the title gives the scope.
    • Priority: P2-Medium. It enables a new capability but depends on the ADR being finalized and is not a security fix.
    • Value: High. It is the only path to safely run read-only commands for the planner.
    • Effort: Low. The body estimates 0.5 elapsed days for the manifest and policy changes.
    • Related: docs(security): design a sandboxed read-only run tool for the planner #3242, which asks for a different change. #3242 is the ADR that designs the sandboxed run tool; the candidate implements its K8s manifest and admission policy.
  3. added
    priority/p2-medium
    on Nov 7, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 8, 2026
  5. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 1f03ee3 (see proposed design in issue body).

    Moved to new items: #4147.

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

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The issue asks for Kubernetes manifests and admission rows that the repository must write itself. They are a suspended CronJob, a NetworkPolicy, a Role rule, ValidatingAdmissionPolicy expressions and a gate check. The native Kubernetes objects the issue names already cover the need. The only outside tool I found, kubernetes-sigs/agent-sandbox, is active and Apache-2.0. It would replace the pod spec of the run Job with a controller. ADR 0018 defers it to #2695 and keeps the seven controls either way. It would not remove the NetworkPolicy, Role or admission rows this issue adds.

    Tool: none found

    Covers:

    • agent-sandbox gives a Sandbox custom resource and a controller that makes an isolated pod (a possible later replacement for the Job's pod spec)

    Lacks:

    • It is not in the cluster, and the owner has accepted no measurement of it.
    • It does not provide this repository's ValidatingAdmissionPolicy rows, Role rule or gate check.
    • It does not provide the repository's own NetworkPolicy that denies all egress.

    Tools considered:

    Searches run:

    • kubernetes-sigs agent-sandbox controller Sandbox custom resource isolated pod, results: 5

    Sources:

    Checked on 2026-11-09. A person decides what this means for the item. The check changes no label and closes no issue.

  7. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    Dependency of the runtimeClassName change: #5434.

    When this item sets runtimeClassName: gvisor on the run Job of the planner, it depends on #5434. The measurement of #5434 shows that the CPU and memory limits of a pod hold under runsc. Its pull request sets overhead.podFixed of RuntimeClass gvisor to memory 16Mi. Set the class only after that pull request merges. Under the policy of #5447, the owner approves the first workload of the class.

  8. added
    status/in-progress
    and removed
    status/ready
    on Nov 14, 2026
  9. removed
    status/in-progress
    on Nov 14, 2026
  10. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-14 23:53 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/p2-mediumscope/k8ssource/agenttype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions