-
Notifications
You must be signed in to change notification settings - Fork 297
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
Feat: Add plugin for generating GCP IAP ID tokens via external command #1795
Merged
fg91
merged 6 commits into
fg91/feat/proxy-authentication
from
fabio/feat/gcp-iap-token-external-command-plugin
Aug 24, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a5d2487
Add external command plugin to generate id tokens for identity aware …
9b40845
Retrieve desktop app client secret from gcp secret manager
ea9b60a
Remove comments
eb9c466
Introduce a command group that allows adding a command to generate se…
c8060d3
Document how to use plugin and deploy Flyte with IAP
69fe91c
Minor corrections README.md
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 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 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 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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from dataclasses import dataclass | ||
|
||
import keyring as _keyring | ||
from keyring.errors import NoKeyringError | ||
from keyring.errors import NoKeyringError, PasswordDeleteError | ||
|
||
|
||
@dataclass | ||
|
@@ -16,6 +16,7 @@ class Credentials(object): | |
refresh_token: str = "na" | ||
for_endpoint: str = "flyte-default" | ||
expires_in: typing.Optional[int] = None | ||
id_token: typing.Optional[str] = None | ||
|
||
|
||
class KeyringStore: | ||
|
@@ -25,20 +26,28 @@ class KeyringStore: | |
|
||
_access_token_key = "access_token" | ||
_refresh_token_key = "refresh_token" | ||
_id_token_key = "id_token" | ||
|
||
@staticmethod | ||
def store(credentials: Credentials) -> Credentials: | ||
try: | ||
_keyring.set_password( | ||
credentials.for_endpoint, | ||
KeyringStore._refresh_token_key, | ||
credentials.refresh_token, | ||
) | ||
if credentials.refresh_token: | ||
_keyring.set_password( | ||
credentials.for_endpoint, | ||
KeyringStore._refresh_token_key, | ||
credentials.refresh_token, | ||
) | ||
_keyring.set_password( | ||
credentials.for_endpoint, | ||
KeyringStore._access_token_key, | ||
credentials.access_token, | ||
) | ||
if credentials.id_token: | ||
_keyring.set_password( | ||
credentials.for_endpoint, | ||
KeyringStore._id_token_key, | ||
credentials.id_token, | ||
) | ||
except NoKeyringError as e: | ||
logging.debug(f"KeyRing not available, tokens will not be cached. Error: {e}") | ||
return credentials | ||
|
@@ -48,18 +57,23 @@ def retrieve(for_endpoint: str) -> typing.Optional[Credentials]: | |
try: | ||
refresh_token = _keyring.get_password(for_endpoint, KeyringStore._refresh_token_key) | ||
access_token = _keyring.get_password(for_endpoint, KeyringStore._access_token_key) | ||
id_token = _keyring.get_password(for_endpoint, KeyringStore._id_token_key) | ||
except NoKeyringError as e: | ||
logging.debug(f"KeyRing not available, tokens will not be cached. Error: {e}") | ||
return None | ||
|
||
if not access_token: | ||
return None | ||
return Credentials(access_token, refresh_token, for_endpoint) | ||
return Credentials(access_token, refresh_token, for_endpoint, id_token=id_token) | ||
|
||
@staticmethod | ||
def delete(for_endpoint: str): | ||
try: | ||
_keyring.delete_password(for_endpoint, KeyringStore._access_token_key) | ||
_keyring.delete_password(for_endpoint, KeyringStore._refresh_token_key) | ||
try: | ||
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 ID token is optional. Deletion fails if non existing. |
||
_keyring.delete_password(for_endpoint, KeyringStore._id_token_key) | ||
except PasswordDeleteError as e: | ||
logging.debug(f"Id token not found in key store, not deleting. Error: {e}") | ||
except NoKeyringError as e: | ||
logging.debug(f"KeyRing not available, tokens will not be cached. Error: {e}") |
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.
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.
When requesting to refresh an id token from GCP, the response contains the new id token but no refresh token. We would, thus, delete the refresh token here.