Skip to content
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

Flytekit Auth system overhaul and pretty printing upgrade #1458

Merged
merged 25 commits into from
Feb 23, 2023

Conversation

kumare3
Copy link
Contributor

@kumare3 kumare3 commented Feb 8, 2023

TL;DR

This PR introduces a new Oauth2 handling system in flytekit, that can be used in non flytekit python libraries that wish to use a standardized flow for flytekit. The standard flow is as defined in the RFC and a few additional supported methods.

The system uses client side - grpc.Interceptors. for fine control on the auth flow. It also introduces exception wrapping and retrying interceptor.

As a last time, it improves the terminal output when using pyflyte. All the output is not distilled and the error is traced correctly. Eventually we could link to docs for the errors.

Type

  • Bug Fix
  • Feature
  • Plugin

Are all requirements met?

  • Code completed
  • Smoke tested
  • Unit tests added
  • Code documentation added
  • Any pending items have an associated Issue

 - Reuse local keyring better
 - use grpc based auth system

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
retrying

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
@kumare3
Copy link
Contributor Author

kumare3 commented Feb 8, 2023

Help wanted.
cc @bethebunny / @kazesberger / @ByronHsu / @flixr / @honnix if some of you can test.
Especially @honnix you have a command based auth system

EngHabu
EngHabu previously approved these changes Feb 8, 2023
Copy link
Collaborator

@EngHabu EngHabu left a comment

Choose a reason for hiding this comment

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

Thank you!

