dcg

Kustomize

kubernetes.kustomize

Protects against destructive Kustomize operations when combined with kubectl delete or applied without review

  • 3blocking rules
  • 1safe patterns
  • 3Critical
~/.config/dcg/config.toml
[packs]
enabled = ["kubernetes.kustomize"]

Evaluated when a command contains kustomize, kubectl.

Blocking rules

Each rule ID is kubernetes.kustomize:<name>. Use it in allowlists and [policy.rules].

  1. kubectl-delete-k

    Critical

    kubectl delete -k removes all resources defined in the kustomization. Use --dry-run first.

    Explanation
    kubectl delete -k removes all resources defined in a kustomization directory. This is a convenient but dangerous shorthand: - All resources in kustomization.yaml are deleted - Includes base resources and all overlays - May include namespaces, PVCs, and other critical resources - No confirmation prompt by default Safer alternatives: - kubectl delete -k <dir> --dry-run=client: Preview what will be deleted - kubectl kustomize <dir>: Review manifests before deleting - kubectl get -k <dir>: List resources that would be affected
  2. kubectl-kustomize-delete

    Critical

    kubectl kustomize | kubectl delete removes all resources in the kustomization.

    Explanation
    Piping kubectl kustomize to kubectl delete removes ALL resources defined in the kustomization directory. This is equivalent to kustomize build | kubectl delete: - Entire application stack can be deleted - Base and overlay resources are all affected - Includes resources from remote URLs if referenced - Order of deletion may cause cascading failures Safer alternatives: - kubectl kustomize <dir>: Review manifests first - kubectl delete --dry-run=client -k <dir>: Preview deletion - kubectl diff -k <dir>: Compare with cluster state
  3. kustomize-delete

    Critical

    kustomize build | kubectl delete removes all resources in the kustomization.

    Explanation
    Piping kustomize build to kubectl delete removes ALL resources defined in the kustomization directory. This can delete entire applications: - Every resource in kustomization.yaml and its bases is deleted - Overlays may include resources you didn't expect - Deployments, services, configmaps, secrets all removed - No confirmation or preview by default Safer alternatives: - kustomize build <dir>: Review manifests first - kustomize build <dir> | kubectl delete --dry-run=client -f -: Preview - kustomize build <dir> | kubectl diff -f -: Compare with cluster state

Safe patterns

Checked first. A command that matches one is never blocked by this pack.

  • kustomize-dry-run