Knowledge Guide
HomeSystem DesignScalable Systems (Advanced Topics)

What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare

Secrets management is the practice of securely storing and handling sensitive information (like passwords, API keys, and tokens) used in software systems to prevent unauthorized access.

Understanding Secrets Management

In modern applications and IT environments, a “secret” refers to any sensitive credential or key that must be kept confidential, examples include database passwords, API tokens, encryption keys, certificates, and SSH keys.

Secrets management encompasses the tools and methods to safeguard these credentials throughout their lifecycle, storing them securely (usually encrypted), controlling who or what can access them, transmitting them safely to applications, and rotating or revoking them when needed.

This practice ensures that only authorized users or services can retrieve secrets, thereby reducing the risk of leaks or breaches.

Why Secrets Management Matters

Without proper secrets management, organizations often suffer from "secret sprawl"; credentials scattered across config files, code, environment variables, and even chat logs.

This sprawl leads to several issues:

By implementing robust secrets management, teams can centralize secrets storage, enforce access controls (like least privilege), and automate credential updates.

This greatly improves security by limiting secret exposure and ensuring secrets remain up-to-date and monitored.

Common Approaches to Secrets Management

There are various ways to manage secrets, each with different levels of security and complexity.

Here we’ll compare three common approaches: using environment variables, using a Key Management Service (KMS), and using a secrets vault like HashiCorp Vault.

Environment Variables

Environment variables are one of the simplest and most widely used methods to supply secrets to applications.

Developers often load sensitive values (database passwords, API keys, etc.) into the application’s environment at runtime (or via a .env file in development), allowing the code to read those values from memory.

For example, you might set an environment variable DB_PASSWORD="supersecret" on a server or in a container, and the application reads DB_PASSWORD from its environment.

This approach is popular because it’s easy and language-agnostic, no additional tools are required, and nearly every platform supports environment configs.

In fact, many tutorials use environment variables for secrets simply because it’s convenient, not because it’s the most secure practice.

However, there are important drawbacks to relying on environment variables for secrets:

Pros and Cons of Environment Variables:

Key Management Services (KMS)

A Key Management Service (KMS) is a cloud (or on-premise) service focused on managing cryptographic keys and performing encryption/decryption operations.

Examples include AWS KMS, Google Cloud KMS, or Azure Key Vault (which, despite the name “Key Vault,” functions as a KMS and secrets store).

Using a KMS for secrets management typically means leveraging strong encryption for your secrets: you encrypt sensitive data using keys stored in the KMS, and only decrypt them at runtime with KMS authorization.

For instance, you might store an encrypted form of your API key in an environment variable or configuration file.

Your application at startup calls the KMS (with proper credentials) to decrypt it.

The idea is that the plaintext secret is never stored at rest, only the ciphertext is, and the encryption keys are safely managed by the KMS.

Cloud KMS systems often use Hardware Security Modules (HSMs) under the hood, adding an extra layer of physical security for key material.

Benefits of KMS approach:

Limitations/considerations:

Pros and Cons of KMS:

Secrets Vaults (HashiCorp Vault)

HashiCorp Vault (often just called “Vault”) is a popular open-source secrets management tool designed to be a centralized vault for sensitive data.

Vault acts as a secure store where you can keep and tightly control access to secrets like tokens, passwords, certificates, API keys, and more.

Unlike environment variables or a simple KMS, Vault provides a full suite of features purpose-built for secrets management.

Key characteristics of Vault include:

Naturally, Vault’s richness comes with more complexity.

Deploying Vault means running a server (or a cluster of them for high availability).

You need to initialize and “unseal” the Vault (provide master key shares to unlock it) whenever it starts.

Applications must be configured to authenticate to Vault (via tokens, AppRole, cloud IAM, etc.) and to request the secrets they need. This setup is non-trivial, especially compared to using simple env vars or a cloud service.

Pros and Cons of Vault:

Environment Vault
Environment Vault

Environment Variables vs KMS vs Vault: Key Differences

Each approach to secrets management strikes a different balance between simplicity, security, and functionality.

Below is a comparison of environment variables, KMS, and Vault across various dimensions:

🤖 Don't fully get this? Learn it with Claude

Stuck on What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare** (System Design) and want to truly understand it. Explain What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes