Skip to content

feat: default authentication support for external hosts #3655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

feat: default authentication support for external hosts #3655

wants to merge 6 commits into from

Conversation

sagnghos
Copy link
Contributor

@sagnghos sagnghos commented Feb 22, 2025

Default authentication support for external hosts by using auth token path mentioned in env variable

@sagnghos sagnghos requested review from a team as code owners February 22, 2025 18:53
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: spanner Issues related to the googleapis/java-spanner API. labels Feb 22, 2025
@@ -967,6 +990,7 @@ public static class Builder
private boolean enableBuiltInMetrics = SpannerOptions.environment.isEnableBuiltInMetrics();
private String monitoringHost = SpannerOptions.environment.getMonitoringHost();
private SslContext mTLSContext = null;
private boolean isExternalHost = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this a method instead of a field. This now gives the impression of being in sync with the current settings, but it isn't if you do weird stuff (like first setting an emulator host and then overriding that by setting a host). By implementing it as a method, you can just calculate it based on the values at that time, instead of trying to set the correct value when setHost / setEmulatorHost is being set.

Copy link
Contributor Author

@sagnghos sagnghos Feb 25, 2025

Choose a reason for hiding this comment

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

removed the need to check emulatorHost. But had to keep isExternalHost calculation in setHost. Can't convert it to a method to do a on demand calculation since host is a private member in the parent builder class
#3656

@@ -799,6 +810,18 @@ protected SpannerOptions(Builder builder) {
enableBuiltInMetrics = builder.enableBuiltInMetrics;
enableEndToEndTracing = builder.enableEndToEndTracing;
monitoringHost = builder.monitoringHost;
String externalHostTokenPath = System.getenv("SPANNER_EXTERNAL_HOST_AUTH_TOKEN");
if (builder.isExternalHost && builder.emulatorHost == null && externalHostTokenPath != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Prefer !Strings.isNullOrEmpty(externalHostTokenPath) over a null check.
  2. This check should also include && builder.credentials == null to prevent the default credentials to override specific credentials that have been set for this builder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done
#3656

@@ -407,6 +407,9 @@ Spanner createSpanner(SpannerPoolKey key, ConnectionOptions options) {
if (options.getConfigurator() != null) {
options.getConfigurator().configure(builder);
}
if (options.usesEmulator()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed
#3656

} catch (IOException e) {
throw SpannerExceptionFactory.newSpannerException(e);
}
credentials = new GoogleCredentials(new AccessToken(token, null));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This constructor is deprecated. Use the static create method instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done
#3656

@sagnghos
Copy link
Contributor Author

Closing this PR as its not able to upload the latest commit and stuck in this state for 10hrs

Screenshot 2025-02-25 at 8 32 15 AM

@sagnghos sagnghos closed this Feb 25, 2025
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: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants