Lesson 9 of 9 · 28m
Operating GitOps Securely at Scale
Apply least privilege, repository segmentation, signing, multi-cluster design, and disaster-recovery practice so the control plane itself does not become the easiest attack path.
GitOps centralizes operational power. That is the point — and the risk. Whoever can merge to the right branch or impersonate the controller can mutate production. If your threat model worries about direct cluster access but treats the deployment repository as a convenience bucket, you have built a beautifully audited back door. At scale, GitOps is security infrastructure and must be operated that way.
Protect the writable path
Protect main with branch protection, required review, required status checks, no force pushes, signed commits or verified automation identity, CODEOWNERS for production overlays, and separate deploy credentials per cluster. The key question is not whether commits are signed in isolation. It is whether the system can attribute a production-changing merge to a human or controlled automation identity. Bypass permissions for CI should be narrow and reviewed.
Separate powers intentionally
A monorepo can work. Monolithic privilege cannot. Keep application source, deploy config, cluster bootstrap, and secret key material under distinct review and ownership boundaries. Argo CD Projects and Flux tenancy controls help, but repository-level ownership is often the first real boundary. A developer may be allowed to promote checkout-api without being allowed to edit the admission controller that could disable policy enforcement.
Controller RBAC is production power
The service account used by Flux or Argo CD often needs broad write access. Do not casually grant cluster-admin because bootstrap was easier that day. Model what the instance manages:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata: {name: checkout-reconciler, namespace: checkout}
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: [""]
resources: ["services", "configmaps"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]This example is intentionally narrow. Real applications may need more, but every additional resource and verb is part of the blast radius. Multi-tenant clusters should prefer namespace-scoped reconciliation where feasible.
Multi-cluster needs hierarchy, not copy-paste
A fleet usually has shared platform components, regional differences, and cluster-local state. Structure those explicitly:
fleet/platform/{base,overlays/prod-us-east}
fleet/tenants/{base,team-commerce}
clusters/{prod-us-east-1,prod-eu-west-1}Do not encode cluster identity only in secrets on the cluster. If a controller cannot tell which cluster it is supposed to be, bootstrap and recovery become improvisation.
Audit both Git and the cluster
Git history shows declared intent. API audit logs show actual writes. You need both because controllers, humans, webhooks, and automation can interact in ways a commit graph does not fully explain.
Send controller logs and Kubernetes audit logs somewhere durable. During incident response, the question "did this come from Git?" should be answerable without interviewing six people.
Disaster recovery is a GitOps feature
A good bootstrap means a new cluster can become itself from Git:
flux bootstrap github --owner=SudoSecurityOrg --repository=fleet --branch=main --path=clusters/prod-us-east-1Test cluster replacement. Test controller restore. Test secret key restore. Test what happens when the Git host is unavailable — reconciliation should continue from cached source or last-applied state depending on controller behavior, but new changes cannot be fetched. Know which behavior your version provides instead of guessing during an outage.
Field notes
- The controller credential is often equivalent to production administrator access even when individual developers are not.
- Do not let application teams bypass policy by giving them direct write access to namespaces managed by GitOps.
- Bootstrap repositories deserve stricter review than ordinary application repositories.
- Rotate deploy keys and tokens; they are production credentials even when named after robots.
- Practice losing the cluster, not just losing a pod. GitOps pays off when reconstruction is boring.
Was this lesson helpful?