Skip to content

feat(secretmanager): Add Cloud SQL managed-rotation samples - #14562

Draft
suvidha-malaviya wants to merge 3 commits into
GoogleCloudPlatform:mainfrom
suvidha-malaviya:cloudsql-managed-rotation
Draft

feat(secretmanager): Add Cloud SQL managed-rotation samples#14562
suvidha-malaviya wants to merge 3 commits into
GoogleCloudPlatform:mainfrom
suvidha-malaviya:cloudsql-managed-rotation

Conversation

@suvidha-malaviya

@suvidha-malaviya suvidha-malaviya commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Added samples for Secret Manager's Cloud SQL managed-rotation feature (regional secrets only — this feature isn't available for global secrets)

  • create_regional_secret_with_cloud_sql_credentials
  • enable_regional_secret_managed_rotation
  • rotate_regional_secret

Added a test case for creating the Cloud SQL DB credentials secret type.

Note: requires google-cloud-secret-manager>=2.30.0, which itself requires Python>=3.10 — this feature does not exist in 2.29.0 or earlier.

##Checklist

  • I have followed Sample Guidelines from AUTHORING_GUIDE.MD
  • README is updated to include all relevant information
  • Tests pass: nox -s py-3.9 (see Test Environment Setup)
  • Lint pass: nox -s lint (see Test Environment Setup)
  • These samples need a new API enabled in testing projects to pass (Cloud SQL Admin API — sqladmin.googleapis.com)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
    - CLOUD_SQL_INSTANCE / CLOUD_SQL_USER — a pre-provisioned, long-lived Cloud SQL instance + DB user for managed-rotation tests to point at (same pattern as this repo's other Cloud SQL-backed sample tests)
    - The identity running these tests additionally needs resourcemanager.projects.getIamPolicy/setIamPolicy on the test project (e.g. roles/resourcemanager.projectIamAdmin)
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@product-auto-label product-auto-label Bot added api: secretmanager Issues related to the Secret Manager API. samples Issues that are directly related to samples. labels Sep 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces new regional samples and corresponding tests for Google Cloud Secret Manager, specifically covering creating secrets with Cloud SQL credentials, enabling managed rotation, and triggering rotation. Additionally, the google-cloud-secret-manager dependency is updated to version 2.30.0 in requirements.txt. However, there are critical runtime issues in both enable_regional_secret_managed_rotation.py and rotate_regional_secret.py where the API request payloads incorrectly use the key parent instead of name for the secret's resource name, which will result in a ValueError at runtime.

Comment on lines +60 to +73
# Build the resource name of the secret.
parent = f"projects/{project_id}/locations/{location_id}/secrets/{secret_id}"

# Enable managed rotation. Leaving password unset lets Secret Manager
# generate a secure password itself.
response = client.enable_managed_rotation(
request={
"parent": parent,
"cloud_sql_single_user_credentials": {
"instance_id": instance_id,
"username": username,
},
}
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In EnableManagedRotationRequest, the field to specify the secret's resource name is name, not parent. Using parent as the key in the request dictionary will cause a ValueError at runtime because the field does not exist on the request message.

Please update the request dictionary key to name (and consider renaming the local variable parent to name for clarity).

Suggested change
# Build the resource name of the secret.
parent = f"projects/{project_id}/locations/{location_id}/secrets/{secret_id}"
# Enable managed rotation. Leaving password unset lets Secret Manager
# generate a secure password itself.
response = client.enable_managed_rotation(
request={
"parent": parent,
"cloud_sql_single_user_credentials": {
"instance_id": instance_id,
"username": username,
},
}
)
# Build the resource name of the secret.
name = f"projects/{project_id}/locations/{location_id}/secrets/{secret_id}"
# Enable managed rotation. Leaving password unset lets Secret Manager
# generate a secure password itself.
response = client.enable_managed_rotation(
request={
"name": name,
"cloud_sql_single_user_credentials": {
"instance_id": instance_id,
"username": username,
},
}
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against the installed SDK — both enable_managed_rotation and rotate_secret only define a parent field (no name), so parent is correct here.

Comment on lines +48 to +52
# Build the resource name of the secret.
parent = f"projects/{project_id}/locations/{location_id}/secrets/{secret_id}"

# Rotate the secret.
response = client.rotate_secret(request={"parent": parent})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In RotateSecretRequest, the field to specify the secret's resource name is name, not parent. Using parent as the key in the request dictionary will cause a ValueError at runtime because the field does not exist on the request message.

Please update the request dictionary key to name (and consider renaming the local variable parent to name for clarity).

Suggested change
# Build the resource name of the secret.
parent = f"projects/{project_id}/locations/{location_id}/secrets/{secret_id}"
# Rotate the secret.
response = client.rotate_secret(request={"parent": parent})
# Build the resource name of the secret.
name = f"projects/{project_id}/locations/{location_id}/secrets/{secret_id}"
# Rotate the secret.
response = client.rotate_secret(request={"name": name})

@suvidha-malaviya
suvidha-malaviya marked this pull request as ready for review September 1, 2026 07:03
@suvidha-malaviya
suvidha-malaviya requested review from a team as code owners September 1, 2026 07:03
@snippet-bot

snippet-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 3 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: secretmanager Issues related to the Secret Manager API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant