Skip to content
Français
Account: not signed in, sync available My learning
Select theme
Français

HashiCorp Vault: manage your secrets securely

  • 20 min

By updated

Improve this page

HashiCorp Vault logo

This module puts a secret in a vault, makes every client prove who it is, then opens only the strictly necessary path. HashiCorp Vault is the implementation: it encrypts what you entrust to it, issues a token after a successful authentication, and answers only if a policy allows it. It is for people who already know the lifecycle of a secret and want to move from principle to practice, in three lessons that follow one another: Vault KV, authentication then policies.

What you will learn

  • Decide whether a Vault is justified for your context, or whether a lighter tool is enough
  • Place authentication, policies and secrets engines in Vault's access chain
  • Understand why the three lessons follow the order store, authenticate, scope
  • Spot what running the vault itself costs, and where the optional module details it
  • Connect the module to the SOCLE-SEC-STO (in French) requirements on storage, scoped access and their traceability

Why does this module come after the lifecycle?

The previous module set out the eight-step lifecycle of a secret, the choice between a static, dynamic or federated-identity secret and the envelope encryption that protects the vault itself. It said where a secret must live at the storage step. This module builds that place: the vault, the front door (authentication) and the opening rule (the policy).

It comes before dynamic secrets for a mechanical reason. A dynamic secret is made on demand by Vault, but the client that asks for it goes through the same chain as a KV read: it authenticates, receives a token, and a policy decides which path is open. Without that chain, you could neither tell who to issue an ephemeral credential to, nor stop them from asking for one for production. The vault and its scoped access are therefore the common prerequisite for everything that follows.

Each lesson answers a question, and the answer of one becomes the input of the next. The first fixes the paths under which the secrets live, the second has a token issued to a human or a machine, the third attaches to that token a policy that names those paths. The tree chosen in KV therefore determines the policies, and the policies attach to the authentication methods: the order is not decorative.

LessonQuestion askedWhat you produce
Vault KVWhere does the secret live, under which path?A KV v2 mount, versioned secrets filed by application and by environment
AuthenticationWho is asking?A userpass account, an AppRole role, a short-lived token
PoliciesWhat can this token do, and on which path?An HCL policy loaded, attached and tested with an expected denial

One optional lesson completes this module: Vault Transit, which encrypts data without ever entrusting the key to the application. It follows the same access chain, with a different engine.

When is Vault the right vault?

Vault is a powerful but complex tool, and the first decision is not technical: is there a need that justifies this complexity? It becomes relevant as soon as at least one of the following needs appears. The right column says what Vault brings that the rest of the market brings less well.

NeedWhy Vault excels
Dynamic secretsDatabase, cloud and SSH credentials generated on demand with a TTL
Internal PKIBuilt-in certificate authority, short-lived certificates (hours/days)
Application-level encryptionTransit: the application never has access to the encryption keys
Strong auditComplete log of who accesses what, when, and for what reason
Multi-teamIsolation of secrets per team/environment with ACL policies
Rotation / revocationInstant revocation, automatic rotation of credentials
Kubernetes integrationNative auth via ServiceAccount, secret injection
Identity federationUnified authentication with OIDC, LDAP, cloud providers

Conversely, some situations bring more complexity than value. For a small team, a lighter tool often does more good, because the operational cost of Vault outweighs the benefit. The table gives, for each situation, the simplest alternative to examine first.

SituationSimpler alternative
A few team secretsPassword manager (Bitwarden, 1Password)
Simple CI/CD secretsGitLab/GitHub secret variables, AWS Secrets Manager
Team < 10 people, single environmentSOPS + Git, Infisical, Doppler
No dedicated ops budgetManaged solution (HCP Vault, Infisical Cloud)
Occasional need for certificatesLet's Encrypt, Certbot

Between the two, the choice of solution depends on the profile. Vault and its fork OpenBao become the right choice as soon as multi-team use, an internal PKI or application-level encryption appear; the Enterprise edition is justified for namespaces, replication and strict compliance.

ProfileRecommended solutionWhy
Small team (< 10 devs)Infisical, Doppler, SOPSLess operational complexity
Startup / mid-size teamVault CE or OpenBaoGood power/complexity ratio
Multi-team internal platformVault Enterprise or OpenBaoNamespaces, isolation
Kubernetes-firstExternal Secrets + (Vault or OpenBao)Native integration
Internal PKI / mTLSVault CE or OpenBaoComplete PKI engine
Application-level encryptionVault TransitKeys never leave Vault
Strict complianceVault EnterpriseMFA, Sentinel, Control Groups
Pure open source requiredOpenBaoMPL 2.0 licence

What does it cost to run a vault?

Vault is not a simple safe: it is an infrastructure component whose outage or misconfiguration hits every application that depends on it. The table below is the real cost of Vault, the one that does not show up in a tutorial in dev mode. Each line is a recurring task to equip, not a box ticked once. Look first at initialization, unsealing and storage: they determine the ability to restart the service after an outage.

ComponentWhat you must manage
InitializationGenerate and secure the unseal keys
UnsealingUnseal Vault after every restart (manual or auto-unseal)
StorageConfigure and maintain the backend (integrated Raft recommended)
High availabilityCluster of 3+ nodes for fault tolerance
BackupsRegular snapshots of the Raft storage
Key rotationPeriodic rotation of the master encryption key
AuditConfigure and monitor the audit devices (file, syslog, socket)
MonitoringPrometheus metrics, alerts on auth failures and expirations
PoliciesWrite and maintain the ACLs for every team/application
TLSCertificates for the Vault API (mandatory in production)

These tasks are the subject of the last module of the course, which is optional: it targets the operator of the vault rather than whoever reads secrets from it. It covers the installation, the auto-unseal and recovery keys (which spare you the manual intervention after every restart) and running in production. It also holds three pages about choices: the CE and Enterprise editions, the BSL 1.1 licence adopted in August 2023 (internal use allowed, competing managed offering forbidden) and Vault vs OpenBao, the fork maintained by the Linux Foundation under the MPL 2.0 licence.

How does Vault protect a secret?

Vault chains several components that interact to secure your secrets. The diagram below follows the flow of access to a secret, from the client to the decrypted value. Two points deserve attention as you read it. Every request first goes through an auth method, which issues a token, then through a policy, which decides what that token can do; the secret is reached only after these two barriers. And nothing works until the barrier, the encryption layer, is unsealed.

Secret access chain in Vault: clients authenticate through an auth method, the identity system consolidates the entity, ACL policies decide the rights per path, the secrets engines answer, and everything is stored encrypted in the storage backend.authidentitypoliciesaccessencryptedCLIENTSapplications, users, CI/CD pipelinesAUTH METHODSToken, Userpass, AppRole, Kubernetes, OIDC, Cloud...IDENTITY SYSTEMEntities, Groups, Aliases: consolidates identitiesPOLICIESACL HCL: define permissions per pathSECRETS ENGINESKV, Transit, PKI, Database, SSH, Cubbyhole...STORAGE BACKENDintegrated Raft, Consul, or others
Source · SVG
Esc to close, + and − to zoom, scroll to move around. 100 %

The three lessons of the module occupy the three middle links: KV is a secrets engine, authentication is the auth method, policies are the ACL layer that separates them. The identity system deserves a word because it is often underestimated: Vault maintains entities that consolidate the different authentication methods.

  • Entity: represents a single person or application
  • Alias: links an entity to an auth method (alice via userpass and alice via OIDC make up the same entity)
  • Group: gathers entities to apply common policies to them

This gives a unified view of access even if you mix several methods: userpass for development, OIDC for employees, Kubernetes for pods. What remains is the sealed state: Vault starts sealed and refuses every operation, because its data is encrypted by a master key that is itself encrypted. The default Shamir mode splits this key into N shares of which M are enough to rebuild it; auto-unseal entrusts the key to an external service (KMS, Transit) to avoid manual interventions.

Which secrets engines for which needs?

A secrets engine is a module that you enable on a given mount path and that defines how Vault handles secrets at that location. You enable only the engines you use, and each one is mounted on a distinct path that the policies control separately. Vault distinguishes two families: static secrets, which you deposit and which stay identical until you change them, with all the problems that brings, and dynamic secrets, generated on demand with a limited lifetime, then deleted by Vault when the lease expires.

Look first at the Family column: it says whether the engine stores a fixed value (Static), makes a disposable one (Dynamic) or transforms data without storing it (Encryption). The move from static to dynamic is the real gain of Vault: Database, PKI, SSH and the cloud engines remove the shared, permanent credential lying around in your configurations.

EngineFamilyWhat it does in practice
KV v2StaticYour classic safe: store any secret with versioning (last 10 versions kept)
TransitEncryptionVault encrypts/decrypts your data without ever giving you the key. Your app sends plaintext, receives ciphertext.
DatabaseDynamicCreates a PostgreSQL/MySQL/MongoDB user on demand, deletes it automatically after expiry
PKIDynamicMakes TLS certificates signed by your internal CA, with the lifetime you want (1 hour, 30 days...)
SSHDynamicSigns SSH keys or generates OTP passwords to access your servers
AWS/Azure/GCPDynamicGenerates temporary cloud credentials (IAM user, service account...)
CubbyholeStaticPersonal safe tied to your token, nobody else can access it, not even admins

