HashiCorp Cloud Platform
AWS automatic secret rotation
Plus tier
This feature is available in HCP Vault Secrets Plus tier.
HCP Vault Secrets allows you to create access keys for an existing AWS IAM user and automatically rotate them on a scheduled interval.
Prerequisites
- Ability to create AWS IAM identity providers, users, and roles
- Your AWS principal may use the managed IAMFullAccess policy or a custom policy for authorization
- Ability to create HCP Vault Secrets integrations, apps, and secrets
Set up AWS
HCP Vault Secrets is able to authenticate with your AWS account using two different methods. Each method requires AWS resources to provision auto-rotating credentials:
- OpenID Connect (OIDC) Federation (Recommended)
- IAM OIDC identity provider
- IAM role that HCP can assume through its web identity
- IAM role with the permissions to grant to the generated dynamic credentials
- Access Keys
- IAM user with an access key pair
- IAM role with the permissions to grant to the generated dynamic credentials
Configure your AWS account using either the AWS console or Terraform.
Add identity provider
Navigate to the Add an Identity provider section in the AWS IAM service.
Select the OpenID connect provider type.
Use
https://idp.hashicorp.com/oidc/organization/<org-id>
as the provider URL, replacing the placeholder with your HCP organization ID.Use
arn:aws:iam::<account-id>:oidc-provider/idp.hashicorp.com/oidc/organization/<org-id>
as the audience, replacing the placeholders with your AWS account ID and HCP organization ID.Note
You can navigate to the AWS integration creation page on the HCP portal and select AWS STS credentials from the list to easily find the appropriate Provider URL and org ID.
Click Add provider.
Select the identity provider you just created and note its ARN and Audience for the next steps.
Create IAM user/role for integration
Create IAM role for integration
Navigate to the Create Role section in the AWS IAM service.
Select the Web Identity trust entity type.
Select the Identity provider and Audience created in the previous step from the dropdown and click Next.
This role needs IAMFullAccess, select and click Next.
Give the role a name and optionally a description and tags, then click Create role.
Select the role you just created and note its ARN for the next steps.
Warning
Be cautious with the AWS access key and secret access key while they are in transit to HCP Vault Secrets. These credentials provide access to your AWS account and and do not automatically expire.
Create a target AWS User
Go to the IAM Users and click Create User.
Enter the username you want IAM access keys for and click Next.
This user does not need any permissions, click Next.
Click Create User, this is the username Vault Secrets will use for creating a rotating secret.
Configure a rotating secret
Navigate to the Vault Secrets app panel and select an app where you want to create a rotating secret.
Click Create new secret and select Auto-rotating secret.
Select the AWS option from the pull down menu.
Select an existing integration or select Add new integration.
Select an Authentication method and follow the appropriate steps below.
Add a new rotating secret
Provide a new Secret Name for this secret.
Enter the username of the IAM user created in the previous section.
Rotation period
There are at most 2 active versions of an auto-rotating AWS credential at a time. In order to ensure that applications are consuming active secrets, it is recommended that applications fetch the latest secret at least once per rotation period.
If an application has multiple rotating secrets, the minimum frequency for fetching the latest secrets should be the minimum of the rotation periods of the auto-rotating secrets.
Note
If an auto-rotating secret is manually rotated, it is recommended that any applications consuming the secret should fetch the latest version.