Secrets management
HashiCorp Vault

Install and configure HashiCorp Vault

14min

The Vault Hardware Security Module (HSM) auto-unseal and Seal Wrap features require Vault Enterprise with the Governance & Policy module.

Perform the following tasks to install and configure Vault:

1 | Download Vault

You can download precompiled Vault binaries at https://releases.hashicorp.com/vault/. Download Vault Enterprise binaries by following the instructions available to HashiCorp Vault customers.

This integration requires the Enterprise HSM binary. You can use the following link for testing: https://releases.hashicorp.com/vault/

2 | Install Vault

1

Unzip the downloaded package and move the vault binary to /usr/local/bin/.

Shell

2

Set the owner of the Vault binary.

Shell

3

Check that vault is available on the system path.

Shell

4

Verify the Vault version.

Shell

5

The vault command features opt-in autocompletion for flags, subcommands, and arguments (where supported).

Shell

6

Enable autocompletion.

Shell

7

Give Vault the ability to use the mlock syscall without running the process as root. The mlock syscall prevents memory from being swapped to disk.

Shell

8

Create a unique, non-privileged system user to run Vault.

Shell


3 | Configure systemd

Systemd uses documented sane defaults, so you must set only non-default values in the configuration file.

1

Create a Vault service file at /etc/systemd/system/vault.service.

Shell

2

Add the following configuration to the Vault service file:

Text


4 | Configure Vault

Vault uses documented sane defaults, so you need to set only non-default values in the configuration file.

1

Create /etc/vault.d directory.

Shell

2

Create a Vault configuration file, vault.hcl.

Shell

3

Set the ownership of the /etc/vault.d directory.

Shell

4

Set the file permissions.

Shell


5 | Configure HSM Auto-unseal and Entropy Augmentation

When a Vault server is started, it normally starts in a sealed state where a quorum of existing unseal keys is required to unseal it. By integrating Vault with the , a trusted HSM key provider can automatically unseal the Vault server.

To integrate the Vault Enterprise server with a , the configuration file must define the PKCS11 seal stanza providing necessary connection information.

Example: vault.hcl

Text


This guide sets the storage backend to the local file system (/tmp/vault) to make the verification step easy.

The example configuration defines the following in its seal stanza:

  • lib: Path to the PKCS #11 library on the machine where Vault Enterprise is installed.
  • slot : The slot number to use (this should be set to "0" because "0" is the slot that is set by default in the FXPKCS11 config file).
  • key_label: Defines the label of the key to use.
  • hmac_key_label: Defines the label of the key to use for HMACing.
  • generate_key: If no existing key with the label specified by key_label can be found at Vault initialization time, Vault generates a key.
For this integration, set the generate_key parameter to true so that Vault automatically creates the encryption keys that it uses for the Seal Wrap functionality on the . The values set for the key_label and hmac_key_label parameters correspond with the special key label defines that must be set in the <CONFIG> section of the fxpkcs11.cfg file.

For the full list of configuration parameters, please refer to the Vault documentation here.

6| Start the Vault Server

1

First, log in with the vault user.

2

Next, set the PKCS #11 PIN for login with the following command (this is the identity password configured inside the <CRYPTO-OPR-PASS> tag in the fxpkcs11.cfg file).

Shell


The PKCS #11 PIN can also be set in the Vault configuration file (vault.hcl) with the pin parameter, but we do not recommend this in a production setting. The best practice is to specify the pin with the VAULT_HSM_PIN environment variable, as shown here. This prevents the password from being exposed if the config file is compromised or stored in an unsecured location. If set through the environment variable, Vault obfuscates the environment variable after reading it. The one caveat is that you must rest the VAULT_HSM_PIN environment variable if you restart Vault.

3

Now, start the Vault server with the following command.

Shell


If the command succeeded, you should see something similar to the following output:

Text

4

Open a new terminal window and leave the terminal where you started the Vault server running.

a | Initialize Vault

1

In the new terminal, first, set the VAULT_ADDR environment variable.

Shell

2

Check the Vault status.

Shell


The output should be similar to the following:

Text

3

Initialize Vault.

Shell


The output should be similar to the following:

Text

4

Set the VAULT_TOKEN environment variable value to the generated Root Token value displayed in the terminal output.

Shell


To interact with Vault, you must provide a valid token. Setting this environment variable allows interaction with Vault through the CLI.

b | Access the Vault UI

1

Go to http://localhost:8200 in a web browser.

2

Copy and paste the Initial Root Token output from the Vault initialization command into the Token field, and select [ Sign In ].

If the login succeeds, you see the Vault UI homepage.

7 | Enable and test the Seal Wrap feature

Perform the following tasks:

a | Enable Seal Wrap

Select one of the following methods to enable Seal Wrap and follow the instructions:

CLI command
Web UI
1

To compare seal-wrapped data against unwrapped data, enable key/value v1 secrets engine at two different paths: kv-unwrapped and kv-seal-wrapped.

  • Enable k/v v1 without seal wrap at kv-unwrapped.
  • Enable k/v v1 with seal wrap, by using the -seal-wrap flag when you enable the KV workflow.

To enable Seal Wrap, pass the -seal-wrap flag when you enable a secrets engine.

2

List the enabled secrets engines with details.

Shell


Notice that the Seal Wrap parameter value is true for kv-seal-wrapped/.

3



b | Test the Seal Wrap feature

Select one of the following methods to test Seal Wrap and follow the instructions:

CLI command
Web UI

Perform the following steps to test the Seal Wrap feature:

1

Write a secret at kv-unwrapped/unwrapped for testing.

Shell

2

Read the path to verify.

Shell

3

Write the same secret at kv-seal-wrapped/wrapped for testing.

Shell

4

Read the path to verify.

Shell


Using a valid token, you can write and read secrets the same way regardless of the Seal Wrap.

Perform the following steps to view the encrypted secrets:

Remember that you configured the Vault server to use the same local file as the system (/tmp/vault) as its storage backend in this example:

Text

1

SSH into the machine where the Vault server is running, and check the stored values in the /tmp/vault directory.

Shell


The /tmp/vault/logical directory has two sub-directories. One maps to kv-unwrapped/ and another maps to kv-seal-wrapped/ although you cannot tell by the folder names.

2

View the secret at rest. One of the directories maps to kv-unwrapped/unwrapped.

Example:

Shell

3

View its content. The password value is encrypted.

Shell

4

Another directory maps to kv-seal-wrapped/wrapped.

Shell

5

View its content. The password value is encrypted.

Shell


Secrets are encrypted regardless. However, the seal-wrapped value is significantly longer even though both values are the same (my-long-password).

8 | Enable and test the Entropy Augmentation feature

To leverage an external entropy source, the external_entropy_access parameter must be set to true when you enable a secrets engine or auth method.

This step enables the as the external entropy source on a transit secrets engine.

The Entropy Augmentation feature must be enabled through the CLI. Currently, we do not support enabling Entropy Augmentation through the Web UI.

1

Execute the following command to enable transit secrets engine with external entropy source using the -external-entropy-access flag.

Shell

2

List the enabled secrets engine with -detailed flag.

Shell


Notice that the External Entropy Access is set to true for transit/.

3

You can start using the transit secrets engine to encrypt your sensitive data which leverages the as its external entropy source. Regardless, the user experience remains the same as before.

Example: Create a new encryption key named, "orders".

Shell


Send a base64-encoded string to be encrypted by Vault.

Shell


Now, test to verify that you can decrypt.

Shell


Decode to get the original data.

Shell


When the external entropy access is enabled, you need connectivity to the . If the becomes unreachable for any reason, the transit secrets engine fails to generate new keys or rotate the existing keys. The error is similar to the following example:

Text