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 <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
@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.

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 <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
@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 <[email protected]>
wild-endeavor
wild-endeavor previously approved these changes Feb 23, 2023
Signed-off-by: Ketan Umare <[email protected]>
@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 <[email protected]>
wild-endeavor
wild-endeavor previously approved these changes Feb 23, 2023
Signed-off-by: Ketan Umare <[email protected]>
kumare3 and others added 2 commits February 23, 2023 11:38
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
@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 <[email protected]>

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

Signed-off-by: Ketan Umare <[email protected]>

* Delete legacy files

Signed-off-by: Ketan Umare <[email protected]>

* add missing None

Signed-off-by: Ketan Umare <[email protected]>

* keyring removed

Signed-off-by: Ketan Umare <[email protected]>

* added insecure_skip_verify

Signed-off-by: Ketan Umare <[email protected]>

* test fixed

Signed-off-by: Ketan Umare <[email protected]>

* Test fixed

Signed-off-by: Ketan Umare <[email protected]>

* Auth update

Signed-off-by: Ketan Umare <[email protected]>

* updated test

Signed-off-by: Ketan Umare <[email protected]>

* updated

Signed-off-by: Ketan Umare <[email protected]>

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

Signed-off-by: Yee Hing Tong <[email protected]>

* updated ca-cert logic

Signed-off-by: Ketan Umare <[email protected]>

* Fixed unit tests

Signed-off-by: Ketan Umare <[email protected]>

* updated

Signed-off-by: Ketan Umare <[email protected]>

* test fix

Signed-off-by: Ketan Umare <[email protected]>

* updated

Signed-off-by: Ketan Umare <[email protected]>

* nest raise if exc

Signed-off-by: Yee Hing Tong <[email protected]>

* added keyring.alt for tests

Signed-off-by: Ketan Umare <[email protected]>

* updated

Signed-off-by: Ketan Umare <[email protected]>

* updated

Signed-off-by: Ketan Umare <[email protected]>

* Lint

Signed-off-by: Eduardo Apolinario <[email protected]>

---------

Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Yee Hing Tong <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Ketan Umare <[email protected]>
Co-authored-by: Ketan Umare <[email protected]>
Co-authored-by: Ketan Umare <[email protected]>
Co-authored-by: Yee Hing Tong <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
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 <[email protected]>

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

Signed-off-by: Ketan Umare <[email protected]>

* Delete legacy files

Signed-off-by: Ketan Umare <[email protected]>

* add missing None

Signed-off-by: Ketan Umare <[email protected]>

* keyring removed

Signed-off-by: Ketan Umare <[email protected]>

* added insecure_skip_verify

Signed-off-by: Ketan Umare <[email protected]>

* test fixed

Signed-off-by: Ketan Umare <[email protected]>

* Test fixed

Signed-off-by: Ketan Umare <[email protected]>

* Auth update

Signed-off-by: Ketan Umare <[email protected]>

* updated test

Signed-off-by: Ketan Umare <[email protected]>

* updated

Signed-off-by: Ketan Umare <[email protected]>

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

Signed-off-by: Yee Hing Tong <[email protected]>

* updated ca-cert logic

Signed-off-by: Ketan Umare <[email protected]>

* Fixed unit tests

Signed-off-by: Ketan Umare <[email protected]>

* updated

Signed-off-by: Ketan Umare <[email protected]>

* test fix

Signed-off-by: Ketan Umare <[email protected]>

* updated

Signed-off-by: Ketan Umare <[email protected]>

* nest raise if exc

Signed-off-by: Yee Hing Tong <[email protected]>

* added keyring.alt for tests

Signed-off-by: Ketan Umare <[email protected]>

* updated

Signed-off-by: Ketan Umare <[email protected]>

* updated

Signed-off-by: Ketan Umare <[email protected]>

* Lint

Signed-off-by: Eduardo Apolinario <[email protected]>

---------

Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Yee Hing Tong <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Ketan Umare <[email protected]>
Co-authored-by: Ketan Umare <[email protected]>
Co-authored-by: Ketan Umare <[email protected]>
Co-authored-by: Yee Hing Tong <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>

* Remove requirements files (#1511)

* Remove mentions to spark

Signed-off-by: Eduardo Apolinario <[email protected]>

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

Signed-off-by: Eduardo Apolinario <[email protected]>

* Remove plugins requirements.

Signed-off-by: Eduardo Apolinario <[email protected]>

* Remove all_requirements target from plugins makefile

Signed-off-by: Eduardo Apolinario <[email protected]>

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

Signed-off-by: Eduardo Apolinario <[email protected]>

* Revert "Remove all_requirements target from plugins makefile"

This reverts commit 50cbb4d.

Signed-off-by: Eduardo Apolinario <[email protected]>

* Revert "Remove plugins requirements."

This reverts commit eae945c.

Signed-off-by: Eduardo Apolinario <[email protected]>

---------

Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>

* Remove requirements files (#1511)

* Remove mentions to spark

Signed-off-by: Eduardo Apolinario <[email protected]>

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

Signed-off-by: Eduardo Apolinario <[email protected]>

* Remove plugins requirements.

Signed-off-by: Eduardo Apolinario <[email protected]>

* Remove all_requirements target from plugins makefile

Signed-off-by: Eduardo Apolinario <[email protected]>

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

Signed-off-by: Eduardo Apolinario <[email protected]>

* Revert "Remove all_requirements target from plugins makefile"

This reverts commit 50cbb4d.

Signed-off-by: Eduardo Apolinario <[email protected]>

* Revert "Remove plugins requirements."

This reverts commit eae945c.

Signed-off-by: Eduardo Apolinario <[email protected]>

---------

Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>

---------

Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Yee Hing Tong <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Ketan Umare <[email protected]>
Co-authored-by: Ketan Umare <[email protected]>
Co-authored-by: Ketan Umare <[email protected]>
Co-authored-by: Ketan Umare <[email protected]>
Co-authored-by: Yee Hing Tong <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
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