How to Enforce Secret Management in GitOps

Enforce secret management in GitOps with Sealed Secrets, SOPS, External Secrets or Vault, plus push protection, CI checks, admission policies and RBAC.

Aug 16, 2025 - 16:13
Nov 16, 2026 - 04:58
 0  60
TOPICDevOps BasicsPractical guide
How to Enforce Secret Management in GitOps

You enforce secret management in GitOps by never committing plaintext secrets: store either encrypted secrets (Sealed Secrets or SOPS) or references to an external secret store (External Secrets Operator, Vault, Secrets Store CSI Driver) in Git, then back that up with pre-commit and push-time secret scanning, admission policies, RBAC on Secret objects and encryption at rest in etcd.

GitOps works because Git holds the full desired state of a system. Secrets are the one part of that state that cannot be stored as is. This guide compares the patterns that solve the problem, shows minimal working configuration for each, and explains how to make the rules stick so a hurried commit cannot leak a password. It was checked against the Kubernetes, Argo CD, Flux, Sealed Secrets, SOPS and External Secrets documentation in November 2026. If GitOps is new to you, read what GitOps is and how it supports infrastructure automation first.

Key takeaways

  • Kubernetes Secrets are not encrypted by default. The Kubernetes documentation says they are stored unencrypted in etcd unless you enable encryption at rest.
  • Base64 in a Secret manifest is encoding, not protection. A plain Secret YAML in Git is a leaked secret.
  • Argo CD strongly recommends managing secrets on the destination cluster, with an operator, rather than injecting them during manifest generation.
  • Choose encrypted-in-Git (Sealed Secrets, SOPS) for small setups, and reference-in-Git (External Secrets Operator, Vault) when you need central rotation and auditing.
  • Enforcement needs layers: scanning before and at push, CI checks, admission policies and RBAC.
  • Plan for rotation and key backup from the start, not after the first incident.

Why secrets are a special problem in GitOps

In GitOps a controller such as Argo CD or Flux continuously applies what is in a Git repository to a cluster. Everyone with read access to that repository, every clone on a laptop, every CI cache and every fork can see its contents, and Git history keeps old versions forever. A password committed once and deleted in the next commit is still in the history.

Kubernetes adds its own risk. The Secrets documentation warns that Secrets are stored unencrypted in etcd by default, that anyone with API access can retrieve or modify them, and that anyone allowed to create a Pod in a namespace can read every Secret in that namespace, including indirectly through a Deployment. It recommends four minimum steps: enable encryption at rest, apply least-privilege RBAC to Secrets, restrict Secret access to specific containers, and consider external secret store providers.

The two main patterns

Every approach falls into one of two families. Either Git holds the secret in encrypted form and something in the cluster decrypts it, or Git holds only a reference and something in the cluster fetches the value from a dedicated secret store.

ApproachWhat is in GitWhere decryption or fetch happensGood fitWatch out for
Sealed SecretsSealedSecret encrypted with the controller's public keySealed Secrets controller in the clusterSingle or few clusters, simple setupBack up controller keys; values tied to one cluster's key
SOPSFiles with encrypted values, readable keysFlux kustomize-controller, or a tool in the pipelineFlux users, teams already using KMS or ageKey distribution; Argo CD needs a plugin, which it discourages
External Secrets OperatorExternalSecret and SecretStore referencesESO controller fetches from the providerCloud secret managers, central rotationProvider credentials and IAM design
Vault Secrets Operator or Vault AgentCustom resources or annotations referencing Vault pathsOperator or sidecar talks to VaultOrganisations standardised on Vault, dynamic secretsRunning Vault itself well
Secrets Store CSI DriverSecretProviderClass referencesCSI driver mounts values into PodsAvoiding Secret objects in etcdApps must read files; syncing to Secrets is optional

What Argo CD recommends

Argo CD's secret management page distinguishes two styles. Destination cluster secret management, where an operator on the target cluster populates secrets and Argo CD never sees the values, is the style it strongly recommends. Manifest generation based secret management, where a plugin such as argocd-vault-plugin injects values while Argo CD renders manifests, is the style it strongly cautions against. The reasons given are that Argo CD then needs access to the secrets, generated manifests are cached in plaintext in Redis, secret updates become tied to unrelated application syncs, and the approach does not fit the rendered manifests pattern. The tools it lists for the recommended style include Sealed Secrets, External Secrets Operator, the Secrets Store CSI Driver and the Vault Secrets Operator.

Flux takes a different route for SOPS: its kustomize-controller decrypts SOPS-encrypted fields right before applying them, using a key stored as a Secret in the cluster. That is built into Flux and documented as a supported workflow. For a side-by-side look at the two controllers, see how Argo CD and Flux enable declarative deployments.

Pattern 1: Sealed Secrets

Sealed Secrets has two parts: a controller in the cluster and the kubeseal command-line tool. You create a normal Secret locally without applying it, pipe it through kubeseal, and commit the resulting SealedSecret. Only the controller in that cluster holds the private key, so only it can turn the SealedSecret back into a Secret.

kubectl create secret generic db-credentials \
  --namespace payments \
  --from-literal=password='change-me' \
  --dry-run=client -o yaml \
  | kubeseal --format yaml > db-credentials-sealed.yaml

git add db-credentials-sealed.yaml

By default the scope is strict: the name and namespace are part of the encryption, so the SealedSecret cannot be moved to another namespace or renamed. Namespace-wide and cluster-wide scopes loosen this when you need it. The controller renews its sealing key every 30 days by default and keeps old keys for decryption. Renewal is not the same as rotating the secret values themselves, and you must back up the keys, because losing them means losing the ability to decrypt everything in Git. The project's documentation shows how to export them with kubectl get secret -n kube-system -l sealedsecrets.bitnami.com/sealed-secrets-key -o yaml; store that backup somewhere far more protected than the repository.

Pattern 2: SOPS

SOPS is an editor of encrypted files. It encrypts the values in YAML, JSON, ENV and INI files while leaving keys readable, so diffs and reviews still make sense. It supports age, PGP and cloud KMS services from AWS, Google Cloud and Azure among others. SOPS started at Mozilla and became a CNCF Sandbox project in 2023.

With Flux, you store the private key in the cluster and point the Kustomization at it:

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: payments-secrets
  namespace: flux-system
spec:
  interval: 10m0s
  sourceRef:
    kind: GitRepository
    name: platform
  path: ./apps/payments/secrets
  prune: true
  decryption:
    provider: sops
    secretRef:
      name: sops-age

Encrypt only the sensitive fields of a Secret manifest with the age public key before committing:

sops --age=<AGE_PUBLIC_KEY> \
  --encrypt --encrypted-regex '^(data|stringData)$' --in-place db-credentials.yaml

Flux's guide notes that the age key file stored in the sops-age Secret must have a name ending in .agekey. With Argo CD, SOPS normally needs a config management plugin, which falls into the manifest generation style Argo CD discourages.

Pattern 3: External Secrets Operator

External Secrets Operator (ESO) keeps the values out of Git entirely. A SecretStore, or a cluster-wide ClusterSecretStore, describes how to reach a provider such as AWS Secrets Manager, Azure Key Vault, Google Cloud Secret Manager or HashiCorp Vault. An ExternalSecret says what to fetch and which Kubernetes Secret to create. The controller keeps the Secret in sync on a refresh interval.

apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
  name: db-credentials
  namespace: payments
spec:
  refreshInterval: 1h0m0s
  secretStoreRef:
    name: aws-secrets
    kind: ClusterSecretStore
  target:
    name: db-credentials
  data:
  - secretKey: password
    remoteRef:
      key: prod/payments/db
      property: password

Only this reference goes into Git. Rotation happens in the secret manager, and the change flows into the cluster at the next refresh without a commit. The hard part moves to identity: the operator needs credentials to read the store, ideally through workload identity rather than a long-lived key, and those permissions should be scoped per namespace or team.

Pattern 4: Vault and the CSI driver

Organisations that run HashiCorp Vault can use the Vault Secrets Operator or Vault Agent injection to deliver secrets, including short-lived dynamic credentials for databases and clouds. The Kubernetes Secrets Store CSI Driver takes another approach: it mounts secret values from an external provider into Pods as files, which avoids storing them as Secret objects in etcd unless you choose to sync them. Both keep values out of Git and suit teams that need detailed audit trails. For Vault concepts in interview form, see our Vault interview questions.

Enforcing the rules

Choosing a tool does not stop someone from committing a plain Secret. Enforcement comes from several layers that each catch what the previous one missed.

Before and at push

Run a secret scanner as a pre-commit hook so mistakes are caught on the developer's machine. On GitHub, push protection blocks pushes that contain recognised secrets, including partner patterns, generic patterns such as private keys and connection strings, and custom patterns you define. For private repositories it requires GitHub Secret Protection to be enabled. Our article on securely storing secrets in Git repositories covers scanning tools and history clean-up.

In CI

Add a pipeline check that fails if any manifest of kind: Secret appears in the GitOps repository outside an allowed path, or if a SOPS-managed file contains values that are not encrypted. Make the check required on protected branches so it cannot be skipped.

In the cluster

An admission policy with Kyverno, Gatekeeper or ValidatingAdmissionPolicy can reject Secrets that are not created by your chosen controller, for example by requiring an owner reference or a label that only the controller sets. Argo CD AppProjects can also block the Secret kind for application teams, so only the platform's secret pipeline can create them.

Access control and encryption at rest

Limit get, list and watch on Secrets to the service accounts and people who need them, remembering that Pod creation rights imply Secret read rights in the same namespace. Enable encryption at rest for Secrets in the API server, preferably with a KMS provider on managed clusters that support it.

Rotation and incident response

If a secret is committed in plaintext, treat it as compromised. Rotate it at the source first, then remove it from the repository, then clean history if your policy requires it. Rewriting history alone does not help, because clones and caches may already hold the value. Reference-based patterns make rotation easier because the new value never touches Git. With encrypted-in-Git patterns, plan how to re-encrypt files when a key holder leaves or a key is suspected compromised. Ownership of these processes is a topic of its own; see who should maintain secrets management systems.

Managing secrets across environments

Most GitOps setups promote the same application through development, staging and production. Secrets must not follow the same path, because each environment should have its own credentials. With Sealed Secrets this happens naturally: each cluster has its own controller key, so a SealedSecret sealed for staging cannot be decrypted in production, and you seal each environment's value separately. With SOPS, use a separate key per environment, for example different age keys or KMS keys, and set creation rules so files under a production path are always encrypted for the production key. With External Secrets Operator, point each environment's SecretStore at a separate secret manager path or account, so the ExternalSecret manifests can be identical across environments while the values differ.

Keep the people with access to production keys or production secret paths to a small group, and let the platform's automation do the rest. Developers can then work freely with development secrets without ever holding production credentials, which limits the damage if a laptop or a CI token is compromised.

Auditing

Decide where the audit trail lives. With encrypted-in-Git patterns, Git history shows who changed an encrypted value, but not who read it. With external stores such as cloud secret managers and Vault, the store's own access logs show reads as well as writes, which is often what security reviews ask for.

Choosing an approach

  • One or two clusters, small team, no central secret store: Sealed Secrets.
  • Flux users who want encrypted files reviewed in Git: SOPS with age or a cloud KMS.
  • Already using a cloud secret manager or Vault, need rotation and auditing: External Secrets Operator.
  • Need dynamic, short-lived credentials: Vault with its operator or agent.
  • Want to avoid Secret objects in etcd: Secrets Store CSI Driver.

Our DevSecOps training covers these patterns with GitOps labs in the Kharadi, Pune classroom and live online for learners elsewhere in India.

References

Frequently asked questions

Can I store Kubernetes Secrets in Git if they are base64 encoded?

No. Base64 is an encoding that anyone can reverse. A plain Secret manifest in Git exposes the value to everyone with repository access and stays in history after deletion.

Are Kubernetes Secrets encrypted by default?

No. The Kubernetes documentation says Secrets are stored unencrypted in etcd by default. Enable encryption at rest and restrict access to Secrets with RBAC.

What is the difference between Sealed Secrets and SOPS?

Sealed Secrets encrypts a whole Secret with a key held by a controller in one cluster. SOPS encrypts values inside files with age, PGP or a cloud KMS, and the decrypting key can live wherever you choose, such as in Flux.

Which secret approach does Argo CD recommend?

Argo CD strongly recommends destination cluster secret management with an operator such as Sealed Secrets or External Secrets Operator, and cautions against injecting secrets during manifest generation with plugins.

How does External Secrets Operator work with GitOps?

Git holds only an ExternalSecret and a SecretStore reference. The operator fetches the value from a provider such as AWS Secrets Manager or Vault and creates a Kubernetes Secret, refreshing it on a set interval.

What should I do if a secret was committed to Git?

Treat it as compromised and rotate it at the source first. Then remove it from the repository and clean history if needed, since clones and caches may already contain it.

How do I stop developers from committing secrets?

Use pre-commit secret scanning, enable push protection on your Git host, add a required CI check for plain Secret manifests, and reject unmanaged Secrets with an admission policy.

Interested in learning more?Get a callback from our training advisors.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.