Safeguard
Developer Tools•

Why review rendered Kustomize output and not just the patch?

A small Kustomize patch can change security settings in a base. Render the overlay with kubectl kustomize, then policy check and diff the result.

Safeguard Security Team
3 min read

Because a patch shows only the edit, not the result. Kustomize merges patches into base resources, so a few lines in an overlay can change a securityContext, an image or a replica count in ways the patch file does not make obvious. Render with kubectl kustomize, then policy check and diff the final YAML.

How Kustomize builds the final manifests

Kubectl supports Kustomize directly. The Kubernetes documentation shows two commands:

  • kubectl kustomize DIR prints the resources found in a directory containing a kustomization file.
  • kubectl apply -k DIR applies them.

A kustomization lists resources, can generate ConfigMaps and Secrets, and applies patches using strategic merge or JSON 6902 through the patches field. Patches may be a file or an inline string and can target one or many resources. Generated ConfigMaps get a name suffix derived from content, which you can see in the rendered output.

Where review goes wrong

What reviewers seeWhat can be hidden
A three line patch to the deploymentThe merged result has a different securityContext than the base intended
A new overlay directoryA copy of the base with different image or limits
A generator entryA ConfigMap or Secret with content pulled from a file
A patch targeting many resourcesChanges applied to every matching object, not just the one you were thinking of

Reviewers read what changed in the pull request. The output of the build is what runs in the cluster.

A review process that works

  1. Render in CI for every overlay: kubectl kustomize overlays/prod > prod.yaml.
  2. Run policy checks on the rendered file. No privileged containers, no hostPath, allowPrivilegeEscalation false, runAsNonRoot, image digests, resource limits.
  3. Diff against live with kubectl diff -k overlays/prod. See using kubectl diff.
  4. Compare overlays to each other. A diff between the staging and production render shows exactly where they differ, which is often where a security setting got dropped.
  5. Store the rendered output as a build artifact so what you checked is what you deploy.

Secrets and generators

Kustomize can generate Secrets from literals or files. If the source is a plaintext file in the repository, you have recreated the problem of secrets in version control. Reference an external secret store instead, and keep generators for non sensitive configuration.

Try it yourself

Click through it at your own pace, or open it full screen.

See how the gate evaluates the change set as a whole. Your Kustomize build output should be the thing that gate evaluates.

Quick check

What is the quickest way to see what an overlay produces?

Run kubectl kustomize on the overlay directory. It prints the final resources.

Should policy checks run on the base or the overlay?

On the rendered result of each overlay, because that is what gets applied.

Safeguard runs policies and gates on pull requests, so a failed rule can hold a merge, and its dependency and SBOM scanning covers the packages your infrastructure code pulls in. You can try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.