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

Allow workers to pass an API key to flow runs that is different from their own #10717

Closed
3 tasks done
EmilRex opened this issue Sep 13, 2023 · 6 comments · Fixed by PrefectHQ/prefect-kubernetes#94
Closed
3 tasks done
Assignees
Labels
enhancement An improvement of an existing feature

Comments

@EmilRex
Copy link
Contributor

EmilRex commented Sep 13, 2023

First check

  • I added a descriptive title to this issue.
  • I used the GitHub search to find a similar request and didn't find it.
  • I searched the Prefect documentation for this feature.

Prefect Version

2.x

Describe the current behavior

When creating a new flow run, workers inject their own api key into the flow run's environment. This means that the flow run always has the same permissions as the worker.

Describe the proposed behavior

In cases where workers and flow runs should have different permissions, it would be great if you could specify an api key for the flow run to use that is different from the worker api key.

Example Use

No response

Additional context

I'm not sure how this would be implemented, but one consideration is how environment variables are handled - especially PREFECT_ environment variables. If there was greater control over how environment variables are populated in infrastructures, this feature would likely be easier to support.

@EmilRex EmilRex added enhancement An improvement of an existing feature needs:triage labels Sep 13, 2023
@desertaxle
Copy link
Member

Thanks for the issue @EmilRex! This is possible by setting PREFECT_API_KEY in the env attribute on the base job template for our supported work pools. I believe users can use a secret block to prevent this API key from being stored in plaintext, but I will need to confirm that.

@EmilRex
Copy link
Contributor Author

EmilRex commented Sep 14, 2023

That would work great if that's possible! I know we are doing some manipulation of env and wasn't 100% sure if we overwrite PREFECT_API_KEY or if a user supplied value would take precedence.

@prefectcboyd
Copy link
Contributor

prefectcboyd commented Sep 14, 2023

Discussing with the team and a few customers to get more details, I think this is a pretty strong / urgent requirement for them to be capable of delivering / executing this work in production, and would be a very hard stop / do not pass go situation if it was not available.

Ideally, I think what should be possible is the ability to specify / pass a reference to a secretKeyRef in the base job template that doesn't get overwritten. Currently, any environment variables that are set through env get replaced with the ones that the worker wants to set by default (so like the API_URL and API_KEY).

If there was an option / toggle on the prefect worker side to say "inherit the worker key" or alternatively "reference this k8s secret api key", I think that might be a solution?

cc @taylor-curran

@prefectcboyd
Copy link
Contributor

prefectcboyd commented Sep 14, 2023

@EmilRex , @desertaxle - Just to confirm and verify - I tested adding an environment reference in the job template.
My current k8s worker is setup to reference the API key through a secret.
I have passed this reference as an environment variable in the job template using secretKeyRef, but it becomes overwritten and in plain text, with no reference to the secret.
Image below for reference -

image

@meggers
Copy link

meggers commented Sep 14, 2023

Chiming in from the customer side, we have a critical need to not use plain text secrets (#10716) and so if we were able to say "If there was an option / toggle on the prefect worker side to say "inherit the worker key" or alternatively "reference this k8s secret api key"" instead of including the plain text worker api key, that would be a big win.

Ideally I'd like to use a k8s secret, similar to what I am doing with the worker secret, rather than a secret block.

@desertaxle
Copy link
Member

@prefectcboyd I have a fix for the issue you're seeing in PrefectHQ/prefect-kubernetes#94. I believe merging and releasing that PR will allow us to resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature
Projects
None yet
7 participants