Skip to content

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

Merged
YashSaraf11 merged 6 commits into
GoogleCloudPlatform:mainfrom
suvidha-malaviya:cloudsql-managed-rotation
Nov 18, 2026
Merged

YashSaraf11 merged 6 commits into
GoogleCloudPlatform:mainfrom
suvidha-malaviya:cloudsql-managed-rotation

Conversation

@suvidha-malaviya

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

Copy link
Copy Markdown
Contributor

Description

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

  1. Create a regional secret with Cloud SQL DB credentials
  2. Enable managed rotation on a regional Cloud SQL DB credentials secret
  3. Trigger an on-demand rotation
  4. Reconfigure the recurring rotation schedule on a secret that already has managed rotation enabled

Also added two global scenario with secret-type:

  1. Create a secret restricted to a given secret type (global)
  2. Get a secret's type (global and regional)

Sample List (global & regional):

  • CreateSecretWithType.java (secret-type restriction is global-only — no regional counterpart)
  • GetSecretType.java / GetRegionalSecretType.java
  • CreateRegionalSecretWithCloudSqlCredentials.java
  • EnableRegionalSecretManagedRotation.java
  • RotateRegionalSecret.java
  • UpdateRegionalSecretWithManagedRotationSchedule.java

Added required tests for all of the above in SnippetsIT.java (regional and global).

Also bumps google-cloud-secretmanager/proto-google-cloud-secretmanager-v1 from 2.66.0 → 2.98.0 (and the google-cloud-bom import from 26.62.0 → 26.89.0) — minimum version with Cloud SQL managed-rotation support.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended.
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only

Compliance & Style

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones) — 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
    - 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

Post-Approval Actions

  • Please merge this PR for me once it is approved

@product-auto-label product-auto-label Bot added samples Issues that are directly related to samples. api: secretmanager Issues related to the Secret Manager API. labels Sep 25, 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 Java samples and integration tests for Google Cloud Secret Manager, specifically focusing on creating secrets with type restrictions and managing regional secrets with Cloud SQL managed rotation. The feedback suggests improving code maintainability by using standard protobuf utility classes (Timestamps and Durations) to build timestamp and duration objects, and enhancing test reliability by adding a backoff sleep when retrying on AbortedException during IAM policy updates.

suvidha-malaviya added a commit to suvidha-malaviya/java-docs-samples that referenced this pull request Sep 25, 2026
…latform#10348

- UpdateRegionalSecretWithManagedRotationSchedule.java: build the
  Timestamp/Duration via com.google.protobuf.util.Timestamps/Durations
  instead of manual builders.
- SnippetsIT.java: add backoff between AbortedException retries in
  grantCloudSqlRole and revokeCloudSqlRole to reduce contention.
- UpdateRegionalSecretWithManagedRotationSchedule.java: build the
  Timestamp/Duration via com.google.protobuf.util.Timestamps/Durations
  instead of manual builders.
- SnippetsIT.java: add backoff between AbortedException retries in
  grantCloudSqlRole and revokeCloudSqlRole to reduce contention.
@suvidha-malaviya
suvidha-malaviya force-pushed the cloudsql-managed-rotation branch from 22c4ce4 to 8370800 Compare September 25, 2026 12:09
@suvidha-malaviya
suvidha-malaviya marked this pull request as ready for review September 25, 2026 12:13
@snippet-bot

snippet-bot Bot commented Sep 25, 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

@suvidha-malaviya suvidha-malaviya changed the title Cloudsql managed rotation feat(secretmanager): Add Cloud SQL managed-rotation samples Sep 25, 2026
…ation samples

Align Javadoc with other samples, simplify comments, clarify rotation schedule behavior and mask placeholder project ids.

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

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

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

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

Copy link
Copy Markdown

Kokoro CI (Java 11 and Java 17) failed because CLOUD_SQL_INSTANCE and CLOUD_SQL_USER are not set in the Kokoro environment, causing SnippetsIT.beforeAll to abort the entire test suite (AssertionError: missing CLOUD_SQL_INSTANCE).

To match Go, Node.js, and PHP (which skip Cloud SQL managed-rotation tests when those env vars are absent), please update secretmanager/src/test/java/secretmanager/regionalsamples/SnippetsIT.java:

  1. In beforeAll(): remove Assert.assertFalse("missing CLOUD_SQL_INSTANCE", ...) and Assert.assertFalse("missing CLOUD_SQL_USER", ...), and guard the 3 createRegionalSecretWithCloudSqlCredentialsAndGrant(...) setup calls with if (!Strings.isNullOrEmpty(CLOUD_SQL_INSTANCE_ID) && !Strings.isNullOrEmpty(CLOUD_SQL_USERNAME)).
  2. In afterAll(): guard the revokeCloudSqlRole(...) and deleteRegionalSecret(...) calls for those 3 secrets with != null checks.
  3. In testEnableRegionalSecretManagedRotation, testRotateRegionalSecret, and testUpdateRegionalSecretWithManagedRotationSchedule: add JUnit Assume.assumeFalse(...) at the top of each test so JUnit skips them when CLOUD_SQL_INSTANCE or CLOUD_SQL_USER is missing.

@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
@YashSaraf11
YashSaraf11 merged commit cd5ce49 into GoogleCloudPlatform:main Nov 18, 2026
12 checks passed
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.

4 participants