Vault
Set up Vault
Scenario
Danielle is on the HashiCups development team, and builds the applications and plugins which interact with Vault. They have installed the Vault binary on their computer, and can now use a Vault development (dev mode) server for development and testing.
Oliver from the operations team evaluates a self-managed Vault server, and the HashiCorp Cloud Platform (HCP) Vault Dedicated server as solutions for local user acceptance testing.
Danielle and Oliver will start and prepare their Vault servers for use, check the server status, and user their initial root token to authenticate with Vault.
Prerequisites
To complete this tutorial, you need the following:
- Vault binary installed and configured in your system PATH.
Set up the lab
Vault operates as a client-server application. The Vault server is the sole piece of the Vault architecture that interacts with the data storage and backends. All operations done using the Vault CLI interact with the server over a TLS connection.
The HashiCups team members can operate their Vault servers to achieve goals for development, testing, and pre-production.
Here are some key differences in startup and setup between each Vault server type:
Dev mode Vault | Self-managed Vault | HCP Vault Dedicated |
---|---|---|
In-memory storage backend | Configurable storage backend | Integrated storage backend |
Automatic initialization and unsealing | Requires initialization and unsealing | Automatic initialization and unsealing |
Shamir's Secret Sharing seal with a single key share | Configurable seal | Cloud auto seal |
Initial root token automatically generated or specified at runtime | Initial root token part of unseal output | No root token; generate admin tokens in HCP UI |
Choose a tab to start and prepare a dev server, self-managed server, or HCP server.
(Persona: Developer)
The dev server is a built-in, pre-configured server that is not useful for production, but is helpful if you want to use Vault in your local development environment.
Reminder: dev mode in-memory storage backend
The dev server uses an in-memory storage backend. This means that when you stop a dev server, you lose access to any data you wrote to the server.
Before you start the server, use the
vault
binary to print help with the-help
flag.$ vault server -help
Scroll to the Dev options section.
Dev Options: -dev Enable development mode. In this mode, Vault runs in-memory and starts unsealed. As the name implies, do not run "dev" mode in production. The default is false. -dev-cluster-json=<string> File to write cluster definition to -dev-listen-address=<string> Address to bind to in "dev" mode. The default is 127.0.0.1:8200. This can also be specified via the VAULT_DEV_LISTEN_ADDRESS environment variable. -dev-no-store-token Do not persist the dev root token to the token helper (usually the local filesystem) for use in future requests. The token will only be displayed in the command output. The default is false. -dev-root-token-id=<string> Initial root token. This only applies when running in "dev" mode. This can also be specified via the VAULT_DEV_ROOT_TOKEN_ID environment variable. -dev-tls Enable TLS development mode. In this mode, Vault runs in-memory and starts unsealed, with a generated TLS CA, certificate and key. As the name implies, do not run "dev-tls" mode in production. The default is false. -dev-tls-cert-dir=<string> Directory where generated TLS files are created if `-dev-tls` is specified. If left unset, files are generated in a temporary directory. -dev-tls-san=<string> Additional Subject Alternative Name (as a DNS name or IP address) to generate the certificate with if `-dev-tls` is specified. The certificate will always use localhost, localhost4, localhost6, localhost.localdomain, and the host name as alternate DNS names, and 127.0.0.1 as an alternate IP address. This flag can be specified multiple times to specify multiple SANs.
The dev server listens on the loopback interface at 127.0.0.1 on TCP port 8200 without TLS enabled by default. At runtime, the dev server also automatically unseals, and prints the unseal key and initial root token values to the standard output.
Open a terminal and start a Vault dev server with the literal string
root
as the root token value, and enable TLS.Root tokens
The dev mode server starts with an initial root token value set.
Root token use should be extremely guarded in production environments because it provides full access to the Vault server.
You can supply the root token value to start Vault in dev mode for convenience and to keep the steps here focused on the learning goals of this tutorial.
$ vault server -dev -dev-root-token-id root -dev-tls
The server starts and emits startup details, and some helpful suggestions to the standard output.
==> Vault server configuration: Administrative Namespace: Api Address: https://127.0.0.1:8200 Cgo: disabled Cluster Address: https://127.0.0.1:8201 Environment Variables: BROWSER, EDITOR, FZF_DEFAULT_OPTS, GOPATH, GPG_TTY, HOME, LANG, LC_ALL, LESS, LESSOPEN, LOGNAME, LSCOLORS, LS_COLORS, MANPATH, NVM_BIN, NVM_CD_FLAGS, NVM_DIR, NVM_INC, OLDPWD, OS_ARCH, PAGER, PATH, PRODUCT, PWD, SHELL, SHLVL, SSH_AGENT_PID, SSH_AUTH_SOCK, STARSHIP_SESSION_KEY, STARSHIP_SHELL, TERM, TERM_PROGRAM, TERM_PROGRAM_VERSION, TERM_SESSION_ID, TMPDIR, USER, VERSION, VISUAL, XPC_FLAGS, XPC_SERVICE_NAME, ZDOTDIR, ZSH, ZSH_TMUX_CONFIG, ZSH_TMUX_TERM, _, _ZSH_TMUX_FIXED_CONFIG, __CFBundleIdentifier Go Version: go1.21.5 Listener 1: tcp (addr: "127.0.0.1:8200", cluster address: "127.0.0.1:8201", disable_request_limiter: "false", max_request_duration: "1m30s", max_request_size: "33554432", tls: "enabled") Log Level: Mlock: supported: false, enabled: false Recovery Mode: false Request Limiter: disabled Storage: inmem Version: Vault v1.16.0-rc2, built 2024-02-20T22:43:58Z Version Sha: f85545f4f6488615859efe1c25b6b9e2b0fbaea3 ==> Vault server started! Log data will stream in below: 2024-04-04T13:24:07.248-0400 [INFO] proxy environment: http_proxy="" https_proxy="" no_proxy="" 2024-04-04T13:24:07.251-0400 [INFO] incrementing seal generation: generation=1 2024-04-04T13:24:07.251-0400 [WARN] no `api_addr` value specified in config or in VAULT_API_ADDR; falling back to detection if possible, but this value should be manually set 2024-04-04T13:24:07.257-0400 [INFO] core: Initializing version history cache for core 2024-04-04T13:24:07.258-0400 [INFO] events: Starting event system 2024-04-04T13:24:07.262-0400 [INFO] core: security barrier not initialized 2024-04-04T13:24:07.262-0400 [INFO] core: security barrier initialized: stored=1 shares=1 threshold=1 2024-04-04T13:24:07.272-0400 [INFO] core: post-unseal setup starting 2024-04-04T13:24:07.285-0400 [INFO] core: loaded wrapping token key 2024-04-04T13:24:07.285-0400 [INFO] core: successfully setup plugin runtime catalog 2024-04-04T13:24:07.285-0400 [INFO] core: successfully setup plugin catalog: plugin-directory="" 2024-04-04T13:24:07.290-0400 [INFO] core: no mounts; adding default mount table 2024-04-04T13:24:07.301-0400 [INFO] core: successfully mounted: type=cubbyhole version="v1.16.0+builtin.vault" path=cubbyhole/ namespace="ID: root. Path: " 2024-04-04T13:24:07.317-0400 [INFO] core: successfully mounted: type=system version="v1.16.0+builtin.vault" path=sys/ namespace="ID: root. Path: " 2024-04-04T13:24:07.325-0400 [INFO] core: successfully mounted: type=identity version="v1.16.0+builtin.vault" path=identity/ namespace="ID: root. Path: " 2024-04-04T13:24:07.333-0400 [INFO] core: successfully mounted: type=token version="v1.16.0+builtin.vault" path=token/ namespace="ID: root. Path: " 2024-04-04T13:24:07.334-0400 [INFO] rollback: Starting the rollback manager with 256 workers 2024-04-04T13:24:07.335-0400 [INFO] rollback: starting rollback manager 2024-04-04T13:24:07.337-0400 [INFO] core: restoring leases 2024-04-04T13:24:07.339-0400 [INFO] identity: entities restored 2024-04-04T13:24:07.339-0400 [INFO] identity: groups restored 2024-04-04T13:24:07.340-0400 [INFO] expiration: lease restore complete 2024-04-04T13:24:07.341-0400 [INFO] core: Recorded vault version: vault version=1.16.0 upgrade time="2024-04-04 17:24:07.341637 +0000 UTC" build date=2024-02-20T22:43:58Z 2024-04-04T13:24:07.345-0400 [INFO] core: post-unseal setup complete 2024-04-04T13:24:07.346-0400 [INFO] core: root token generated 2024-04-04T13:24:07.346-0400 [INFO] core: pre-seal teardown starting 2024-04-04T13:24:07.347-0400 [INFO] rollback: stopping rollback manager 2024-04-04T13:24:07.347-0400 [INFO] core: pre-seal teardown complete 2024-04-04T13:24:07.347-0400 [INFO] core.cluster-listener.tcp: starting listener: listener_address=127.0.0.1:8201 2024-04-04T13:24:07.347-0400 [INFO] core.cluster-listener: serving cluster requests: cluster_listen_address=127.0.0.1:8201 2024-04-04T13:24:07.348-0400 [INFO] core: post-unseal setup starting 2024-04-04T13:24:07.348-0400 [INFO] core: loaded wrapping token key 2024-04-04T13:24:07.348-0400 [INFO] core: successfully setup plugin runtime catalog 2024-04-04T13:24:07.348-0400 [INFO] core: successfully setup plugin catalog: plugin-directory="" 2024-04-04T13:24:07.350-0400 [INFO] core: successfully mounted: type=system version="v1.16.0+builtin.vault" path=sys/ namespace="ID: root. Path: " 2024-04-04T13:24:07.351-0400 [INFO] core: successfully mounted: type=identity version="v1.16.0+builtin.vault" path=identity/ namespace="ID: root. Path: " 2024-04-04T13:24:07.351-0400 [INFO] core: successfully mounted: type=cubbyhole version="v1.16.0+builtin.vault" path=cubbyhole/ namespace="ID: root. Path: " 2024-04-04T13:24:07.352-0400 [INFO] core: successfully mounted: type=token version="v1.16.0+builtin.vault" path=token/ namespace="ID: root. Path: " 2024-04-04T13:24:07.352-0400 [INFO] rollback: Starting the rollback manager with 256 workers 2024-04-04T13:24:07.352-0400 [INFO] rollback: starting rollback manager 2024-04-04T13:24:07.352-0400 [INFO] core: restoring leases 2024-04-04T13:24:07.353-0400 [INFO] expiration: lease restore complete 2024-04-04T13:24:07.353-0400 [INFO] identity: entities restored 2024-04-04T13:24:07.353-0400 [INFO] identity: groups restored 2024-04-04T13:24:07.354-0400 [INFO] core: post-unseal setup complete 2024-04-04T13:24:07.354-0400 [INFO] core: vault is unsealed 2024-04-04T13:24:07.363-0400 [INFO] expiration: revoked lease: lease_id=auth/token/root/h682dc4863bb61206a91b3ba7ebac7f38ce5a37e3f781538171b7f1dd1f360463 2024-04-04T13:24:07.374-0400 [INFO] core: successful mount: namespace="" path=secret/ type=kv version="v0.17.0+builtin" WARNING! dev mode is enabled! In this mode, Vault runs entirely in-memory and starts unsealed with a single unseal key. The root token is already authenticated to the CLI, so you can immediately begin using Vault. You may need to set the following environment variables: $ export VAULT_ADDR='https://127.0.0.1:8200' $ export VAULT_CACERT='/var/folders/qr/zgztx0sj6n1dxy86sl36ntnw0000gn/T/vault-tls3037226588/vault-ca.pem' The unseal key and root token are displayed below in case you want to seal/unseal the Vault or re-authenticate. Unseal Key: 1kDP9lKLzPHZsTzc9TEel3FfclBmKNClhaDhAnDx2J8= Root Token: root Development mode should NOT be used in production installations!
The first section lists Vault server configuration details. This information is helpful to confirm that the server is operating under your desired configuration.
The second section shows server startup log output. This information relates to the operational status of the server during startup.
Since this is a dev server, Vault adds some extra helpful suggestions to the output in the third section.
You can use these suggestions to prepare your Vault client for communicating with the server.
In a new terminal, export the
VAULT_ADDR
andVAULT_CACERT
environment variables using the commands suggested in your Vault dev server output. Copy each command (without the$
) from the server output, and paste it into the new terminal session.Here is an example of the first export command that instructs the client to communicate with the dev mode server.
export VAULT_ADDR='https://127.0.0.1:8200'
Here is an example of the second command to specify the certificate authority file path.
$ export VAULT_CACERT='/var/folders/qr/zgztx0sj6n1dxy86sl36ntnw0000gn/T/vault-tls3037226588/vault-ca.pem'
Remember to use your dev server's values, not the examples shown here.
Check the server status
Now that you have a running Vault server, you can check its status from the command line.
Open a new terminal session, and check the server status.
(Persona: developer)
Check the status of your Vault dev server.
$ vault status
Example output:
Key Value
--- -----
Seal Type shamir
Initialized true
Sealed false
Total Shares 1
Threshold 1
Version 1.16.0
Build Date 2024-02-20T22:43:58Z
Storage Type inmem
Cluster Name vault-cluster-eabfb52b
Cluster ID 6150648b-ed4d-4e5f-8927-223137b0507b
HA Enabled false
Authenticate with Vault
You have a running server, and have checked its status. You're ready to authenticate with Vault.
(Persona: developer)
Authenticate with Vault using the initial root token value.
$ vault login root
Vault prompts you for the token value:
Token (will be hidden):
Type in the literal string root
, and press RETURN
.
Vault responds with a success message, and output containing the token value and metadata.
Success! You are now authenticated. The token information displayed below
is already stored in the token helper. You do NOT need to run "vault login"
again. Future Vault requests will automatically use this token.
Key Value
--- -----
token hvs.Iz85NhcoJ9yl3q9q0FiBqd65
token_accessor Xph6WI0roJRmLmVuM8J9Akky
token_duration ∞
token_renewable false
token_policies ["root"]
identity_policies []
policies ["root"]
Root tokens
Root token use should be extremely guarded in production environments. The root token is used here for convenience and to keep the tutorial steps focused on what you'll learn.
You've started your Vault server, checked its status and authenticated with Vault. From here, you can explore Vault further on your own or clean up the environment.
What are two common environment variables used to configure the Vault CLI?
VAULT_ADDR
specifies the address of the Vault server you are trying to connect
to.
VAULT_CACERT
specifies the path to the TLS certificates used for secure
connections to Vault.
Clean up
(Persona: developer)
Use CTRL+C
to stop the server process in the terminal window where you started the server, or use this command to kill the server process from any local terminal session:
$ pkill vault
Unset environment variables.
$ unset VAULT_ADDR VAULT_CACERT
Summary
Vault has different setup options based on your use case. Developers can run Vault in dev mode to support local testing and development against Vault. For production workloads, operations teams will need to follow the self-managed Vault setup and create a properly written configuration file. Teams can also opt for a production ready cluster managed by HashiCorp by choosing to deploy Vault Enterprise on the HashiCorp Cloud Platform (HCP).