The second table approaches the problem from the other end: start from your real need, and it points to the right engine. A reading rule helps you decide quickly. If the secret is imposed from outside (API key of a third-party provider), it is static in KV v2, and that is the subject of the first lesson. As soon as Vault can create and destroy the credential itself, prefer the matching dynamic engine, which eliminates the shared password.

Your needRecommended engineWhy
Store third-party API keysKV v2Static secrets imposed by the provider
Database access for your appsDatabaseNo more shared password, automatic rotation
Encrypt sensitive data (GDPR)TransitYour developers never have access to the keys
Internal TLS certificates (mTLS)PKIShort-lived certificates, easy revocation
SSH access to your serversSSHNo more SSH keys lying around, audited access
Temporary AWS credentialsAWSNo more permanent access keys in configs

How does a client prove its identity?

Before accessing a secret, a client must prove who it is, and the method depends on its nature. For a human, it is simple: a password or the company SSO. A machine cannot type a password: it proves its identity through its environment. The selection criterion is therefore the nature of whoever authenticates, and the right column describes the verification mechanism.

Who authenticatesRecommended methodHow it works
Developer locallyUserpassClassic login/password, simple for tests
Employee in a companyOIDC or LDAPSSO via Keycloak, Okta, Azure AD, or Active Directory
CI/CD pipelineAppRolerole_id in a variable, secret_id generated on every run
Kubernetes podKubernetes authServiceAccount token verified by Vault
EC2/cloud VM instanceAWS/Azure/GCP authThe cloud provider's machine identity
On-premises serverAppRole or TLS certsDepending on your infrastructure

The authentication lesson covers the two methods that depend on no third-party infrastructure: userpass and AppRole, where the application receives a role_id (its identity) and a secret_id (a disposable password). The Kubernetes and cloud methods illustrate a broader concept, workload identity: instead of distributing a secret, the machine proves who it is through its environment. The course devotes a whole module to it, starting from machine identity and the identity broker.

One question remains that every disposable-secret mechanism raises: how do you give the application the first secret, without it travelling in the clear? This is the secret zero problem. AppRole reduces it with response wrapping, where the secret_id is wrapped in a single-use token that expires within minutes; the lesson puts it into practice. Vault tokens also work on their own, but you have to create and distribute them by hand: with 50 microservices, this becomes unmanageable, and that is why you let applications authenticate themselves.

How does a policy limit access?

Once authenticated, what can the client do? That is the role of policies, which associate paths with capabilities, that is, allowed actions. The central mechanism is default deny: Vault grants only what is written, everything else is forbidden. In the example below, the team has full rights on the development secrets, read-only access to pre-production, and no access to production, since that path appears nowhere.

# Policy for the development team
path "secret/data/dev/*" {
capabilities = ["create", "read", "update", "delete", "list"]
}
# Read-only on staging (no changes in pre-prod)
path "secret/data/staging/*" {
capabilities = ["read", "list"]
}
# No access to production: whatever is not explicitly
# allowed is denied

The final * covers everything that follows the prefix; the lesson on policies details the eight capabilities, the rule that arbitrates between two overlapping paths, and how to test a policy before handing it to a pipeline. What to remember here: access is designed by business role and by path, never by person, and an explicit deny is reserved for exceptions: it acts only inside the rule that is retained, so a broad deny does not override an access defined more precisely elsewhere.

Key points

  1. A vault is only worth something if a complete chain reaches it: authentication, token, policy, engine, encrypted storage
  2. The three lessons follow one another: KV fixes the paths, authentication issues the token, policies name the paths open to that token
  3. Vault is powerful but demanding: assess whether you have the resources to run it, or whether a lighter tool is enough
  4. Static or dynamic: KV v2 for what is imposed on you, a dynamic engine as soon as Vault can create and destroy the credential
  5. Default deny: a policy grants only what it names, access is designed by business role
  6. Identity system: consolidates the identities of several auth methods into one entity
  7. The vault protects itself too: sealing, auto-unseal, audit and backups are detailed in the optional operations module
  8. Evidence expected by SOCLE: secrets are in a vault, encrypted at rest, access is scoped to the strict minimum and traced (see SOCLE-SEC-STO (in French))

FAQ: frequently asked questions

These short answers cover the decision questions that come up most often before adopting Vault: the choice between the CE and Enterprise editions, the scope of the BSL licence, the positioning of the OpenBao alternative and how dynamic secrets work.

Is this project useful to you?

The guides, courses, quizzes and labs stay free. If you use them regularly, you can contribute to their upkeep and development.

Become a supporting member (new tab) One-time support (new tab) Learn more

Follow the project on LinkedIn