Vault Structure
HashiCorp Vault is designed around a core set of components that work together to manage secrets and identity. Understanding these building blocks is crucial for operating Vault effectively. It uses a component-based architecture to decouple identity from the secret data itself.
Before anyone (user or machine) can interact with Vault, they must authenticate. Auth Methods are the components that perform this verification. Vault supports a wide variety of methods to suit different environments:
Key Concept: Authentication does not directly grant access to secrets. Instead, successful authentication returns a Token.
The Token is the core unit of authentication within Vault. Once an Auth Method verifies an identity, Vault issues a token to that client.
X-Vault-Token header).Policies are the authorization layer (RBAC). They define what a token can do.
secret/data/webapp/*”.This is where the actual secrets live. Secret engines are plugins that store, generate, or encrypt data.
Main Secret Engines:
Static Secrets:
Dynamic Secrets:
Encryption as a Service:
Mounting: Secret engines are “mounted” at specific paths. You can mount the same engine multiple times at different paths (e.g., secret/ for general secrets and apps/ for application secrets).
Vault behaves like a virtual filesystem.
my-secrets/).my-secrets/prod/database).data/ sub-path (e.g., my-secrets/data/prod/database) to handle versioning.secret/data/myapp/config (for KV v2) including its Token.read permission on secret/data/myapp/config?vault server -dev
The startup requires docker for quick and easy initialization.
docker-compose.yaml and the config/config.hcl is mandatory requirements.
Create docker compose file
Create configuration file under config/
Start the service docker compose up -d

Setup the vault address
export VAULT_ADDR=http://localhost:8200
type vault operator init, the vault will init and generate [Vault Initialization Docs]
vault operator init
# vault operator init -key-shares={number of keys} -key-threshold={number to unlock}
type vault operator unseal <Unseal_Key> for unseal the vault
There is only a one method that user can access to the vault server, providing a vault token (set up envrionment variable VAULT_TOKEN).
Command as export VAULT_TOKEN={token} in linux.
Command as set VAULT_TOKEN={token} in CMD Windows.
But there is multiple ways to acquire a vault token, the raw and easiest way is that when the vault is first time init throught vault operator init method, the unseal token and the root token is generated automaticall. officially, if user don’t do anything, the root token should be a powerful and life long vault session token, which mean the root token is never expired.
In vault server, there is a lot of authentication method for accessing the vault server.
User can user vault auth list to view the current enabled authentication method.
Approle is one of the main methodology for accessing the machines or application to access to the vault server.
Use vault auth enable approle to enable the approle in vault serve
Normally below script cover most of the setting on creating a approle.
vault write auth/approle/role/{role name} \
policies="policy1,policy2" \
secret_id_ttl="24h" \
token_ttl="1h" \
token_max_ttl="4h" \
secret_id_num_uses=10 \
token_num_uses=5 \
enable_local_secret_ids=true
For simplicity, if you want an AppRole that works indefinitely, but each issued token is valid for only 10 minutes, you can define the AppRole as below:
vault write auth/approle/role/{role name} \
policies="policy1,policy2" \
token_ttl="10m"
RoleID is the unique identifier for an AppRole in Vault. It acts as the first factor in AppRole authentication and is required (along with SecretID) to log in and obtain a token.
Set a custom RoleID: Vault allows you to set a custom RoleID when creating or updating an AppRole:
vault write auth/approle/role/{role name} role_id="{custom_role_id}"
This can be useful for integration with external systems or for easier management.
Retrieve a RoleID:
vault read auth/approle/role/{role name}/role-id
SecretID is a credential used in Vault’s AppRole authentication method. It acts as a second factor (along with RoleID) to authenticate machines or applications securely.
Generate a SecretID:
vault write -f auth/approle/role/{role name}/secret-id
This command returns a new SecretID for the specified AppRole.
Important: SecretIDs cannot be set manually—they can only be generated by Vault. This ensures that no one can predict or predefine the next SecretID, enhancing security.
This command returns a new, unpredictable SecretID for the specified AppRole.
TokenTo log in to Vault using AppRole, use the following command with your RoleID and SecretID:
vault write auth/approle/login role_id="{role_id}" secret_id="{secret_id}" # token will return by this command
This will return a Vault token that you can use to access secrets according to the policies attached to the AppRole.
The KV (Key-Value) secret engine is the most common way to store static secrets in Vault. Below are the typical operations:
1. Enable a KV secret mount: You can enable a KV engine at a specific path (e.g., “mysecrets”):
vault secrets enable -path=mysecrets kv
For KV v2 (with versioning):
vault secrets enable -path=mysecrets kv-v2
2. List all secret mounts: To see all enabled secret engines:
vault secrets list
3. List secret paths under a given secret mount: To list keys (secret paths) under a mount (e.g., “mysecrets”) for both KV v1 and KV v2, use:
vault kv list mysecrets/
The CLI handles the versioning and path details internally for KV v2.
4. Store (put) secret data at a secret path: To store secret data at a path:
vault kv put mysecrets/myapp username="admin" password="s3cr3t"
This command writes the key-value pairs to the specified path.
5. Get the secret payload from a secret path: To retrieve the secret data stored at a path:
vault kv get mysecrets/myapp
The CLI handles the versioning and path details internally for KV v2.
Check Vault Status
vault status