-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(spanner): auth login support for Spanner Omni endpoints #18273
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
Open
sagnghos
wants to merge
11
commits into
googleapis:main
Choose a base branch
from
sagnghos:sagnghos/authLogin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c4d6def
feat(spanner): auth login support for Spanner Omni endpoints
sagnghos f468dfd
chore(spanner): revert run_in_transaction changes to match upstream
sagnghos 9477e40
fix(spanner): run synchronous credentials refresh in executor in asyn…
sagnghos 1340081
fix(spanner): synchronize token refresh with lock and optimize xor_bytes
sagnghos a554be1
fix(spanner): avoid bytearray memory copies and handle premature stre…
sagnghos c42ab4b
fix(spanner): support mTLS with default root certs and graceful fallback
sagnghos 73c846f
fix(spanner): require ca_certificate for TLS/mTLS in credentials refresh
sagnghos 6a338c0
fix(spanner): restrict random_oracle_sha256 domain size to prevent si…
sagnghos 251a2a7
fix(spanner): add cryptography to dependencies and test constraints
sagnghos 2658dbc
fix(spanner): bump cryptography lower bound to 44.0.0 for argon2 support
sagnghos 54ea4a3
fix(omni): adjust protobuf and grpc runtime version requirements for …
sagnghos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -820,6 +820,8 @@ def connect( | |
| instance_type=None, | ||
| data_boost_enabled=False, | ||
| auto_partition_mode=False, | ||
| username=None, | ||
| password=None, | ||
| **kwargs, | ||
| ): | ||
| """Creates a connection to a Google Cloud Spanner database. | ||
|
|
@@ -909,6 +911,10 @@ def connect( | |
| :param client_key: (Optional) The path to the client key file used for mTLS connection. | ||
| This is intended only for Spanner Omni endpoints. | ||
| This is mandatory if Spanner Omni requires an mTLS connection. | ||
| :type username: str | ||
| :param username: (Optional) Username for Spanner Omni authentication. | ||
| :type password: str | ||
| :param password: (Optional) Password for Spanner Omni authentication. | ||
| """ | ||
| if client is None: | ||
| client_info = ClientInfo( | ||
|
|
@@ -956,7 +962,29 @@ def connect( | |
| ) | ||
|
|
||
| project = "default" | ||
| credentials = AnonymousCredentials() | ||
| has_username = username is not None | ||
| has_password = password is not None | ||
| if has_username != has_password: | ||
| raise ValueError( | ||
| "Both username and password must be specified for Omni authentication" | ||
| ) | ||
| from google.cloud.spanner_v1.omni.credentials import ( | ||
| SpannerOmniCredentials, | ||
| ) | ||
|
|
||
| if has_username and has_password: | ||
| credentials = SpannerOmniCredentials( | ||
| username=username, | ||
| password=password, | ||
| target=host_endpoint, | ||
| use_plain_text=use_plain_text, | ||
| ca_certificate=ca_certificate, | ||
| client_certificate=client_certificate, | ||
| client_key=client_key, | ||
| ) | ||
| else: | ||
| credentials = AnonymousCredentials() | ||
|
|
||
| client_options = kwargs.get("client_options") | ||
| if client_options is None: | ||
| client_options = ClientOptions(api_endpoint=host_endpoint) | ||
|
|
@@ -969,6 +997,12 @@ def connect( | |
| client_options = copy.copy(client_options) | ||
| client_options.api_endpoint = host_endpoint | ||
|
|
||
| client_kwargs = {} | ||
| if username is not None: | ||
| client_kwargs["username"] = username | ||
| if password is not None: | ||
| client_kwargs["password"] = password | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The username and password should already be in |
||
|
|
||
| client = spanner.Client( | ||
| project=project, | ||
| credentials=credentials, | ||
|
|
@@ -980,6 +1014,7 @@ def connect( | |
| client_certificate=client_certificate, | ||
| client_key=client_key, | ||
| instance_type=instance_type, | ||
| **client_kwargs, | ||
| ) | ||
| else: | ||
| if project is not None and client.project != project: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/google-cloud-spanner/google/cloud/spanner_v1/omni/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| """Spanner Omni authentication and connection utilities.""" | ||
|
|
||
| from google.cloud.spanner_v1.omni.credentials import SpannerOmniCredentials | ||
| from google.cloud.spanner_v1.omni.login_client import LoginClient | ||
| from google.cloud.spanner_v1.omni.opaque import UserAuthenticator | ||
|
|
||
| __all__ = ( | ||
| "LoginClient", | ||
| "SpannerOmniCredentials", | ||
| "UserAuthenticator", | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.