Skip to content

OAuth cache improvements - #435

Merged
hashhar merged 3 commits into
trinodb:masterfrom
hovaesco:hovaesco/oauth-cache
Feb 16, 2024
Merged

hashhar merged 3 commits into
trinodb:masterfrom
hovaesco:hovaesco/oauth-cache

Conversation

@hovaesco

Copy link
Copy Markdown
Member

Description

Closes #430 and #431

Non-technical explanation

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot Bot added the cla-signed label Dec 29, 2023
@hovaesco
hovaesco requested review from hashhar and mdesmet December 29, 2023 10:47
@hovaesco
hovaesco force-pushed the hovaesco/oauth-cache branch from 5632003 to 292bd0f Compare December 29, 2023 11:07
Comment thread trino/auth.py Outdated

@staticmethod
def _construct_cache_key(host: Optional[str], user: Optional[str]) -> str:
return f"{host}@{user}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

usually people expect stuff to be user@host but it doesn't matter here since it's an internal cache key (unless we log it somewhere)

@hashhar hashhar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

first commit is unclear to me, can you explain a bit about it?

2nd looks good.

@hovaesco

Copy link
Copy Markdown
Member Author

If there is no backend available then keyring backend is being initialized as backends.fail.Keyring so first commit adds a check which validates and treats it as no keyring avaiable and fall backs to _OAuth2TokenInMemoryCache() 0517c65#diff-6db3a24c52bc43426976f516411e7de756f5ee0f8f3904ca036da682aeaa840cL278

Comment thread trino/auth.py

@staticmethod
def _determine_user(headers: Mapping[Any, Any]) -> Optional[Any]:
return headers.get(HEADER_USER)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

X-Trino-User header is optional

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right, is there any other way to get username?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since the actual user might come from user mapping then getting it from the server is probably the only option.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe we can use the client provided principal/user instead of user which it gets resolved to on the server to bypass this problem entirely?

@hovaesco hovaesco self-assigned this Jan 3, 2024
@hovaesco
hovaesco force-pushed the hovaesco/oauth-cache branch from 292bd0f to 8c4c75f Compare February 2, 2024 13:43

@hashhar hashhar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please update docs to add warning what happens when you don't specify user when connecting (token cache gets shared)

Comment thread trino/auth.py

def get_token_from_cache(self, host: Optional[str]) -> Optional[str]:
return self._cache.get(host)
def get_token_from_cache(self, key: Optional[str]) -> Optional[str]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if you extract the host -> key rename to it's own commit functional changes will be more visible and easier to see.

Comment thread trino/auth.py Outdated
@hovaesco
hovaesco force-pushed the hovaesco/oauth-cache branch from 8c4c75f to 9064581 Compare February 2, 2024 16:26
@hovaesco
hovaesco requested a review from hashhar February 2, 2024 16:26

@hashhar hashhar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@lukasz-walkiewicz do you want to take a look?

We now do like JDBC driver, if username was specified we use host+user cache key otherwise we use only host as the cache key and tokens get shared (same as JDBC driver).

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

Development

Successfully merging this pull request may close these issues.

Support for oauth2 token per user per host (vs per host only)

3 participants