This page describes how to configure automatic rotation for your Cloud SQL database credentials in Secret Manager.
Before you begin
- Ensure that your Cloud SQL instance uses a supported database engine flavor, such as PostgreSQL or SQL Server.
- Ensure that you are using a regional secret. Automatic rotation for Cloud SQL credentials is available only for regional secrets in Secret Manager. Global secrets don't support this feature.
- Ensure that you have an existing Cloud SQL instance and a database user. For more information, see Create instances and Create and manage users.
- Ensure that you have permissions to manage the IAM policies on your Cloud SQL instance. For more information, see Roles and permissions.
Required roles
To get the permissions that you need to enable automatic rotation, ask your administrator to grant you a role that contains the following permissions:
cloudsql.users.listcloudsql.users.update
You can get these permissions either with predefined roles or custom roles. To see which roles are associated with which permissions, refer to IAM roles for Cloud SQL.
For more information about granting roles, see Manage access to projects, folders, and organizations.
Create a Cloud SQL database credential secret
To enable automatic rotation, you must create a secret of the type Cloud SQL DB credentials.
Console
-
In the Google Cloud console, go to the Secret Manager page.
-
On the Secret Manager page, click the Regional secrets tab, and then click Create regional secret.
-
On the Create regional secret page, enter a name for the secret in the Name field.
-
Select the Set secret type checkbox and choose
Cloud SQL DB credentialsas the secret type. -
Choose the location where you want your regional secret to be stored from the Region list.
-
(Optional) In the Rotation section, configure the rotation schedule for your secret. If you don't configure a rotation schedule, you must rotate the secret manually.
Select the Set rotation period checkbox.
In the Rotation period list, select from the default options or select Custom to configure your own rotation schedule.
In the Starting on field, enter the rotation period start date and time.
-
Click Create secret.
Grant permissions to the built-in secret identity
Each secret has a unique identifier that distinguishes it from all other resources in your Google Cloud project. You must grant the built-in identity the required permissions that are needed to update credentials on your Cloud SQL instance. For more information, see Granting roles to resources with built-in identities.
Console
-
On the secret details page, go to the Overview tab.
-
Locate and copy the IAM principal identifier of the secret.
The identifier has the following format:
principal://secretmanager.googleapis.com/projects/PROJECT_NUMBER/uid/secrets/SECRET_UID. -
In the Google Cloud console, go to the IAM page.
-
Click Grant access.
The Grant access panel appears.
-
In the New principals field, paste the identifier copied in previously.
-
From the Select a role list, select a role that grants the necessary permissions.
For more information, see Required roles.
-
Click Save.
Rotate your secret
The rotation status of the newly created Cloud SQL secrets are Disabled until the first successful rotation. You must manually rotate your secret to verify permissions and start the automatic rotation schedule.
Console
-
In the Google Cloud console, go to the Secret Manager page.
-
On the Secret Manager page, click the Regional secrets tab.
-
Click the secret name to go to the secret details page.
-
Click Rotate.
The Rotate secret panel appears.
-
Specify the instance ID and the username of the Cloud SQL instance that you want to update.
-
(Optional) Expand the Additional settings section to enter a specific password. If left blank, Secret Manager automatically generates a strong, random password.
-
Click Rotate.
Secret Manager attempts to update the credentials in your Cloud SQL instance. If successful,
the Rotation status changes to Enabled, and the scheduled automatic rotation timer begins.
What's next
- Learn how to set up rotation schedules for secrets.