User configurable password generation for secret engines
Challenge
Vault's secret engines generate passwords that adhere to a default pattern that may not meet the standards required by your applications or within your organization. You may require passwords with:
- Lengths that are smaller or exceed the default length
- Differing character sets
- Frequency of characters
- Positional requirements for characters
- Disallowed repetition
- Disallowed words from a dictionary
Solution
Vault 1.5 introduced support for configurable password generation defined by a password policy. A policy defines the rules and requirements that the password must adhere and can provide that password directly through a new endpoint or within secrets engines.
Secrets engines with support for password policies:
Prerequisites
This lab was tested on macOS using an x86_64 based processor. If you are running macOS on an Apple silicon-based processor, click the Start interactive lab button or perform the steps using a x86_64 based Linux virtual machine in your preferred cloud provider.
Vault version 1.5 or later; refer to the Vault install guide to install Vault.
RabbitMQ environment or Docker.
ngrok installed and configured with auth token (HCP Vault Dedicated only)
Launch Terminal
This tutorial includes a free interactive command-line lab that lets you follow along on actual cloud infrastructure.
Lab setup
Start RabbitMQ
RabbitMQ is a message-broker that has a secrets engine that enables Vault to generate user credentials.
In a new terminal, start a RabbitMQ server running on port 15672
that
has a user named learn_vault
with the password hashicorp
.
Docker downloads the necessary images and launches a RabbitMQ database container. RabbitMQ is ready for Vault to generate credentials.
Start Vault
A Vault server is able to generate passwords that meet the requirements of a configurable password policy. These password policies may also be applied to supported secrets engines.
In another terminal, start a Vault dev server with
root
as the root token.Insecure operation
Do not run a Vault dev server in production. This approach is only used here to simplify the unsealing process for this demonstration.
Export an environment variable for the
vault
CLI to address the Vault server.Login with the root token.
The Vault server is ready to explore password policies.
Set an environment variable for the RabbitMQ address.
You are ready to proceed with the lab.
Setup RabbitMQ secrets engine with the default password policy
The RabbitMQ secrets engine generates passwords that adhere to a default password policy.
Enable the RabbitMQ secrets engine at the
rabbitmq-default-policy
path.The secrets engine requires configuration so it can communicate with the RabbitMQ server.
Configure the secrets engine to connect to the RabbitMQ server.
Output:
The secrets engine is configured to talk to the RabbitMQ server running locally over the HTTP management interface. The user,
learn_vault
, with its passwordhashicorp
, is an administrator that was generated when RabbitMQ started.Create a role named
example
.Output:
The
example
role defines an endpoint for dynamic credential generation. The credentials generated are granted read and write every entity.Generate credentials from the
example
role.Example output:
The credentials display the
username
andpassword
generated. The password generated,v0E6LjTeabrtEAz72cbYINNodWSApPS61vGP
, adheres to the default password policy for the secrets engine.
Define a password policy
Create a policy file named
example_policy.hcl
.The policy is written in HashiCorp Configuration Language (HCL). The
length
field sets the length of the password returned to20
characters. Each rule stanza defines a character set and the minimum number of occurrences those characters need to appear in the generated password. These rules are cumulative so each one adds more requirements on the password generated.Create a Vault password policy named
example
with the password policy rules defined inexample_policy.hcl
.This policy can now be accessed directly to generate a password or referenced by its name
example
when configuring supported secrets engines.Generate a password from the
example
password policy.The password generated adheres to the requirements:
- length of 20 characters
- at least 1 uppercase character
- at least 1 lowercase character
- at least 1 number
- at least 1 symbol
Setup RabbitMQ secrets engine with a password policy
The RabbitMQ secrets engine may be configured to adopt a password policy.
Enable the RabbitMQ secrets engine at the
rabbitmq-with-policy
path.The secrets engine requires configuration so it can communicate with the RabbitMQ server.
Configure the secrets engine to connect to the RabbitMQ server and use the
example
password policy.Output:
The same connection information is used to establish the connection with the RabbitMQ server. The difference is that the
password_policy
has been set to theexample
policy defined in Define a password policy section.Create a role named
example
.Output:
The
example
role defines an endpoint for dynamic credential generation. The credentials generated are granted read and write on every entity.Generate a login from the
example
role.Example output:
The credentials display the
username
andpassword
generated. Thepassword
generated,HtjHFtdy21*iBpNZjLNb
, adheres to the example password policy defined in the secrets engine's configuration.
Next steps
You configured a RabbitMQ secrets engine that generated credentials with the default password policy. Learn more about the RabbitMQ secrets engine by reading the documentation and the API documentation.
Then you defined a password policy and generated a password. Learn more about by reading the documentation and the API documentation.
Finally, you configured another RabbitMQ secrets engine that generated credentials that used a custom password policy.