-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Update Cloud Client for new USER-scoped API tokens #1410
Conversation
Note for review: many of the files are affected by the name changes ( |
@@ -59,4 +58,7 @@ def login(token): | |||
click.secho("Error attempting to communicate with Prefect Cloud", fg="red") | |||
return | |||
|
|||
# save token | |||
client.save_api_token() | |||
|
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.
Will this now work or will users still need to select a tenant? Should we make a CLI command to switch tenants?
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.
This will work fine with current API tokens that don't require selecting a tenant; it writes the token to disk (and recovers it) without regard for what token it is.
We should 100% make a CLI interface for this, but I wanted to get the machinery in first.
src/prefect/config.toml
Outdated
|
||
[cloud] | ||
# the Prefect Server address | ||
api = "https://api.prefect.io" | ||
graphql = "${cloud.api}/graphql/alpha" | ||
api = "https://api.prefect.io/graphql/alpha" |
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.
In a lot of places deployment related this is provided only as https://api.prefect.io
because it was placed into graphql with {}/graphql/alpha
so you should also update the defaults in all the agent code.
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.
I would say the fallback should actually remain api.prefect.io
so that it isn't versioned, and the config should include the versioned API (which it now does). That way the agent code doesn't need updating in most scenarios, and does have a sane fallback (since the Agent will always be hitting the most current API -- the main reason for changing the config is so that users could store a separate API token for each endpoint during testing)
I think I got all of the places where graphql/alpha
was being added manually, the only place I still see it in the codebase is config.toml
Co-Authored-By: Josh Meek <40716964+joshmeek@users.noreply.github.com>
…to client-auth
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.
Overall this looks solid, two comments and I'm going to do another pass
- name: PREFECT__CLOUD__AUTH_TOKEN | ||
value: PREFECT__CLOUD__AUTH_TOKEN | ||
- name: PREFECT__CLOUD__API_TOKEN | ||
value: PREFECT__CLOUD__API_TOKEN |
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.
For the record, this is a large breaking change - this means that once this agent is deployed, it can only deploy flows built off of the most recent version of Core.
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.
This includes the local agent.
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.
Oh yeah this hadn’t occurred to me. Should we make it so that it places both API_TOKEN and AUTH_TOKEN in the images to maintain current compatibility?
Co-Authored-By: Chris White <chris@prefect.io>
api = "https://api.prefect.io" | ||
graphql = "${cloud.api}/graphql/alpha" | ||
# the Prefect Cloud API | ||
graphql = "https://api.prefect.io/graphql/alpha" |
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.
Why was api
removed?
Closing for #1423 which does not have any breaking changes |
Doc: fix account name in cloud screenshot
Thanks for contributing to Prefect!
Please describe your work and make sure your PR:
CHANGELOG.md
(if appropriate)docs/outline.toml
for API reference docs (if appropriate)Note that your PR will not be reviewed unless all three boxes are checked.
What does this PR change?
This PR adds a new auth flow to the Python Cloud client, without changing its existing behavior. However, it does rename some private attributes.
The primary contribution of this PR is to support
USER
-scoped Cloud API tokens, which function as personal access tokens.USER
-scoped tokens can not be used to interact with the Cloud API in a significant way, but are able to authenticate with the API and receive short-lived JWTs in return. These JWTs are full auth tokens representing a user's membership in a specific Cloud tenant.The user flow works like this:
USER
-scoped API tokenclient.save_api_token()
to write the token to local storage so it persists across Python sessions.client.get_available_tenants()
to see what tenants they can login toclient.log_to_tenant(tenant_id=<>, tenant_slug=<>)
(with one or the other argument). When this happens, an ephemeral JWT is received as well as a refresh token. Note this step is also persisted across sessions.client.graphql(...)
. The Client is managing all refreshing and exchanging of JWTs in the background.client.logout_from_tenant()
. This discards the JWT access token.The
TOKEN
- andAGENT
- scoped flows are unchanged: