Skip to main content
RunBook Academy

Git, CI/CD & GitOpsCIV · CI/CD Anti-PatternsAutoApply

Unsafe auto-apply — auto-merge without guardrails

Intermediate⏱ ~26 mingit

What you'll learn

  • Distinguish safe auto-apply from unsafe auto-apply and identify the missing controls
  • Identify the four guardrails that must be in place before any automated apply runs
  • Configure environment protection rules, required reviewers, and drift detection in a GitOps controller
  • Design a break-glass procedure for emergency applies that reconciles back into the audit trail

Prerequisites

Verified against Git 2.55.x teaching target; 2.40+ minimum · GitHub Actions continuous service; Aug 2026 documentation baseline · Argo CD v3.5.x teaching target; v3.0+ minimum · Flux v2.9.x · Sigstore Cosign v3.1.x · SLSA v1.2 · OCI Distribution Specification v1.1 · Git LFS v3.7.1 · Kubernetes (cross-course target) 1.36.x

Not yet marked complete on this device.

Auto-apply is one of the most powerful patterns in GitOps and one of the most dangerous when it ships without guardrails. The pattern: a CI pipeline or a GitOps controller watches the repository for changes, and when a change lands on the production branch, the controller applies it. No manual gate. No human review at apply time. The commit is the deployment.

The discipline is not to disable auto-apply. The discipline is to wire it so that the commit has been so thoroughly reviewed, signed, scanned, and reconciled that auto-apply is the natural final step, not a leap of faith.

Four shapes the violation takes

  • Auto-merge on CI green. A repository rule that auto-merges a pull request when CI passes, with no required reviewers, no CODEOWNERS, and no environment protection rule on the deploy job.
  • Auto-deploy on push to main, no approval. A workflow that runs terraform apply or kubectl apply on every push to the production branch, with no manual gate.
  • Auto-sync with self-heal, no drift review. A GitOps controller with automated sync and self-heal, no prune policy, no diff approval.
  • Break-glass apply without reconcile-back. An emergency runbook that applies a hotfix without committing the change back to the repository.
    flowchart LR
        A["auto-merge on CI green"] --> E["Auto-apply with no gate"]
        B["auto-deploy on push"] --> E
        C["auto-sync no approval"] --> E
        D["break-glass no reconcile"] --> E
        E --> F["Production changes without review"]
        E --> G["Drift reverts hotfixes"]
        E --> H["Audit trail breaks"]

All four converge: production changes without the controls that make the change safe.

The four guardrails that must be in place

Auto-apply is safe when four guardrails are wired in unison. Remove any one and the pattern becomes unsafe.

  • Required reviewers and CODEOWNERS. Branch protection requiring N approvals; CODEOWNERS maps paths to owners; the merge button is disabled until the right owners have approved.
  • Required status checks. CI runs plan, lint, scan, and test. The merge button is disabled until each required check is green.
  • Environment protection rules on the deploy job. Reviewer list, wait timer, branch restriction. The deploy job cannot run until the environment’s reviewers have signed off.
  • Drift detection and reconciliation. The GitOps controller reports out-of-band changes; the prune policy decides what to do with deleted resources.

What safe auto-apply looks like

  • Argo CD with automated: selfHeal: true plus a sync window and a manual diff approval. The repository is the source of truth; the diff is visible before sync; the prune policy is explicit.
  • Flux with spec.interval, spec.prune, and a Kustomization whose spec.sourceRef points at a signed commit.
  • Terraform Cloud with auto-apply: true on a workspace whose execution mode is remote and whose run triggers require a successful plan with a saved plan file.
  • GitHub Actions environment with required reviewers, wait timer, and branch restriction on the deploy job.

Production discipline

  1. Auto-apply runs only on thoroughly-reviewed PRs. Required reviewers, required status checks, CODEOWNERS, signed commits.
  2. Environment protection rules gate the deploy job. Reviewer list, wait timer, branch restriction.
  3. Drift detection is configured and reviewed.
  4. Break-glass applies reconcile back. The hotfix is committed to the repository before or alongside the apply.

Cross-course references

  • This course, Part LI (GitOps) - the GitOps reconciliation model that auto-apply depends on.
  • This course, Part XLVIII (Conditional) - environment protection rules and conditional deploy jobs.
  • This course, Part XLI (RunnerSecurity) - runner controls before a deploy job is trusted with production credentials.
  • This course, Part LXXXVII (IncidentGitOps) - break-glass procedures that reconcile back into the audit trail.

Quiz

Knowledge check · 4 questions

  1. Q1. A team wires Terraform Cloud to auto-apply on merge to main. Branch protection exists, but the production workspace has no required reviewers and no run-triggers from a saved-plan artifact. What is missing?

  2. Q2. A break-glass apply is not necessarily acceptable just because the change is small and the operator is senior.

  3. Q3. Name the four guardrails that must be in place before auto-apply is safe.

  4. Q4. Diagnose an unsafe auto-apply configuration and recommend the discipline that makes it safe.

    An Argo CD Application has automated sync and self-heal on the production cluster. The repository holds Kubernetes manifests; the controller syncs on every commit to main; no manual diff approval is required. A junior engineer pushes a manifest change that drops a NetworkPolicy; the controller reconciles; the policy is gone.

Passing score: 75%. Answers are checked in this browser.