Configure password generation polices for secret engines
Vault supports 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.
In the dynamic secrets tutorial, you configured Vault to generate dynamic credentials for a PostgreSQL database. In this tutorial, you will learn how to configure Vault to generate passwords that meet your organization's standards.
If you are not familar with how to configure Vault for dynamic credentials, follow the database secrets engine tutorial before you begin.
Scenario
HashiCups has a password policy that must be used for all application. Vault's database secrets engine generates passwords that adhere to a default pattern.
Secrets engines with support for password policies:
You can edit the default pattern to fit usecases such as:
- 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
Oliver will create a custom password policy that fullfils HashiCups security standars. The password requirements are:
- Length of 20 characters
- Multiple character sets
- Minumum number of characters from each set
Prerequisites
This lab was tested on macOS using an x86_64 based and Apple silicon-based processors. You may also run this tutorial by clicking the Start interactive lab button.
Launch Terminal
This tutorial includes a free interactive command-line lab that lets you follow along on actual cloud infrastructure.
To perform the tasks described in this tutorial, you need to have:
- Docker to run a Vault and PostgreSQL container.
- Vault binary installed.
- Git installed.
Set up the lab
Clone the
learn-vault-dynamic-credentials
repository.Change into the
learn-vault-dynamic-credentials
directory.Deploy the Vault and PostgreSQL containers.
Example output:
Copy the export command from the Terraform output and export the environment variables.
Example:
Verify the PostgreSQL and Vault containers have started.
Vault and PostgreSQL are running. Vault connects to PostgreSQL over the Docker bridge network.
Apply the PostgreSQL configuration used in the dynamic secrets tutorial.
Example output:
Apply the Vault configuration used in the dynamic secrets tutorial.
Example output:
Vault and PostgreSQL are running and configured. You are ready to proceed with the tutorial.
Request credentials with default password policy
Each supported secrets engine has a default password policy that generates passwords.
Generate credentials from the
readonly
role.Example output:
The credentials display the
username
andpassword
generated. The password generated adheres to the default password policy for the secrets engine.
Define a password policy
Create a policy file named
example_policy.hcl
.Policies use the 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 is accessible 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
Configure a custom password policy
Review the current database secrets engine configuration.
The secrets engine initially configured does not contain a password policy.
Configure the secrets engine to use the
example
password policy.Review the updated database secrets engine configuration.
Example output:
The secrets engine now generates passwords that adhere to the
example
password policy.Generate credentials from the
readonly
role with theexample
password policy.The credentials display the
username
andpassword
generated. Thepassword
generated adheres to the example password policy defined in the secrets engine's configuration.
Clean up
Destroy the Terraform resources.
Unset the environment variables.
Delete the
example_policy.hcl
password policy file.
Summary
You requested credentials from the database secrets engine that generated credentials with the default password policy. Then you defined a password policy and generated a password. Finally, you updated the secrets engine configuration to use the custom password policy.