Marius Haberstock
11/26/2025, 8:09 PM- name: docker_deployment
entrypoint: repo/flows/flow.py:flow
work_pool:
name: docker
job_variables:
image: '{{ build_image.image }}'
env:
PASSWORD: "{{ prefect.blocks.secret.password }}"
But then the password is shwon as plain text in the Prefect UI, in the Configuration tab of the deployment. How can I pass the secret as env to the docker deployment without it being shown anywhere?Marvin
11/26/2025, 8:09 PMMarvin
11/26/2025, 8:18 PMwork_pool.job_variables.env. In Prefect 3.x those values are resolved and stored on the deployment, so the UI will show them. Instead, load the secret at runtime inside your flow and, if you truly need an environment variable, set it in-process.
Why you’re seeing plaintext
- {{ prefect.blocks.secret.password }} in job_variables.env is resolved during prefect deploy and the resulting value is stored on the deployment. The Configuration tab then displays that stored value.
Recommended pattern (keeps secrets out of the UI)
- Load the secret inside your flow/task from a Secret block and either:
- Pass it directly to the client/library you’re using; or
- Set it as an environment variable only within the running process.
Example
python
from prefect import flow, task
from prefect.blocks.system import Secret
import os
import subprocess
@task
def do_something_needing_pwd():
password = Secret.load("password").get()
# Option A: pass directly to a library/client
# client.connect(password=password)
# Option B: set env just-in-time for a subprocess
env = {**os.environ, "PASSWORD": password}
subprocess.run(["your_cmd"], env=env, check=True)
@flow
def my_flow():
do_something_needing_pwd()
if __name__ == "__main__":
my_flow()
This keeps the secret:
- Encrypted at rest in the Secret block
- Out of deployment configuration and the UI
- Only present in-memory on the worker at run time
If you absolutely need an env var before any library code runs
- Put the logic that loads the Secret block at the start of your flow (as above) and set os.environ["PASSWORD"] before initializing your client.
- Alternatively, mount a file (via job_variables.volumes) that contains the secret and read it in your code; the file path will be visible in the UI, but not the secret contents.
- Avoid trying to inherit arbitrary host env into the container—Docker workers don’t automatically pass through host env (only Prefect settings like PREFECT_API_URL).
Cleanup/rotation
- Since the secret was stored in the deployment config, rotate that password/credential, remove the env entry from your deployment spec, and re-deploy.
If you share any constraints (e.g., a third-party tool must read PASSWORD from env before your Python code runs), I can suggest a concrete wrapper pattern for your image or flow to meet that requirement without exposing the value.