Phase 5: Platform Engineering

Secrets management: Vault, SOPS & sealed secrets

Intermediate ~3 min read
Think of it this way A friendly analogy. Read this if the technical version feels dense. Show Hide

Have you ever built a super cool fort with LEGOs or building blocks? Imagine you've got a fantastic blueprint – a detailed plan showing where every wall, window, and door goes. You want to share this blueprint with your friends so they can help build or even make their own versions. But what if your fort has a secret trapdoor, a hidden treasure chest, or a special button that only opens a secret passage? You wouldn't want to write the exact instructions for opening the trapdoor, the combination for the treasure chest, or the secret phrase for the passage directly on the main blueprint, would you? If you did, anyone who saw your blueprint would know all your fort's secrets!

In the world of computers, when grown-ups build amazing digital "forts" (like websites, apps, or big online systems), they also have blueprints called "code." These digital forts often need "secret ingredients" to work, like special passwords for databases or keys to connect to other services. If they write these secret ingredients directly into the code blueprint that gets shared around, it's just like putting your treasure chest combination on a public drawing – super risky! That's why we need "secrets management."

Instead of putting the actual secret combination on the blueprint, you write something like: "Ask the Fort's Secret Keeper for the treasure chest combination." The Fort's Secret Keeper is a special, super-secure vault. When your computer system (your fort-building robot!) needs to open the treasure chest, it doesn't look at the blueprint for the combination. It goes directly to the Secret Keeper. This keeper can do a few things: it might give a brand new, temporary combination every single time the robot asks, and then change it again later! This is great for super sensitive secrets that need to change often. Or, it might have written the secret instructions on the blueprint using special invisible ink that only your fort-building robot can read, making it look like gibberish to everyone else.

So, when engineers build big, complex computer systems, they use tools like these Secret Keepers. They make sure that sensitive information, whether it's a database password or a special key, is never written directly into the shared blueprints. This means you can share your awesome building plans with confidence, knowing that all the truly secret parts are locked away safely, only accessible to the authorized computer programs that need them, and only when they need them.

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 Secret definitions 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

yaml
# 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.3

How 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.