Skip to main content
In this tutorial, you’ll learn how to set up HashiCorp Vault’s Database Secrets Engine to generate dynamic MySQL credentials for an AWS RDS instance. Dynamic secrets improve security by issuing short-lived, on-demand database users.

1. Enable the Database Secrets Engine

Enable the Database Secrets Engine at the path mysql:
You should see:
Verify the mount:
Expected output:
If you choose a custom mount path, update all subsequent commands (mysql/<your-path>/).

2. Configure the MySQL Database Connection

Tell Vault how to connect to your RDS MySQL instance by specifying:
  • plugin_name: Database plugin (e.g., mysql-rds-database-plugin)
  • connection_url: Go template with {{username}} and {{password}}
  • allowed_roles: Roles permitted to use this connection
  • username/password: Vault credentials with admin privileges
Vault supports multiple MySQL plugins. For AWS RDS use mysql-rds-database-plugin.
The image shows a webpage from the Vault documentation, specifically about the MySQL/MariaDB Database Secrets Engine. It includes information on capabilities, setup, and available plugins for managing database credentials.
Assuming your RDS endpoint is database-1.cf5jhixkss7a.us-east-1.rds.amazonaws.com:3306, configure Vault:
Vault will immediately validate this connection.

Verify RDS Endpoint in AWS Console

In the AWS RDS console, confirm your instance endpoint (and port 3306):
The image shows an Amazon RDS console displaying details of a database instance named "database-1," including its connectivity, security settings, and endpoint information.
The master username (admin) and other configuration details are under Configuration:
The image shows an Amazon RDS console displaying configuration details for a database instance, including instance class, storage, and availability settings.

3. Create a Role for Dynamic Credentials

Define a Vault role called advanced. This role tells Vault how to provision database users:
Adjust the SQL in creation_statements to grant required permissions (e.g., INSERT, UPDATE, etc.).
Inspect the role:
Expected output:
View the database connection configuration:
Vault hides admin credentials:

4. Rotate the Root Credentials (Optional)

To rotate the stored admin credentials for mysql-database:
Vault will contact RDS and update the admin password in Vault.

5. Generate Dynamic Credentials

Request credentials for the advanced role:
Example response:
Every call issues a unique user/password pair with its own lease.

6. Revoke Leases

Revoke a specific lease:
Or revoke all leases under the advanced prefix:
Revoked credentials immediately lose access to the database.

Summary

  1. Enabled Vault’s Database Secrets Engine at mysql/.
  2. Configured a connection to an AWS RDS MySQL instance.
  3. Created a Vault role (advanced) to provision dynamic users.
  4. Optionally rotated the stored admin credentials.
  5. Generated and revoked short-lived MySQL credentials.
Vault’s Database Secrets Engine ensures on-demand, rolling credentials for stronger security.

Watch Video

Practice Lab