You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary
A user attempted to configure secret-based environment variables for a Prefect 3 Cloud Run work pool. Using a Cloud Run Job v1 (apiVersion run.googleapis.com/v1, kind: Job), they set container env in job_body and tried to pass secret references via job_variables. However, the resulting Cloud Run Job only contained Prefect-injected envs (PREFECT_API_URL, PREFECT__FLOW_RUN_ID, etc.); all custom secret-based envs were ignored or stringified. Switching the work pool to Cloud Run v2 resolved the issue.
Key findings
Cloud Run v1 worker behavior:
The v1 worker overwrites containers[].env when building the Job request; hardcoding env in job_body is ignored.
The built-in variables define env as a dict[str, str]; Prefect coerces it to strings and does not pass through objects like valueFrom.secretKeyRef.
Attempting to set job_variables.env as a list results in Pydantic coercion errors (it expects a mapping), e.g., AttributeError: 'list' object has no attribute 'items'.
Outcome: Secret-based env cannot be reliably passed to the container via the v1 worker’s default schema. Prefect-injected envs still appear as expected.
Ensure the Cloud Run Job’s service account has Secret Manager Secret Accessor (roles/secretmanager.secretAccessor).
Prefect will still inject required envs (e.g., PREFECT_API_URL, PREFECT__FLOW_RUN_ID). Your container_env is merged alongside.
If you must remain on the v1 worker, options are limited: create a custom worker that merges a container_env array into containers[].env before submission, or fetch from Secret Manager at runtime in your code and export to os.environ.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
This discussion was created from a Slack thread conversation.
Original Thread: https://prefect-community.slack.com/archives/C04DZJC94DC/p1761065531562869
Summary
A user attempted to configure secret-based environment variables for a Prefect 3 Cloud Run work pool. Using a Cloud Run Job v1 (apiVersion run.googleapis.com/v1, kind: Job), they set container env in job_body and tried to pass secret references via job_variables. However, the resulting Cloud Run Job only contained Prefect-injected envs (PREFECT_API_URL, PREFECT__FLOW_RUN_ID, etc.); all custom secret-based envs were ignored or stringified. Switching the work pool to Cloud Run v2 resolved the issue.
Key findings
Cloud Run v1 worker behavior:
Cloud Run Job v1 vs v2 schema:
Successful approach: Cloud Run v2 worker
Actionable steps
Recommended variables schema patch excerpt
Notes
References
This discussion was automatically created by the Marvin bot to preserve valuable community insights.
Beta Was this translation helpful? Give feedback.
All reactions