Skip to content

feat: ability to update credentials on long running client#4371

Draft
ldetmer wants to merge 9 commits intomainfrom
mutable-credentials
Draft

feat: ability to update credentials on long running client#4371
ldetmer wants to merge 9 commits intomainfrom
mutable-credentials

Conversation

@ldetmer
Copy link
Contributor

@ldetmer ldetmer commented Mar 2, 2026

This feature introduces the ability to change Service Account credentials on a long running client without having to restart the client.

Usage:

  1. Create a MutableCredentials instance wrapping initial Service Account Credentials.
  2. Create a client with MutableCredentials created in step 1
  3. Whenever necessary call MutableCredentials.updateCredentials with updated credentials. The next API call on the client will utilize the new credentials.

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: spanner Issues related to the googleapis/java-spanner API. labels Mar 2, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Spanner client library by providing a mechanism to update authentication credentials dynamically within a running application. This is particularly beneficial for long-lived services that need to refresh or change their service account credentials without incurring downtime or complex client re-initialization logic, thereby improving security posture and operational flexibility.

Highlights

  • Dynamic Credential Updates: Introduced a new MutableCredentials class that allows for the dynamic updating or rotation of ServiceAccountCredentials for long-running Spanner client instances without requiring client re-initialization.
  • Credential Delegation: The MutableCredentials class acts as a wrapper, delegating all authentication-related operations (like getAuthenticationType, getRequestMetadata, and refresh) to an internal, scoped ServiceAccountCredentials instance.
  • Comprehensive Testing: Added both unit tests (MutableCredentialsTest) and integration tests (ITMutableCredentialsTest) to thoroughly validate the functionality and behavior of the new mutable credentials, including scenarios for successful authentication and subsequent failure after updating to invalid credentials.
Changelog
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/MutableCredentials.java
    • Added a new class MutableCredentials to enable dynamic updates of ServiceAccountCredentials for Spanner clients.
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ITMutableCredentialsTest.java
    • Added an integration test to verify the MutableCredentials functionality in a real Spanner client environment, demonstrating credential updates and their impact on authorization.
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/MutableCredentialsTest.java
    • Added a unit test for MutableCredentials to ensure proper delegation and updating of underlying ServiceAccountCredentials using mock objects.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 a "MutableCredentials" class to enable dynamic updating of service account credentials for long-running Spanner clients, facilitating credential rotation without client re-initialization. However, the current implementation has thread-safety issues and exposes mutable internal state, which could lead to security vulnerabilities in a multi-threaded environment. Specifically, the lack of "volatile" on the "delegate" field and the exposure of the mutable "scopes" list need to be addressed. While the overall structure is good and includes tests, these security concerns are critical.

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

Labels

api: spanner Issues related to the googleapis/java-spanner API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants