As an SRE, securely managing sensitive data like API keys, database credentials, and certificates is paramount, especially when embracing Infrastructure as Code (IaC). Storing plaintext secrets directly in Git is a major security risk. Secrets management tools bridge this gap, allowing you to define your infrastructure (including secret references) in code while keeping the actual sensitive values encrypted and access-controlled. This ensures that your Git repository remains auditable and free of sensitive information, while your deployments can securely access what they need. Without proper secret management, your IaC efforts are incomplete and vulnerable.
HashiCorp Vault is a powerful, centralized secrets management solution designed for dynamic secrets, fine-grained access control, and auditing. It can generate on-demand credentials for databases, cloud providers, and more, leasing them out and revoking them automatically. This makes Vault ideal for complex, multi-environment setups where secrets are frequently rotated or dynamically provisioned. In contrast, Mozilla SOPS focuses on encrypting structured data files (YAML, JSON, .env) directly in your Git repository using KMS services (AWS KMS, GCP KMS, Azure Key Vault) or GPG keys. This allows encrypted configuration files to be safely committed and versioned in Git, adhering to GitOps principles, with decryption happening at deployment time by an authorized agent or CI/CD pipeline.
Bitnami Sealed Secrets is a Kubernetes-native solution. It encrypts standard Kubernetes Secret resources into SealedSecret custom resources using asymmetric encryption. You can safely commit these SealedSecret objects to Git. An operator running inside your Kubernetes cluster then decrypts them back into standard Secret objects, which only the cluster controller can read. This provides a clean GitOps workflow for Kubernetes secrets. While Vault offers comprehensive secret lifecycle management, SOPS and Sealed Secrets excel at enabling Git-based storage of encrypted secrets, either for generic files (SOPS) or specifically for Kubernetes (Sealed Secrets). Often, these tools can complement each other; for instance, Vault might be the source of highly dynamic secrets, which are then passed to a Kubernetes cluster and managed via Sealed Secrets for GitOps-friendly delivery.
Key Takeaways
- Never commit plaintext sensitive information to version control systems like Git.
- HashiCorp Vault provides centralized, dynamic secret management with robust auditing and access control for complex environments.
- Mozilla SOPS enables secure, GitOps-friendly storage of encrypted configuration files (YAML, JSON) using KMS or GPG.
- Bitnami Sealed Secrets is a Kubernetes-specific solution for safely storing encrypted Kubernetes
Secretdefinitions in Git. - Choose tools based on your environment's complexity, the dynamism of your secrets, and whether you need Kubernetes-native integration or centralized management.
Code Example
# To encrypt a YAML file using SOPS with a GPG key:
# sops --encrypt --pgp <GPG_KEY_FINGERPRINT> --in-place my-secrets.yaml
# Example of `my-secrets.yaml` *after* SOPS encryption:
api_key: ENC[AES256_GCM,data:eyJ2IjoiYiIsImkiOiJ4eXMiLCJhIjoiLi4uIn0=,iv:...,tag:...,type:str]
database_user: admin # SOPS can selectively encrypt fields
database_password: ENC[AES256_GCM,data:eyJ2IjoiYiIsImkiOiJ4eXMiLCJhIjoiLi4uIn0=,iv:...,tag:...,type:str]
sops:
pgp:
- fp: "EXAMPLE_GPG_FINGERPRINT"
enc: |
-----BEGIN PGP MESSAGE-----
... (encrypted key material unique to this file) ...
-----END PGP MESSAGE-----
version: 3.7.3How this code works
This YAML demonstrates a my-secrets.yaml file after it has been encrypted using SOPS, specifically with a GPG key. Its main job is to show how sensitive information, like an api_key or database_password, is stored securely in a human-readable YAML structure but in an encrypted form. Notice how the values for these fields transform into an ENC[...] string, which SOPS generates. This ENC[...] block isn't just random text; it explicitly denotes an encrypted value, containing details like the AES256_GCM encryption algorithm used, alongside an iv (initialization vector) and tag for security and integrity verification.
A key feature visible here is SOPS's ability to selectively encrypt fields; for instance, database_user: admin remains in plain text because it wasn't marked for encryption. This is a subtle but important detail: SOPS encrypts only what's specified or configured, not the entire file by default. Below the encrypted data, the sops: block is metadata added by SOPS itself. Within this block, the pgp section contains the fp (fingerprint) of the GPG key used for encryption and the actual encrypted key material. This encrypted material is unique to this specific file and enables SOPS to later decrypt the file using the original GPG key without exposing the key itself. The version indicates the SOPS version used.