-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: Unwrap SecretStr tokens when building Trino auth objects #6771
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
AdityaPatil22
wants to merge
2
commits into
feast-dev:master
Choose a base branch
from
AdityaPatil22:fix/trino-offline-store-failures
base: master
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
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
65 changes: 65 additions & 0 deletions
65
sdk/python/tests/unit/infra/offline_stores/contrib/trino_offline_store/test_trino_auth.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,65 @@ | ||
| from pydantic import SecretStr | ||
| from trino.auth import BasicAuthentication, JWTAuthentication, OAuth2Authentication | ||
|
|
||
| from feast.infra.offline_stores.contrib.trino_offline_store.trino import ( | ||
| CLASSES_BY_AUTH_TYPE, | ||
| AuthConfig, | ||
| FeastConfigBaseModel, | ||
| ) | ||
|
|
||
|
|
||
| def test_jwt_auth_produces_plain_str_token(): | ||
| auth = AuthConfig(type="jwt", config={"token": "my-secret-token"}) | ||
|
|
||
| trino_auth = auth.to_trino_auth() | ||
|
|
||
| assert isinstance(trino_auth, JWTAuthentication) | ||
| assert trino_auth.token == "my-secret-token" | ||
| assert isinstance(trino_auth.token, str) | ||
|
|
||
|
|
||
| def test_oauth2_auth_unchanged(): | ||
| auth = AuthConfig(type="oauth2", config=None) | ||
|
|
||
| trino_auth = auth.to_trino_auth() | ||
|
|
||
| assert isinstance(trino_auth, OAuth2Authentication) | ||
|
|
||
|
|
||
| def test_basic_auth_with_plain_fields_unaffected(): | ||
| auth = AuthConfig(type="basic", config={"username": "alice", "password": "hunter2"}) | ||
|
|
||
| trino_auth = auth.to_trino_auth() | ||
|
|
||
| assert isinstance(trino_auth, BasicAuthentication) | ||
| assert trino_auth._username == "alice" | ||
| assert trino_auth._password == "hunter2" | ||
|
|
||
|
|
||
| class _MixedAuthModel(FeastConfigBaseModel): | ||
| username: str | ||
| token: SecretStr | ||
|
|
||
|
|
||
| class _MixedAuth: | ||
| def __init__(self, username: str, token: str): | ||
| self.username = username | ||
| self.token = token | ||
|
|
||
|
|
||
| def test_to_trino_auth_unwraps_only_secret_fields_in_mixed_model(monkeypatch): | ||
| monkeypatch.setitem( | ||
| CLASSES_BY_AUTH_TYPE, | ||
| "jwt", | ||
| {"auth_model": _MixedAuthModel, "trino_auth": _MixedAuth}, | ||
| ) | ||
| auth = AuthConfig( | ||
| type="jwt", config={"username": "alice", "token": "my-secret-token"} | ||
| ) | ||
|
|
||
| trino_auth = auth.to_trino_auth() | ||
|
|
||
| assert trino_auth.username == "alice" | ||
| assert trino_auth.token == "my-secret-token" | ||
| assert isinstance(trino_auth.username, str) | ||
| assert isinstance(trino_auth.token, str) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker: While this test ensures OAuth2 auth still works, it could be enhanced to test a config with actual OAuth2 parameters to ensure non-SecretStr fields are handled correctly in the new code path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion - OAuth2 doesn't actually have any config parameters in CLASSES_BY_AUTH_TYPE (its auth_model is None, and to_trino_auth() short-circuits to trino_auth_cls() with no fields at all), so there's no non-SecretStr field handling to exercise on that path. The new test_to_trino_auth_unwraps_only_secret_fields_in_mixed_model and test_basic_auth_with_plain_fields_unaffected tests cover the non-SecretStr field handling instead.