Secrets management is where platform engineering gets real. You can abstract away deployments, spin up a beautiful Internal Developer Platform: Self-Service Infrastructure for Engineering Teams, and still grind to a halt because a database password was hardcoded, leaked in a log, or expired without rotation and took down production. In my experience, most teams don't have a secrets problem until they suddenly have a massive one. Moving from manual `.env` files and Kubernetes Secrets to a proper stack with HashiCorp Vault, External Secrets Operator (ESO), and SOPS is how you build a system that is secure by default, auditable, and actually usable for developers. This article covers how I architect these three tools together in production, where each fits, and the operational lessons you only learn after running them for a year.
Why Native Kubernetes Secrets and Plain Git Will Betray You
Kubernetes Secrets look convenient. You base64-encode a value, apply a manifest, and mount it as an environment variable. The problem is that by default, they are stored unencrypted in etcd, base64 is not encryption, and anyone with `get` permission on that namespace or access to etcd backups can read them. The Kubernetes Documentation is clear that you must enable encryption at rest and enforce RBAC, but even then you still lack rotation, lease management, and audit trails.
The other anti-pattern I see constantly is unencrypted secrets in Git. Teams tell themselves a private repository is safe enough, until a contractor is added, a repo is made public by mistake, or a secret is copied into a CI log. Once a secret is in Git history, it is compromised forever unless you rotate it. You need a solution where Git can store the secret, but only in an encrypted form, and Kubernetes can consume secrets without developers ever handling plaintext.
What a Production-Grade Requirements List Looks Like
Before picking tools, I define the requirements I will be held to during an incident or audit. In my experience, if you can't answer these five questions, your design is incomplete: Where is the single source of truth for secrets? How is access authenticated and authorized without long-lived credentials? How are secrets delivered to workloads with minimal manual steps? How are they rotated and revoked automatically? And can you prove who accessed what and when? Vault answers the first two, External Secrets Operator solves delivery, and SOPS solves the Git storage problem for GitOps.
Architecting HashiCorp Vault as Your Central Secrets Control Plane
Vault is not just a key-value store. Treating it as an encrypted database misses its real value. I deploy Vault as a control plane for identity and short-lived credentials. Instead of issuing a 90-day database password and trying to remember to rotate it, Vault dynamically generates a 1-hour credential, automatically revokes it, and logs the entire transaction.
For platform teams, the architecture I recommend is a single Vault cluster per organization or per regulated environment, running in HA mode with Raft integrated storage. Avoid running Vault inside the same Kubernetes cluster it is serving unless you have a clear disaster recovery path for when that cluster goes down. I run Vault on dedicated VMs or a separate management cluster, with auto-unseal via cloud KMS (AWS KMS, GCP KMS, or Azure Key Vault). Enable audit devices from day one. If auditing is not enabled on initialization, you will have a gap you cannot backfill.
Auth Methods and Policies That Actually Scale
The biggest mistake is using Vault's root token or a single long-lived AppRole for everything. I configure Kubernetes auth so each workload authenticates with its own ServiceAccount identity. Vault validates the ServiceAccount JWT against the Kubernetes API, then issues a short-lived token bound to a policy. This removes the need to distribute any Vault secret to the workload.
# Vault policy that allows a payment-service to read only its own secrets
path "kv/data/payment-service/*" {
capabilities = ["read"]
}
path "database/creds/payment-service" {
capabilities = ["read"]
}
# Allow renewing own token
path "auth/token/renew-self" {
capabilities = ["update"]
}
I pair this with the KV v2 secrets engine for static secrets and database engines for dynamic secrets. For example, the database secrets engine can be configured to create ephemeral users in PostgreSQL: vault write database/config/my-postgresql ... and then a role like vault write database/roles/payment-service db_name=my-postgresql creation_statements="CREATE ROLE ..." default_ttl="1h" max_ttl="24h". The Terraform Documentation has a complete Vault provider that I use to codify all of this. Managing Vault policies, auth roles, and secret engines via Terraform is non-negotiable if you want reproducibility. I've found that manually clicking in the Vault UI is how you end up with 40 slightly different policies nobody dares to delete.
Syncing Vault Secrets into Kubernetes with External Secrets Operator
Vault is excellent, but you don't want every application to speak the Vault API directly. Developers want to consume a normal Kubernetes Secret. That is where External Secrets Operator comes in. ESO runs as a controller in your cluster, authenticates to Vault using the workload's identity or a central ClusterSecretStore, fetches the secret, and materializes it as a native Kubernetes Secret. When the value changes in Vault, ESO reconciles it.
This pattern is critical for a Golden Paths: Reducing Cognitive Load for Development Teams approach. The developer experience is unchanged - they mount a Secret - but the platform team controls the lifecycle outside the cluster. You also avoid the alternative, Vault Agent Injector, which I have found to be more intrusive because it requires sidecars and annotation-based injection that breaks with some service meshes and serverless workloads. ESO is more declarative and GitOps-friendly.
Configuring a ClusterSecretStore and ExternalSecret
First, you define the connection to Vault once per cluster. I use a ClusterSecretStore for shared Vault instances and a namespaced SecretStore only when a tenant team runs its own Vault.
apiVersion: external-secrets.io/v1beta1
kind: ClusterSecretStore
metadata:
name: vault-backend
spec:
provider:
vault:
server: "https://vault.platform.internal:8200"
path: "secret"
version: "v2"
auth:
kubernetes:
mountPath: "kubernetes"
role: "external-secrets-controller"
serviceAccountRef:
name: external-secrets
namespace: external-secrets
---
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: payment-api-secrets
namespace: payments
spec:
refreshInterval: 1h
secretStoreRef:
kind: ClusterSecretStore
name: vault-backend
target:
creationPolicy: Owner
deletionPolicy: Retain
data:
- secretKey: DATABASE_URL
remoteRef:
key: kv/data/payment-service/prod
property: DATABASE_URL
- secretKey: STRIPE_KEY
remoteRef:
key: kv/data/payment-service/prod
property: STRIPE_KEY
A few lessons from running this in production. Set refreshInterval intentionally. A 1-hour interval is a good balance; 1 minute will hammer Vault and get you rate-limited. Always set deletionPolicy: Retain unless you want a mistaken deletion of the ExternalSecret to delete the underlying Secret and crash your app. And enable ESO's metrics and alerts. I alert on externalsecret_status_condition{condition="Ready", status="False"} - this is how you catch expired Vault tokens or RBAC changes before your pods fail to start. In one incident, a cluster upgrade rotated ServiceAccount issuer keys and ESO could no longer authenticate to Vault. Without that alert, we would have found out from failed deployments.
Encrypting Secrets in Git with SOPS for GitOps Workflows
Vault is ideal for dynamic and high-value secrets, but not every secret needs a network call to Vault. For GitOps with Argo CD or Flux, you often want the entire application state, including secrets, to live in Git and be reconciled declaratively. SOPS (Secrets OPerationS) gives you that by letting you commit encrypted files to Git that can be decrypted only by authorized parties or controllers.
I use SOPS with age, not PGP. Age keys are simple, small, and far easier to manage than GPG keyrings. The typical setup is one age public key per cluster and per developer group, managed via a .sops.yaml configuration at the repository root. Encryption is done locally or in CI, and decryption happens on the cluster via the Flux SOPS controller or Argo CD's SOPS plugin. In my experience, SOPS is the fastest way to satisfy GitOps principles without building a custom controller to pull from Vault for every small config value.
A Practical SOPS Workflow That Doesn't Create Bottlenecks
Create an age keypair for your cluster and store the private key as a Kubernetes Secret in your management cluster. Never commit the private key. Distribute the public key to developers.
# .sops.yaml in repo root
creation_rules:
- path_regex: clusters/prod/.*\.enc\.yaml$
age: age1ql3z7hj432v2w96qz8y7f9e2k5p6q... # prod cluster public key
- path_regex: clusters/staging/.*\.enc\.yaml$
age: age1qyqszqgpqyqszqgpqyqszqgpqyq... # staging cluster public key
# Encrypt a file
sops --encrypt --in-place clusters/prod/payment-service.enc.yaml
# The file on disk is encrypted, but `sops exec` lets you edit plaintext
sops clusters/prod/payment-service.enc.yaml
# Flux will decrypt automatically if sops-age secret is present
# kubectl create secret generic sops-age --namespace=flux-system \
# --from-file=age.agekey=./keys/prod.agekey
What you encrypt matters. Encrypt the entire file, not just values, to avoid leaking key names and structure. Use enc.yaml as a naming convention so your tooling knows what to decrypt. I also enforce a creation rule where developers can encrypt but cannot decrypt production secrets unless they are on-call; decryption keys for prod live only in the cluster. This gives you an auditable boundary while keeping the workflow fast for non-production environments.
Vault vs External Secrets vs SOPS: Picking the Right Tool for the Job
These tools are not mutually exclusive; I run all three in most platforms. The art is knowing which to use when. Vault is your privileged backend for identity-aware, short-lived, and highly audited secrets. ESO is the bridge that makes Vault usable for Kubernetes workloads without leaking Vault complexity to developers. SOPS is for Git-resident configuration that needs version control and GitOps reconciliation without an external dependency at runtime.
If you try to force everything through Vault, you will create a hard runtime dependency for every pod start. If you try to do everything with SOPS, you lose dynamic credentials, automatic rotation, and centralized revocation. The pattern that has worked best for me is: secrets that change rarely and are tied to application config (TLS certificates for internal services, third-party API keys) go in SOPS-encrypted Git. Secrets that are high-risk or dynamic (database credentials, cloud IAM keys) live in Vault and are synced via ESO.
| Tool / Pattern | Best For | Source of Truth | Delivery Model | Operational Overhead |
|---|---|---|---|---|
| HashiCorp Vault | Dynamic credentials, strong audit, identity-based access | Vault cluster (HA Raft, KMS auto-unseal) | API-driven; workloads or ESO pull via authenticated request | High - HA, unseal, backups, upgrades, monitoring |
| External Secrets Operator | Syncing external secrets into native Kubernetes Secrets | Vault, AWS Secrets Manager, GCP Secret Manager | Controller reconciles external source to Kubernetes Secret | Medium - controller RBAC, refresh tuning, alerting |
| SOPS with Age / KMS | GitOps-friendly static secrets, config per environment | Git (encrypted file) with age/KMS keys | Decrypted at apply time by Flux/Argo CD controller | Low - key distribution, .sops.yaml governance |
For a platform that supports dozens of teams, this layered approach maps cleanly to golden paths. A team starting out can use SOPS on day one with zero infrastructure. As their service becomes critical, they graduate to ESO + Vault for database credentials without rewriting application code.
Hardening Your Secrets Stack: Rotation, Auditing, and Recovery Patterns
Shipping Vault and ESO is only 40% of the work. The rest is what keeps you out of a security incident review. I treat secrets hardening as three distinct problems: rotation, audit, and disaster recovery.
Automated Rotation Without Downtime
Static secrets that never rotate are a liability. For Vault KV, I set a 30-day rotation policy and use ESO's refreshInterval combined with a pod rollout trigger. For dynamic database credentials, rotation is automatic - every pod gets a new credential on restart. For SOPS-encrypted secrets, I rotate by re-encrypting with sops updatekeys when an engineer leaves or a key is rotated. I've found that the most reliable rotation mechanism is simply restarting workloads after a secret changes. ESO can trigger this with Reloader or Argo CD's auto-sync if you annotate deployments.
Audit and Least Privilege
Enable Vault audit logs to a durable sink like S3 or CloudWatch and ship ESO controller logs to your central logging stack. I review who requested kv/data/* paths weekly. Kubernetes RBAC should be tightened so developers cannot kubectl get secrets in production. They can see ExternalSecret definitions, but not the materialized Secret unless explicitly allowed. This separation has saved us during a compromised developer credential - the attacker could list ExternalSecrets but could not read the actual values without also compromising Vault authentication.
Disaster Recovery You Have Actually Tested
Vault Raft snapshots must be taken hourly and stored off-site, encrypted with KMS. I run a monthly restore drill to a separate Vault instance and verify that unseal and policy replication work. For SOPS, the disaster is losing the age private key. I back up age keys in two places: a hardware security module and a sealed Vault Transit encryption. If you lose both, your Git-encrypted secrets are unrecoverable. Document the recovery runbook and test it. A secret management system you cannot recover is worse than not having one, because teams will assume it is durable and stop keeping manual backups.
When you get this stack right, secrets become invisible. Developers request access via a self-service Terraform module that creates a Vault policy and an ExternalSecret, and the platform handles the rest. That is the goal of platform engineering: make the secure path the easy path.
Frequently Asked Questions
Can I use External Secrets Operator without HashiCorp Vault?
Yes, absolutely. ESO is provider-agnostic and supports AWS Secrets Manager, GCP Secret Manager, Azure Key Vault, and others. I've used it with AWS Secrets Manager for teams that are all-in on AWS to avoid running Vault. The pattern is the same - a SecretStore points to your backend and ExternalSecret resources sync values. Vault makes sense when you need dynamic credentials, strong identity-based auth, and cross-cloud portability.
Is SOPS safe for production secrets if the Git repository is private?
Private is not encrypted. SOPS-encrypted files are safe to commit even to a public repository, provided you manage keys correctly. The security boundary is the private age key or KMS key, not Git access. In my experience, the risk with SOPS is key distribution - ensure prod decryption keys exist only on the cluster and in a secure backup, not on every developer laptop.
How do you handle secret rotation without restarting pods?
Kubernetes Secrets mounted as environment variables never update without a restart. Secrets mounted as volumes do update when ESO refreshes, but most applications only read env vars at startup. I recommend using a tool like Stakater Reloader or Keptn to automatically roll deployments when the Secret changes. For database credentials from Vault's dynamic engine, give each pod a short TTL and rely on frequent restarts rather than hot-reloading.
Should I run Vault inside Kubernetes?
You can, but consider the blast radius. If Vault runs in the same cluster that depends on it, a cluster failure takes down both your workloads and your ability to issue new secrets to recover. I prefer running Vault outside the workload clusters, on dedicated VMs or a management cluster, with Raft integrated storage and KMS auto-unseal. If you do run it in Kubernetes, use a separate etcd/Raft backend, not the same etcd as your workloads, and test unseal after node failures.