Skip to content

feat(secretmanager): add Cloud SQL managed rotation and secret type samples - #3347

Open
suvidha-malaviya wants to merge 5 commits into
GoogleCloudPlatform:mainfrom
suvidha-malaviya:cloudsql-managed-rotation
Open

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

Conversation

@suvidha-malaviya

@suvidha-malaviya suvidha-malaviya commented Sep 30, 2026 •

Copy link
Copy Markdown

Adds C# samples and integration tests for Secret Manager Cloud SQL managed rotation and secret types.

Regional samples

  • CreateRegionalSecretWithCloudSqlCredentials: creates a secret of type CLOUD_SQL_DB_CREDENTIALS.
  • EnableRegionalSecretManagedRotation: links the secret to a Cloud SQL instance and user, and creates version 1.
  • RotateRegionalSecret: triggers a rotation on demand.
  • UpdateRegionalSecretWithManagedRotationSchedule: sets the recurring schedule. The update mask names rotation.next_rotation_time and rotation.rotation_period rather than the whole rotation message.
  • GetRegionalSecretType

Global samples

  • CreateSecretWithType: takes the secret type as a parameter.
  • GetSecretType

Other changes

  • Bumps Google.Cloud.SecretManager.V1 from 2.6.0 to 2.8.0, the first version with managed rotation support.
  • RegionalSecretManagerFixture now grants and revokes roles/cloudsql.admin for each test secret's own identity, because the grant is per-secret.

…amples

Add C# samples and tests for creating a Cloud SQL credentials secret, enabling, rotating and scheduling managed rotation, and creating/getting secrets by secret type. Bump Google.Cloud.SecretManager.V1 to 2.8.0.
@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 30, 2026

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

Copy link
Copy Markdown

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 C# sample codes and integration tests for Google Cloud Secret Manager, specifically covering regional secrets, secret types, and managed rotation for Cloud SQL database credentials. The review feedback highlights several critical issues in the test suite and test fixture where created secrets and IAM role bindings could be leaked in the GCP project if assertions fail or exceptions are thrown during setup. It is highly recommended to wrap these operations in try-finally or try-catch blocks to guarantee robust resource cleanup.

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

snippet-bot Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 7 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

…ation samples

Align comments with other samples, simplify summaries and clarify rotation schedule behavior.

@YashSaraf11 YashSaraf11 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.

Reviewed the Cloud SQL Managed Rotation and Secret Type .NET samples. Left inline comments categorized into [Must], [Warning], and [Nit].

YashSaraf11
YashSaraf11 previously approved these changes Nov 18, 2026

@YashSaraf11 YashSaraf11 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.

LGTM! All review comments have been addressed.

@YashSaraf11 YashSaraf11 added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 18, 2026
@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. labels Nov 18, 2026
@YashSaraf11

Copy link
Copy Markdown
Contributor

Kokoro CI (Linux 3 and Windows 3) failed on the 3 Cloud SQL managed-rotation tests (System.Exception : missing CLOUD_SQL_INSTANCE) because CLOUD_SQL_INSTANCE and CLOUD_SQL_USER are not set in the Kokoro environment.

To match Go, Node.js, and PHP (which skip Cloud SQL managed-rotation tests when those env vars are absent):

  1. In secretmanager/api/SecretManager.Samples.Tests/RegionalSecretManagerFixture.cs: change CloudSqlInstanceId and CloudSqlUsername from RequiredEnvironmentVariable(...) to Environment.GetEnvironmentVariable(...) so they return null instead of throwing.
  2. In EnableRegionalSecretManagedRotationTests.cs, RotateRegionalSecretTests.cs, and UpdateRegionalSecretWithManagedRotationScheduleTests.cs: return early (or use Skip.If) at the top of each [Fact] method when string.IsNullOrEmpty(_fixture.CloudSqlInstanceId) || string.IsNullOrEmpty(_fixture.CloudSqlUsername).

(Note: The 2 TagKeys quota failures on projects/1061780273775 are pre-existing/unrelated to this PR.)

@YashSaraf11 YashSaraf11 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.

LGTM! Thanks for adding the CI skip guards.

@YashSaraf11 YashSaraf11 added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 18, 2026
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 18, 2026
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.

5 participants