-
Notifications
You must be signed in to change notification settings - Fork 7
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(auth): support basic auth #60
base: main
Are you sure you want to change the base?
Conversation
In PrefectHQ/prefect#16408, Prefect server added support for basic auth. This adds support for setting PREFECT_API_AUTH_STRING. The exporter will base64 encode this value and apply the value as a Basic auth header. Closes #59 Closes https://linear.app/prefect/issue/PLA-931/prometheus-prefect-exporter-doesnt-support-basic-authentication-when
if api_auth_string: | ||
api_auth_string_encoded = base64.b64encode(api_auth_string.encode("utf-8")).decode("utf-8") | ||
headers["Authorization"] = f"Basic {api_auth_string_encoded}" |
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 matches the encoding approach upstream: https://github.com/PrefectHQ/prefect/pull/16408/files#diff-a52d8326344d84ccd617e704df9a030fd4a813a8d705510f778538423e7cf21dR307-R310
@@ -92,6 +92,7 @@ You can now reach each service locally: | |||
You can modify environment variables to change the behavior of the exporter. | |||
- An API Key is only required for auth-enabled, on-prem, self-managed solutions. | |||
- An API key is not required for open-source or Prefect Server. | |||
- If an API key and API auth string are provided, then the API key takes precedence. |
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 was reading up on this and if there was some scenario that would require both to be passed, you can supposedly supply one "Authorization" header key with a comma-separated list of values and that should work.
If this doesn't merge before I'm out next week, Platform/anyone can feel free to take this over - otherwise I'll pick it up again when I'm back on Jan 28. |
Summary
In PrefectHQ/prefect#16408, Prefect server added support for basic auth.
This adds support for setting PREFECT_API_AUTH_STRING. The exporter will base64 encode this value and apply the value as a Basic auth header.
Closes #59
Closes https://linear.app/prefect/issue/PLA-931/prometheus-prefect-exporter-doesnt-support-basic-authentication-when
Testing
Supply the authorization setting to the server and the client (exporter in this case):
Then run
docker compose up -d
. This should build the exporter image, but if you need to refresh that image, rundocker compose build
.Check the logs with
docker compose logs -f
. You should see successful requests to the endpoints:And if you run some test flows, you should see metrics update at
http://localhost:8000
.If you want to confirm auth is active, you can go to
http://localhost:4200
and you should see an authorization window asking for the password before you can reach the UI.