2015-04-10 01:46:44 +00:00
|
|
|
---
|
|
|
|
layout: "intro"
|
2017-07-14 15:15:22 +00:00
|
|
|
page_title: "Deploy Vault - Getting Started"
|
2015-04-10 01:46:44 +00:00
|
|
|
sidebar_current: "gettingstarted-deploy"
|
|
|
|
description: |-
|
|
|
|
Learn how to deploy Vault into production, how to initialize it, configure it, etc.
|
|
|
|
---
|
|
|
|
|
|
|
|
# Deploy Vault
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
Up to this point, we have been working with the "dev" server, which
|
|
|
|
automatically authenticated us, setup in-memory storage, etc. Now that you know
|
|
|
|
the basics of Vault, it is important to learn how to deploy Vault into a real
|
|
|
|
environment.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
On this page, we'll cover how to configure Vault, start Vault, the seal/unseal
|
|
|
|
process, and scaling Vault.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
|
|
|
## Configuring Vault
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
Vault is configured using [HCL][hcl] files. The configuration file for Vault is
|
|
|
|
relatively simple:
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```hcl
|
2017-06-20 14:45:54 +00:00
|
|
|
storage "consul" {
|
2015-05-28 12:11:34 +00:00
|
|
|
address = "127.0.0.1:8500"
|
2018-03-22 13:29:59 +00:00
|
|
|
path = "vault/"
|
2015-04-10 01:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
listener "tcp" {
|
2017-09-21 17:39:26 +00:00
|
|
|
address = "127.0.0.1:8200"
|
2015-04-22 23:47:11 +00:00
|
|
|
tls_disable = 1
|
2015-04-10 01:46:44 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Within the configuration file, there are two primary configurations:
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
- `storage` - This is the physical backend that Vault uses for storage. Up to
|
|
|
|
this point the dev server has used "inmem" (in memory), but the example above
|
|
|
|
uses [Consul](https://www.consul.io), a much more production-ready backend.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
- `listener` - One or more listeners determine how Vault listens for API
|
|
|
|
requests. The example above listens on localhost port 8200 without TLS. In
|
|
|
|
your environment set `VAULT_ADDR=http://127.0.0.1:8200` so the Vault client
|
|
|
|
will connect without TLS.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
For now, copy and paste the configuration above to a file called `config.hcl`.
|
|
|
|
It will configure Vault to expect an instance of Consul running locally.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2015-05-28 12:11:34 +00:00
|
|
|
Starting a local Consul instance takes only a few minutes. Just follow the
|
|
|
|
[Consul Getting Started Guide](https://www.consul.io/intro/getting-started/install.html)
|
|
|
|
up to the point where you have installed Consul and started it with this command:
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```text
|
|
|
|
$ consul agent -dev
|
2015-05-28 12:11:34 +00:00
|
|
|
```
|
2015-04-10 01:46:44 +00:00
|
|
|
|
|
|
|
## Starting the Server
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
With the configuration in place, starting the server is simple, as shown below.
|
|
|
|
Modify the `-config` flag to point to the proper path where you saved the
|
|
|
|
configuration above.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```text
|
|
|
|
$ vault server -config=config.hcl
|
2015-04-10 01:46:44 +00:00
|
|
|
==> Vault server configuration:
|
|
|
|
|
|
|
|
Log Level: info
|
2017-06-20 14:45:54 +00:00
|
|
|
Storage: consul
|
2015-04-10 01:46:44 +00:00
|
|
|
Listener 1: tcp (addr: "127.0.0.1:8200", tls: "disabled")
|
|
|
|
|
|
|
|
==> Vault server started! Log data will stream in below:
|
|
|
|
```
|
|
|
|
|
2018-02-07 14:38:11 +00:00
|
|
|
-> If you get a warning message about mlock not being supported, that is okay.
|
2017-09-21 17:39:26 +00:00
|
|
|
However, you should run Vault on a system that supports mlock for maximum
|
|
|
|
security.
|
|
|
|
|
2015-04-10 01:46:44 +00:00
|
|
|
Vault outputs some information about its configuration, and then blocks.
|
|
|
|
This process should be run using a resource manager such as systemd or
|
|
|
|
upstart.
|
|
|
|
|
|
|
|
You'll notice that you can't execute any commands. We don't have any
|
|
|
|
auth information! When you first setup a Vault server, you have to start
|
|
|
|
by _initializing_ it.
|
|
|
|
|
2015-05-28 11:24:28 +00:00
|
|
|
On Linux, Vault may fail to start with the following error:
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```text
|
2015-05-28 11:24:28 +00:00
|
|
|
$ vault server -config=example.hcl
|
|
|
|
Error initializing core: Failed to lock memory: cannot allocate memory
|
|
|
|
|
|
|
|
This usually means that the mlock syscall is not available.
|
|
|
|
Vault uses mlock to prevent memory from being swapped to
|
|
|
|
disk. This requires root privileges as well as a machine
|
|
|
|
that supports mlock. Please enable mlock on your system or
|
|
|
|
disable Vault from using it. To disable Vault from using it,
|
|
|
|
set the `disable_mlock` configuration option in your configuration
|
|
|
|
file.
|
|
|
|
```
|
|
|
|
|
|
|
|
For guidance on dealing with this issue, see the discussion of
|
2017-03-17 18:27:20 +00:00
|
|
|
`disable_mlock` in [Server Configuration](/docs/configuration/index.html).
|
2015-05-28 11:24:28 +00:00
|
|
|
|
2015-04-10 01:46:44 +00:00
|
|
|
## Initializing the Vault
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
Initialization is the process configuring the Vault. This only happens once when
|
|
|
|
the server is started against a new backend that has never been used with Vault
|
|
|
|
before. When running in HA mode, this happens once _per cluster_, not _per
|
|
|
|
server_.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
During initialization, the encryption keys are generated, unseal keys are
|
|
|
|
created, and the initial root token is setup. To initialize Vault use `vault
|
2018-04-11 18:26:53 +00:00
|
|
|
operator init`. This is an _unauthenticated_ request, but it only works on brand new
|
2017-09-21 17:39:26 +00:00
|
|
|
Vaults with no data:
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```text
|
|
|
|
$ vault operator init
|
|
|
|
Unseal Key 1: E4GnjX+VP9G50uWQNcwpCflzGAMKGR38BbQywgq4I6L8
|
|
|
|
Unseal Key 2: PYMxcCOswEYMNz7N6UW53Up6nu6y+SjAPwTJOTtkju3d
|
|
|
|
Unseal Key 3: yuJ5cSxC7tSBR5mMVJ/WJ9bfhhfGb+uwWw9FQR0JKILh
|
|
|
|
Unseal Key 4: 0vdvEFHM9PHEGMctJrl2ylHqoKQK8DLkfMU6ntmDz6jv
|
|
|
|
Unseal Key 5: cI8yglWJX+jPf/yQG7Sg6SPWzy0WyrBPvaFTOAYkPJTx
|
|
|
|
|
|
|
|
Initial Root Token: 62421926-81b9-b202-86f8-8850176c0cf3
|
|
|
|
|
2018-02-07 14:38:11 +00:00
|
|
|
Vault initialized with 5 key shares and a key threshold of 3. Please securely
|
|
|
|
distribute the key shares printed above. When the Vault is re-sealed,
|
2017-09-21 17:39:26 +00:00
|
|
|
restarted, or stopped, you must supply at least 3 of these keys to unseal it
|
|
|
|
before it can start servicing requests.
|
|
|
|
|
|
|
|
Vault does not store the generated master key. Without at least 3 key to
|
|
|
|
reconstruct the master key, Vault will remain permanently sealed!
|
|
|
|
|
|
|
|
It is possible to generate new unseal keys, provided you have a quorum of
|
|
|
|
existing unseal keys shares. See "vault rekey" for more information.
|
2015-04-10 01:46:44 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Initialization outputs two incredibly important pieces of information:
|
|
|
|
the _unseal keys_ and the _initial root token_. This is the
|
|
|
|
**only time ever** that all of this data is known by Vault, and also the
|
|
|
|
only time that the unseal keys should ever be so close together.
|
|
|
|
|
2016-06-03 17:23:20 +00:00
|
|
|
For the purpose of this getting started guide, save all of these keys
|
2015-04-10 01:46:44 +00:00
|
|
|
somewhere, and continue. In a real deployment scenario, you would never
|
2016-04-12 20:43:55 +00:00
|
|
|
save these keys together. Instead, you would likely use Vault's PGP and
|
2016-06-03 17:23:20 +00:00
|
|
|
Keybase.io support to encrypt each of these keys with the users' PGP keys.
|
2016-04-12 20:43:55 +00:00
|
|
|
This prevents one single person from having all the unseal keys. Please
|
2016-06-21 16:14:58 +00:00
|
|
|
see the documentation on [using PGP, GPG, and Keybase](/docs/concepts/pgp-gpg-keybase.html)
|
2016-04-12 20:43:55 +00:00
|
|
|
for more information.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
|
|
|
## Seal/Unseal
|
|
|
|
|
|
|
|
Every initialized Vault server starts in the _sealed_ state. From
|
|
|
|
the configuration, Vault can access the physical storage, but it can't
|
|
|
|
read any of it because it doesn't know how to decrypt it. The process
|
|
|
|
of teaching Vault how to decrypt the data is known as _unsealing_ the
|
|
|
|
Vault.
|
|
|
|
|
|
|
|
Unsealing has to happen every time Vault starts. It can be done via
|
|
|
|
the API and via the command line. To unseal the Vault, you
|
|
|
|
must have the _threshold_ number of unseal keys. In the output above,
|
|
|
|
notice that the "key threshold" is 3. This means that to unseal
|
|
|
|
the Vault, you need 3 of the 5 keys that were generated.
|
|
|
|
|
|
|
|
-> **Note:** Vault does not store any of the unseal key shards. Vault
|
|
|
|
uses an algorithm known as
|
2016-01-14 18:42:47 +00:00
|
|
|
[Shamir's Secret Sharing](https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing)
|
2015-04-10 01:46:44 +00:00
|
|
|
to split the master key into shards. Only with the threshold number of keys
|
|
|
|
can it be reconstructed and your data finally accessed.
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
Begin unsealing the Vault:
|
|
|
|
|
|
|
|
```text
|
|
|
|
$ vault operator unseal
|
|
|
|
Unseal Key (will be hidden):
|
|
|
|
Key Value
|
|
|
|
--- -----
|
|
|
|
Sealed true
|
|
|
|
Total Shares 5
|
|
|
|
Unseal Progress 1/3
|
|
|
|
Unseal Nonce 786e7190-d1e2-84d2-520c-022efee5b71e
|
|
|
|
Version (version unknown)
|
|
|
|
HA Enabled true
|
|
|
|
HA Mode sealed
|
2015-04-10 01:46:44 +00:00
|
|
|
```
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
After pasting in a valid key and confirming, you'll see that the Vault is still
|
|
|
|
sealed, but progress is made. Vault knows it has 1 key out of 3. Due to the
|
|
|
|
nature of the algorithm, Vault doesn't know if it has the _correct_ key until
|
|
|
|
the threshold is reached.
|
|
|
|
|
|
|
|
Also notice that the unseal process is stateful. You can go to another computer,
|
|
|
|
use `vault unseal`, and as long as it's pointing to the same server, that other
|
|
|
|
computer can continue the unseal process. This is incredibly important to the
|
|
|
|
design of the unseal process: multiple people with multiple keys are required to
|
|
|
|
unseal the Vault. The Vault can be unsealed from multiple computers and the keys
|
|
|
|
should never be together. A single malicious operator does not have enough keys
|
|
|
|
to be malicious.
|
|
|
|
|
|
|
|
Continue with `vault unseal` to complete unsealing the Vault. To unseal the
|
|
|
|
vault you must use three _different_ keys, the same key repeated will not work.
|
|
|
|
As you use keys, as long as they are correct, you should soon see output like
|
|
|
|
this:
|
|
|
|
|
|
|
|
```text
|
|
|
|
$ vault operator unseal
|
|
|
|
Unseal Key (will be hidden):
|
|
|
|
# ...
|
|
|
|
|
|
|
|
$ vault operator unseal
|
|
|
|
Unseal Key (will be hidden):
|
|
|
|
# ...
|
2015-04-10 01:46:44 +00:00
|
|
|
```
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
When the value for `Sealed` changes to `false`, the Vault is unsealed:
|
|
|
|
|
|
|
|
```text
|
|
|
|
Key Value
|
|
|
|
--- -----
|
|
|
|
Sealed false <--
|
|
|
|
Total Shares 5
|
|
|
|
Version (version unknown)
|
|
|
|
Cluster Name vault-cluster-8a8b2c36
|
|
|
|
Cluster ID 34e94a2e-2d8f-c7cc-271d-96fd438ccc6d
|
|
|
|
HA Enabled true
|
|
|
|
HA Mode standby
|
|
|
|
HA Cluster n/a
|
|
|
|
```
|
2015-04-10 01:46:44 +00:00
|
|
|
|
|
|
|
Feel free to play around with entering invalid keys, keys in different
|
2017-09-21 17:39:26 +00:00
|
|
|
orders, etc. in order to understand the unseal process.
|
|
|
|
|
|
|
|
Finally, authenticate as the initial root token (it was included in the output
|
|
|
|
with the unseal keys):
|
|
|
|
|
|
|
|
```text
|
|
|
|
$ vault login 14d1316e-78f6-910b-a4cc-9ba6697ec814
|
|
|
|
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 14d1316e-78f6-910b-a4cc-9ba6697ec814
|
|
|
|
token_accessor a8bbcc57-9be6-6584-a7a6-46290962fd33
|
|
|
|
token_duration ∞
|
|
|
|
token_renewable false
|
|
|
|
token_policies [root]
|
|
|
|
```
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
As a root user, you can reseal the Vault with `vault seal`. A single operator is
|
|
|
|
allowed to do this. This lets a single operator lock down the Vault in an
|
|
|
|
emergency without consulting other operators.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
When the Vault is sealed again, it clears all of its state (including the
|
|
|
|
encryption key) from memory. The Vault is secure and locked down from access.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
|
|
|
## Next
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
You now know how to configure, initialize, and unseal/seal Vault. This is the
|
|
|
|
basic knowledge necessary to deploy Vault into a real environment. Once the
|
|
|
|
Vault is unsealed, you access it as you have throughout this getting started
|
|
|
|
guide (which worked with an unsealed Vault).
|
|
|
|
|
|
|
|
Next, we have a [short tutorial](/intro/getting-started/apis.html) on using the
|
|
|
|
HTTP APIs to authenticate and access secrets.
|
2015-04-10 01:46:44 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
[hcl]: https://github.com/hashicorp/hcl
|