HashiCorp Cloud Platform
GCP automatic secret rotation
Plus tier
This feature is available in HCP Vault Secrets Plus tier.
GCP allows users to upload a public key for a given service account. The corresponding private key can then be used to authenticate with GCP as the service account.
HCP Vault Secrets can create and automatically rotate these GCP service account public keys while securely maintaining the corresponding private keys.
Prerequisites
Ability to create, upload, and manage GCP service account keys
- Your GCP principal may use the predefined Service Account Key Admin role for authorization
- Your GCP organization may need to be granted other policies to allow service account keys to be uploaded
- Your GCP organization should have the
iam.disableServiceAccountKeyUpload
policy disabled or exempted
Ability to create HCP Vault Secrets integrations, apps, and secrets
Set up GCP
HCP Vault Secrets is able to authenticate with your GCP project using two different methods. Each method requires GCP resources to rotate secrets.
- Workload Identity Federation (Recommended)
- Workload identity pool
- Workload identity provider
- IAM service account that HCP can impersonate through its web identity
- IAM service account with the permissions to grant to the generated rotating credentials
- Service Account Keys
- IAM service account with a key
- IAM service account with the permissions to grant to the generated rotating credentials
Add identity provider
Navigate to the New workload provider and pool section in the Google Cloud IAM & Admin service.
Provide a name and optionally a description then click Continue.
Select the OpenID connect (OIDC) provider type.
Provide a descriptive name such as
hcp-rotating-secrets-<project-name>
.Use
https://idp.hashicorp.com/oidc/organization/<org-id>
as the issuer URL, replacing the placeholder with your HCP organization ID.Note
You can navigate to the GCP integration creation page on the HCP portal and select GCP service account credentials from the list to easily find the appropriate Issuer URL.
Note the default audience for the next steps then click Continue.
Enter
assertion.sub
in the OIDC 1 input field to map the provider attributes then click Save.
Create service account for integration
Click + Grant Access by the top navigation bar.
Select Grant access using Service Account Impersonation.
Click the drop-down menu for Select service account, then New Service Account.
Provide a descriptive name such as
hvs-rotating-secrets-integration
and optionally a description, then click Create and Continue.Select the Service Account Key Admin role, then click Continue.
Do not grant users access to this service account, simply click Done.
Navigate back to the Grant Access panel and select the service account we just created.
Use
project:<project-id>:geo:us:service:vault-secrets:type:integration:name:<integration-name>
as the attribute value, replacing the placeholders with your HCP project ID and HCP integration name.Note
You can navigate to the GCP integration creation page on the HCP portal and select GCP service account credentials from the list to easily find the appropriate Service Account subject.
Dismiss the Configure your application modal.
Click to Service Accounts in the left navigation bar, and note the email for the service account you just created for the next steps.
Create service account for the rotating secret
Navigate to the Create Service Account section in the Google Cloud IAM & Admin service.
Give the service account a name and optionally a description, then click Create and Continue.
Click on Service Accounts in the left navigation bar, and note the service account email you just created for the next steps.
Configure rotating secrets
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 GCP 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.
Provide a unique Integration Name for this integration.
Use the integration service account email configured during the previous steps.
Use the GCP workload identity provider audience configured during the previous steps. The format is
https://iam.googleapis.com/projects/<project>/locations/global/workloadIdentityPools/<pool-name>/providers/<provider-name>
.Click Add new integration to return to the new secret form.
Note
If you encounter an error, make sure the service account subject and audience matches between HCP and GCP.
Add new auto-rotating secret
Provide a unique Secret Name for this secret.
Select a Rotation frequency from the dropdown.
Use the rotating secret service account email configured during the previous steps.
Rotation period
There are at most 2 active versions of an auto-rotating GCP 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.