</head>
<body>
<h1>Log in successful to {self.server.remote_metadata.endpoint}</h1>
</body></html>""",
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: add please close this window or something like that..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do, i will make it a configurable thing, also add Flyte icon

self._creds = Credentials(output.stdout.strip())


class ClientCredentialsAuthenticator(Authenticator):
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should also add Device flow at some point...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wdym?

@staticmethod
def _raise_if_exc(request: typing.Any, e: Union[grpc.Call, grpc.Future]):
if e.code() == grpc.StatusCode.UNAUTHENTICATED:
raise FlyteAuthenticationException() from e
Copy link
Collaborator

Choose a reason for hiding this comment

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

Am I missing something, where is this handled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is only an exception beautifier. This is not handled anywhere, this is once all auth tries fail

click.secho(f"Underlying Exception: {e.__cause__}", dim=True)
return

if isinstance(e, grpc._channel._InactiveRpcError): # noqa
Copy link
Member

Choose a reason for hiding this comment

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

grpc._channel needs to be imported.

self._cmd = command
if not self._cmd:
raise ValueError("Command cannot be empty for command authenticator")
super().__init__(header_key)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
super().__init__(header_key)
super().__init__(None, header_key)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you for the catch, updating it

@honnix
Copy link
Member

honnix commented Feb 8, 2023

I did a quick test. I managed to run a task via FlyteRemote and I verified that auth token was created and propagated correctly.

Ketan Umare added 2 commits February 12, 2023 22:10
Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.home>
server_process.terminate()

def refresh_access_token(self, credentials: Credentials) -> Credentials:
if credentials.refresh_token is None:
raise ValueError("no refresh token available with which to refresh authorization credentials")

resp = _requests.post(
url=self._token_endpoint,

Choose a reason for hiding this comment

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

We should consider passing verify switch to request calls as in: #1509

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me incorporate your change

Ketan Umare and others added 10 commits February 13, 2023 22:00
Signed-off-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
…e the image smaller

Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
@kumare3 kumare3 changed the title [WIP] Flytekit Auth system overhaul and pretty printing upgrade Flytekit Auth system overhaul and pretty printing upgrade Feb 22, 2023
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
wild-endeavor
wild-endeavor previously approved these changes Feb 23, 2023
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
@eapolinario
Copy link
Collaborator

eapolinario commented Feb 23, 2023

I was able to repro the test errors in a docker container (e.g. docker run --rm -it -v $(pwd):/root python:3.10-buster "bash" and cd /root && make setup && make unit_test).

Installing keyrings.alt makes the tests pass. That said, I'm not sure yet why we should require that package.

Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
wild-endeavor
wild-endeavor previously approved these changes Feb 23, 2023
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
kumare3 and others added 2 commits February 23, 2023 11:38
Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Feb 23, 2023

Codecov Report

Merging #1458 (9d9feaa) into master (b3ad158) will decrease coverage by 0.05%.
The diff coverage is 53.21%.

@@            Coverage Diff             @@
##           master    #1458      +/-   ##
==========================================
- Coverage   69.32%   69.28%   -0.05%     
==========================================
  Files         305      315      +10     
  Lines       28671    28845     +174     
  Branches     2718     2741      +23     
==========================================
+ Hits        19877    19986     +109     
- Misses       8276     8341      +65     
  Partials      518      518              
Impacted Files Coverage Δ
flytekit/clients/auth/exceptions.py 0.00% <0.00%> (ø)
flytekit/configuration/internal.py 16.21% <0.00%> (-0.23%) ⬇️
flytekit/exceptions/user.py 15.55% <0.00%> (-2.40%) ⬇️
flytekit/remote/remote.py 41.68% <0.00%> (+0.28%) ⬆️
tests/flytekit/unit/cli/pyflyte/test_run.py 99.31% <ø> (ø)
...t/clients/grpc_utils/wrap_exception_interceptor.py 2.70% <2.70%> (ø)
flytekit/clients/grpc_utils/auth_interceptor.py 2.77% <2.77%> (ø)
flytekit/clients/auth/auth_client.py 22.15% <14.28%> (ø)
flytekit/clients/raw.py 7.62% <33.33%> (-18.22%) ⬇️
flytekit/configuration/__init__.py 36.60% <33.33%> (-0.04%) ⬇️
... and 14 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@eapolinario eapolinario merged commit d682410 into master Feb 23, 2023
eapolinario added a commit that referenced this pull request Feb 28, 2023
* [wip] New authentication system

 - Reuse local keyring better
 - use grpc based auth system

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* Better error handling and printing, better exception handling and
retrying

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* Delete legacy files

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* add missing None

Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.home>

* keyring removed

Signed-off-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>

* added insecure_skip_verify

Signed-off-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>

* test fixed

Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>

* Test fixed

Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>

* Auth update

Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>

* updated test

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* updated

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* flush buffer instead of closing, was getting a weird stack trace. make the image smaller

Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>

* updated ca-cert logic

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* Fixed unit tests

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* updated

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* test fix

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* updated

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* nest raise if exc

Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>

* added keyring.alt for tests

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* updated

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* updated

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* Lint

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

---------

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.home>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>
Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Co-authored-by: Ketan Umare <ketanumare@Ketans-MBP.home>
Co-authored-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>
Co-authored-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>
Co-authored-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
Co-authored-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
eapolinario added a commit that referenced this pull request Feb 28, 2023
…pgrade (#1458) (#1525)

* Flytekit Auth system overhaul and pretty printing upgrade (#1458)

* [wip] New authentication system

 - Reuse local keyring better
 - use grpc based auth system

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* Better error handling and printing, better exception handling and
retrying

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* Delete legacy files

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* add missing None

Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.home>

* keyring removed

Signed-off-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>

* added insecure_skip_verify

Signed-off-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>

* test fixed

Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>

* Test fixed

Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>

* Auth update

Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>

* updated test

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* updated

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* flush buffer instead of closing, was getting a weird stack trace. make the image smaller

Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>

* updated ca-cert logic

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* Fixed unit tests

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* updated

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* test fix

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* updated

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* nest raise if exc

Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>

* added keyring.alt for tests

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* updated

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* updated

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>

* Lint

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

---------

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.home>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>
Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Co-authored-by: Ketan Umare <ketanumare@Ketans-MBP.home>
Co-authored-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>
Co-authored-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>
Co-authored-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
Co-authored-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Remove requirements files (#1511)

* Remove mentions to spark

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Remove mentions to requirements.txt and dev-requirements.txt

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Remove plugins requirements.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Remove all_requirements target from plugins makefile

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Use dev-requirements.in in lint gh action job

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Revert "Remove all_requirements target from plugins makefile"

This reverts commit 50cbb4d.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Revert "Remove plugins requirements."

This reverts commit eae945c.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

---------

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Co-authored-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Remove requirements files (#1511)

* Remove mentions to spark

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Remove mentions to requirements.txt and dev-requirements.txt

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Remove plugins requirements.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Remove all_requirements target from plugins makefile

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Use dev-requirements.in in lint gh action job

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Revert "Remove all_requirements target from plugins makefile"

This reverts commit 50cbb4d.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Revert "Remove plugins requirements."

This reverts commit eae945c.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

---------

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Co-authored-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

---------

Signed-off-by: Ketan Umare <ketan.umare@gmail.com>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.home>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>
Signed-off-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>
Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Co-authored-by: Ketan Umare <16888709+kumare3@users.noreply.github.com>
Co-authored-by: Ketan Umare <ketanumare@Ketans-MBP.home>
Co-authored-by: Ketan Umare <ketanumare@Ketans-MacBook-Pro.local>
Co-authored-by: Ketan Umare <ketanumare@Ketans-MBP.UNION.AI>
Co-authored-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
Co-authored-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants