# Make Kubernetes Manifests Pass the Restricted Pod Security Standard

Yes. An agent finds every field the restricted Pod Security Standard rejects in your Kubernetes manifests, fixes them, proves it with a policy check and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/enforce-pod-security-restricted/kubernetes/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the manifests as the admission controller would. In a repository shaped like GoogleCloudPlatform/microservices-demo, kubernetes-manifests/ holds one file per service, eleven Deployments plus the `redis-cart` Deployment inside cartservice.yaml, each with a pod `securityContext` setting `runAsNonRoot: true`, `runAsUser: 1000`, `runAsGroup: 1000` and `fsGroup: 1000`, and a container `securityContext` with `allowPrivilegeEscalation: false`, `privileged: false`, `readOnlyRootFilesystem: true` and `capabilities.drop: [ALL]`. That is almost the restricted profile. What is missing everywhere is `seccompProfile`: the profile requires `seccompProfile.type` to be `RuntimeDefault` or `Localhost` at the pod level or on every container, and the absence of a profile is a violation. No file under kubernetes-manifests/ or kustomize/ sets it, while helm-chart/templates/cartservice.yaml already renders it behind a `seccompProfile.enable` value, so the Helm users have it and the plain-manifest users do not.

It fixes each file the same way, so the diff is easy to read: `seccompProfile: {type: RuntimeDefault}` added to every pod-level `securityContext`, which covers the containers and the `frontend-check` init container in loadgenerator.yaml in one line per pod. It then checks the rest of the profile against each spec: volumes are `emptyDir` on redis-cart and nothing else, which the profile allows; no container adds a capability; no `hostNetwork`, `hostPID` or `hostPort`; and `runAsUser` is non-zero. The `release/kubernetes-manifests.yaml` bundle, which carries pre-built public images for people who do not run skaffold, gets the same change so the two copies do not drift.

The proof is a policy check, not a reading. The agent renders the directory with `kubectl kustomize kubernetes-manifests`, since kustomization.yaml lists the files, and runs `kyverno apply` with a ClusterPolicy whose `validate.podSecurity` rule sets `level: restricted` and `version: latest` against the rendered output, before and after the change. The before run lists each pod with the seccomp control it fails; the after run passes. The repository's own kubevious-manifests-ci.yaml workflow validates the same directories with the kubevious CLI, so the agent runs that too, with the same `skip_rules: container-latest-image` the workflow passes, to show nothing else regressed.

Enforcement is a namespace decision, so the agent documents it rather than imposing it. The pull request adds a short section to kubernetes-manifests/README.md showing the three labels, `pod-security.kubernetes.io/enforce: restricted`, `pod-security.kubernetes.io/audit: restricted` and `pod-security.kubernetes.io/warn: restricted`, and notes that enforce applies to the Pods a Deployment creates rather than to the Deployment itself, so a violation shows as a Deployment with zero ready replicas and an event, which is why the warn label should go on first.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Make the Kubernetes manifests in this repository pass the restricted Pod Security Standard. Read kubernetes-manifests/*.yaml, kubernetes-manifests/kustomization.yaml, release/kubernetes-manifests.yaml, kustomize/base/*.yaml, helm-chart/templates/cartservice.yaml and helm-chart/values.yaml, and .github/workflows/kubevious-manifests-ci.yaml first. For every Deployment, including redis-cart and any init container, compare the pod and container securityContext against the restricted profile: allowPrivilegeEscalation false, runAsNonRoot true, runAsUser non-zero, capabilities drop ALL with nothing added back except NET_BIND_SERVICE, seccompProfile.type RuntimeDefault or Localhost, and only the allowed volume types. Fix each violation with the smallest change, preferring one pod-level seccompProfile over a line per container, and apply the same change to the release bundle and the kustomize base so the copies do not drift. Render with kubectl kustomize and check with kyverno apply using a ClusterPolicy with validate.podSecurity level restricted, version latest, before and after; also run the kubevious CLI the way the workflow does. Add a README section with the pod-security.kubernetes.io namespace labels and the order to apply them. Open a pull request that quotes the before and after policy results per workload.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch touching every Deployment file under kubernetes-manifests/, the matching files under kustomize/base/, and release/kubernetes-manifests.yaml, each diff a few added lines under `securityContext`. No image, probe, port, resource request or environment variable changes, and the description says so, because a reviewer reading a twelve-file diff wants to know up front that it is one field.

The description quotes the `kyverno apply` result before the change, with each failing pod and the control it failed, and after it, with every workload passing, then the kubevious result with the same `container-latest-image` rule skipped as in CI. It ends with the three namespace labels and a sentence on applying `warn` and `audit` before `enforce`.

Before merging, a reviewer checks that the rendered output of `kubectl kustomize` still diffs clean against the release bundle apart from the image tags, labels a staging namespace with `warn`, deploys the branch there and reads the events for anything the local check could not see. A follow-up on the same session can turn the labels into a Namespace manifest in the repository.

## Run it on every manifest change

The first run brings the manifests up to the profile; later runs keep them there. An automation on the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` and the prompt `Render the manifests with kubectl kustomize and check them against the restricted Pod Security Standard with kyverno apply; post one review that names each workload and field that fails` starts one run per push to a pull request. The trigger adds the pull request after the prompt and fills in no placeholder; only work by an owner, member or collaborator fires it.

A team that owns several services, each with its own manifests, sends the same prompt to each repository from the terminal, one run per repository, with a `POST /o/{org}/sessions` and that repository in `resources`. Each run reads its own files and opens its own pull request, and a webhook URL on the key reports each `run.completed` with its `session_url`.

## Why run it on Rush?

The restricted profile has a dozen controls across pod, container, init container and volume fields, and the only reliable way to know a set of manifests passes is to run the same evaluation the admission controller runs. The agent renders the manifests and runs that evaluation in its own sandbox, keeps the before and after output in the run's record, and a reviewer reads a result instead of re-deriving it from the YAML.

The record also shows what was not changed. The transcript has the agent reading the Helm template that already carries seccomp, noticing the release bundle is a second copy, and choosing a pod-level field over twelve container-level ones. A reviewer who prefers `Localhost` profiles for one service can say so in a follow-up and the parked sandbox makes that change with the policy check already set up.

## Frequently asked questions

### Why is seccompProfile the only thing missing?

Because the manifests already set runAsNonRoot, a non-zero runAsUser, allowPrivilegeEscalation false, readOnlyRootFilesystem and drop ALL on every container. The restricted profile also requires an explicit seccomp profile and treats its absence as a violation, which is the one control none of the plain manifests meet.

### Will RuntimeDefault break a service?

RuntimeDefault applies the container runtime's default seccomp filter, which blocks a small set of syscalls ordinary servers do not make. The agent cannot run the workloads against a real node in the sandbox, so the pull request asks for a staging deploy with the warn label first and points at the pod events to read.

### Does it change the Helm chart too?

No. helm-chart/templates/cartservice.yaml and its siblings already render seccompProfile behind the seccompProfile.enable value in values.yaml, so Helm users have the control. The change is to the plain manifests, the kustomize base and the release bundle, which had no equivalent.

### Does the pull request turn enforcement on?

No. Enforcement is a label on the namespace, not a field in these manifests, and switching it on before the pods are known to pass stops new pods from starting. The README section gives the labels and the order: warn and audit first, enforce once the staging events are clean.

### How is the result checked without a cluster?

With kyverno apply, whose podSecurity validation implements the same profile the Pod Security Admission controller uses, run against the output of kubectl kustomize. The repository's kubevious workflow is run as well so the pull request shows both tools before and after.

## More Kubernetes jobs

- [Fix the Cause of a Grafana Alert in Kubernetes](https://getrush.ai/run/fix-grafana-alerts/kubernetes/)
- [Fix "no matches for kind Ingress in version extensions/v1beta1" in Kubernetes Manifests](https://getrush.ai/run/fix-no-matches-for-kind-ingress/kubernetes/)
- [Investigate CrashLoopBackOff Pods in Kubernetes](https://getrush.ai/run/investigate-crashloopbackoff/kubernetes/)

## More jobs like this: Hand off a long task

- [Find Dead Code in a Flask App](https://getrush.ai/run/find-dead-code/flask/)
- [Find Dead Code in a Go Project](https://getrush.ai/run/find-dead-code/go/)
- [Fix the babel-preset-react-app private-property-in-object Warning](https://getrush.ai/run/fix-babel-preset-react-app-private-property-in-object-warning/create-react-app/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
