<@ULVA73B9P> I enabled basic auth on the server. I...
# ask-marvin
c
@Marvin I enabled basic auth on the server. I configured this through prefect.yaml.
Copy code
[server.api]
auth_string="foo:bar"
How can I configure the worker with the same basic auth? I prefer to specify via a file over environment variables.
m
thought for 388.2 seconds
n
short answer:
prefect.toml
wherever you do
prefect worker start
otherwise people commonly like to use
prefect config set PREFECT_{something}={value}
to set settings for a whole profile (applied whenever using the CLI/SDK and that profile is active)
m
You’ll want to set the client-side auth string the worker uses to talk to the API. In Prefect 3.x, that’s the
PREFECT_API_AUTH_STRING
setting (format:
user:pass
). You can do this purely via files in two common ways: Option A — Profiles (global, file-backed) - This writes to
~/.prefect/profiles.toml
(no env vars needed):
Copy code
prefect profile create local-auth
prefect --profile local-auth config set PREFECT_API_URL="<http://127.0.0.1:4200/api>" PREFECT_API_AUTH_STRING="foo:bar"
prefect profile use local-auth
prefect worker start -p <your-pool>
- Or edit the file directly:
Copy code
# ~/.prefect/profiles.toml
[profiles]
active = "local-auth"

[profiles.local-auth]
PREFECT_API_URL = "<http://127.0.0.1:4200/api>"
PREFECT_API_AUTH_STRING = "foo:bar"
Then start your worker with that profile active:
Copy code
prefect --profile local-auth worker start -p <your-pool>
Option B — Project-level TOML file - In a
prefect.toml
at your project root:
Copy code
[prefect.api]
url = "<http://127.0.0.1:4200/api>"
auth_string = "foo:bar"
- Or in `pyproject.toml`:
Copy code
[tool.prefect.api]
url = "<http://127.0.0.1:4200/api>"
auth_string = "foo:bar"
Start the worker from that directory (or ensure the file is present in the worker’s filesystem). Notes: - If both
PREFECT_API_KEY
and
PREFECT_API_AUTH_STRING
are set, the API key takes precedence. - For containerized workers, bake
~/.prefect/profiles.toml
into the image or mount it, or include a `prefect.toml`/`pyproject.toml` in the working directory. Docs for reference: - Security settings (basic auth) - Settings and profiles
upvote 1