Manage dynamic credential leases
In the dynamic secrets tutorial, you configured Vault to generate dynamic credentials for a PostgreSQL database. In this tutorial, you will learn how to manage the leases for these dynamic credentials.
If you are not familar with how to configure Vault for dynamic credentials, follow the database secrets engine tutorial before you begin.
Scenario
HashiCups configured Vault to generate dynamic credentials for their PostgreSQL database. Danielle and the development team successfully retrieved the credentials from Vault.
Oliver and the operations team need to manage the generated credentials to ensure credentials can be renewed or revoked as needed.
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.
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.
Renew leases
(Persona: Operations)
The credentials are managed by the lease ID and remain valid for the lease duration (TTL), renewed up to the maximum TTO, or until revoked. Once revoked the credentials are no longer valid.
Read the Vault
readonly
role to generate PostgreSQL credentials.List the existing leases.
All valid leases for database credentials are displayed.
Create a variable that stores the first lease ID.
Renew the lease for the database credential by passing its lease ID.
The TTL of the renewed lease is now
1h
.
Revoke leases
(Persona: Operations)
You can revoke leases using the lease ID or by specifying a path prefix to revoke all leases associated with the role.
Revoke the lease without waiting for its expiration.
List the existing leases.
The lease is no longer valid and is not displayed.
Read new credentials from the
readonly
database role.Revoke all the leases with the prefix
database/creds/readonly
.The
prefix
flag matches all valid leases with the path prefix ofdatabase/creds/readonly
.List the existing leases.
You have revoked all the leases associated with this path.
Clean up
Destroy the Terraform resources.
Unset the environment variables.
Summary
In this tutorial, you learned how to manage the leases for dynamic credentials. You requested credentials from Vault, renewed the lease, and revoked the lease using both the lease ID and the path prefix.