Basis
Env Variables
export VAULT_TOKEN=hvs.xxxxxxxxxxxxxxxxSet Token for Token Authentication Method.
export VAULT_SKIP_VERIFY=trueSkip TLS check.
Initialization
Check Status
vault statusCheck if server is running.
Initialize and Unseal Vault
vault operator initInitialize vault.
vault operator unsealAsk for an unseal keys to unlock the vault (it unlocks when the required number of unseal keys are given).
Login
vault loginLogin to Vault using a Token.
vault login -method=userpass username="my_user" password="my_pass"Login to Vault using UserPass.
vault login -method=oidc role="my_role"Login to Vault with OIDC.
vault write auth/approle/login role_id="my_role_id" secret_id="my_secret_id"Login to Vault using AppRole.
vault write auth/jwt/login role=my_role jwt=my_jwtLogin to Vault using a JWT.
Tokens
Lookup
vault list auth/my_auth_method/accessorsList tokens created with specified Auth Method.
vault token lookup -accessor <token_accessor>Return info about the token (type, TTL, max TTL ...).
Create
vault token create -policy=my_policy -ttl=30mCreate a token with a specified Policy and TTL.
vault token renew myTokenRenew a token.
Revoke
vault token revoke <token_id>Revoke token.
vault token revoke -accessor <token_accessor>Revoke token using its accessor.
vault token revoke -selfRevoke current token.
vault token revoke -mode-path auth/my_auth_methodRevoke all tokens (and their children) created with specified auth method.
Traceability
Entity
vault list identity/entity/idList entities.
vault delete identity/entity/id/f53c4994-8458-6b6c-8cff-eaf869c9aefcDelete entity.
Audit Device
vault audit listList audit devices.
vault audit enable file file_path=/var/log/vault_audit.logCreate an audit device (the user running Vault has to be able to write to the given path).
vault audit disable fileDisable specified audit device.
vault write sys/audit-hash/file input="P@ssword!"Compute the hash for a given input (can be used to check hashed values in audit file). Warning: only admin should be able to write in
sys/audit-hash/file
.
Access Control
Lease
vault lease revoke aws/creds/myRole/my_lease_idRevoke specified lease.
vault lease revoke -prefix aws/Revoke all leases under the specified prefix.
Policy
vault policy listList policies.
vault policy read my-policyRead policy content.
vault policy write my-policy my-policy.hclCreate a policy from local file.
vault token capabilities hvs.XXXXXXXXXXXX /transit/encrypt/my_keyCheck capabilities of a token for the given path (output example:
update
).
Namespaces (Enterprise)
vault namespace listList namespaces.
vault namespace create my-namespaceCreate namespace.
vault namespace delete my-namespaceDelete namespace.
vault secrets list -namespace=my_namespaceUse a namespace in a command.
Authentication Methods
List
vault auth listList authentication backends enabled.
Enable
vault auth enable awsEnable an authentication backend.
Secret Engines
For more details on specific Secret Engines see: Vault CLI Secret Engines
List
vault secrets listReturn info about secret engines.
vault secrets list -detailedReturn more info about secret engines (e.g. KV version).
Enable
vault secrets enable -path=my_secret_engine_path kvCreate a new Key Value (KV) secrets engine.
Modify
vault secrets move my/old/path my/new/pathChange the path of the Secret Engine.
vault secrets tune -default-lease-ttl=12hChange the configuration of the Secret Engine.
Operator
Regenerate Root Token
vault operator generate-root -generate-otpGenerate an OTP for the
generate-root
command.
vault operator generate-root -init -otp=<otp_token>Initialize Root Token Generation. Give the generated nonce to the Recovery Keys holders.
vault operator generate-root -nonce=<request_nonce>Validate the request with every one that has a Recovery Keys until quorum is reached. This will return the encoded token.
vault operator generate-root -decode=<encoded_token> -otp=<otp_token>Decode the newly generated Root Token.
ReKey (Regenerate Unseal Keys)
vault operator rekey -init -key-shares=3 -key-threshold=2Initialize request for ReKey.
vault operator rekey -nonce=<request_nonce>Validate the request with Useal Keys until quorum is reached. This will output new Unseal.
vault operator rekey -target=recovery -init -key-shares=3 -key-threshold=2Initialize request for ReKey with Recovery Key mode (Auto Unseal enabled).
vault operator rekey -target=recovery -nonce=<request_nonce>Validate the request with Recovery Keys until quorum is reached. This will output new Unseal.
Rotate Encryption Keys
vault operator rotateVault automatically rotate the Encryption Key.
Raft
Cluster
vault operator raft list-peersList Raft members.
vault operator raft autopilot stateShow current cluster autopilot state.
vault operator raft autopilot get-configShow autopilot config.
Snapshot
vault operator raft snapshot save backup.snapCreate a Snapshot.
vault operator raft snapshot restore -force backup.snapRestore Snapshot from local file (copy the Snapshot file on the machine to restore).
-force
option is required here since the Auto-Unseal or Shamir keys will not be consistent with the snapshot data (snapshot from a different cluster). https://developer.hashicorp.com/vault/tutorials/standard-procedures/sop-restore
Snapshot Auto (Enterprise)
vault list /sys/storage/raft/snapshot-auto/configList Auto Snapshot configs.
vault read /sys/storage/raft/snapshot-auto/config/my-auto-snapshot-configCheck specified Auto Snapshot config.
Replication
Basis
vault read sys/replication/statusCheck replication status (DR and Performance).
Disaster Recovery
https://developer.hashicorp.com/vault/tutorials/enterprise/disaster-recovery
vault read sys/replication/dr/statusCheck DR replication status.
vault write -f sys/replication/dr/primary/enableEnable DR replication as Primary.
vault write sys/replication/dr/primary/secondary-token id=dr-secondaryCreate a token for a Secondary cluster.
vault write sys/replication/dr/secondary/enable token=DR_SECONDARY_TOKENEnable DR replication as Secondary.
Performance
vault read sys/replication/performance/statusCheck Performance replication status.
vault write -f sys/replication/performance/primary/enableEnable Performance replication as Primary.
vault write sys/replication/performance/primary/secondary-token id=perf-secondaryCreate a token for a Secondary cluster.
vault write sys/replication/performance/secondary/enable token=PERF_SECONDARY_TOKENEnable Performance replication as Secondary.
Agent
Basis
vault agent generate-config -type="env-template" -exec="./my_script.sh" -path="secret/my_secret" agent-config.hclGenerate a configuration file for an agent.
vault agent -config=agent-config.hclRun an agent.