The Simplest Way to Make Cloud Run and Prefect Work Like They Should
Running Cloud Run and Prefect together lets teams schedule and run data tasks inside containers. Prefect plans the work and Cloud Run spins up the compute for each job. This setup keeps costs low because you only pay when a task runs. Teams do not need to manage idle servers between scheduled jobs. Each flow gets a fresh container that shuts down when the work finishes. How Cloud Run and Prefect share roles and data Prefect holds the schedule and logic for your data pipelines. A worker proce
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Running Cloud Run and Prefect together lets teams schedule and run data tasks inside containers. Prefect plans the work and Cloud Run spins up the compute for each job.
This setup keeps costs low because you only pay when a task runs. Teams do not need to manage idle servers between scheduled jobs. Each flow gets a fresh container that shuts down when the work finishes.
How Cloud Run and Prefect share roles and data
Prefect holds the schedule and logic for your data pipelines. A worker process polls the Prefect server for scheduled flow runs. When a job is ready, the worker asks Google Cloud to start a container.
The worker uses a Google Cloud service account to make this request. That service account needs permission to create jobs and read container images. Once the container starts, it pulls the flow code from your storage bucket.
Inside the container, the job uses its own runtime service account. This second role gives the task permission to read or write cloud databases. When the code finishes, the container sends status logs back to the Prefect server.
Separating the worker role from the job role keeps your setup clean. The worker only triggers compute, while the task only touches the data it needs. Teams can track which flow ran and when it finished.
Common failures with shared accounts and broad keys
Many teams use one service account for both the worker and every job. That single account soon gains read and write permissions across the whole cloud project. If one task leaks a key, an attacker can reach every database.
Long-lived API keys stored inside container images cause another big problem. Developers often bake Prefect keys or database passwords right into the build. Anyone who pulls that image from the registry can read those static secrets.
End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Network timeouts also break flows when containers cannot reach private databases. Teams sometimes open public database ports to fix a failed run fast. This quick fix exposes sensitive tables to the wider network.
Unlogged database queries create blind spots during an audit. Prefect logs show that a Python task ran, but not the exact SQL query. Security teams cannot see who changed a row or read customer emails.
How to scope roles and network paths
Give each flow its own runtime service account in Google Cloud. Grant that role permission to reach only the buckets and tables for that job. Never share the worker service account with the task containers.
Keep secrets out of your container images and source code. Pull database keys and API tokens from a secret manager when the job starts. Rotate those keys often so an old token cannot cause harm.
Route container traffic through a private virtual network to reach internal databases. Use firewall rules to block public traffic and limit which ports a job can use. Set short time limits on jobs so hung tasks do not run forever.
Test your permission rules in a staging project before going live. Check your cloud logs after each test run to spot denied requests early. Small, clear roles make it easy to see what each pipeline does.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.
First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
Should I use Cloud Run services or jobs for Prefect flows?
Use jobs for Prefect flows that run to completion and then stop. Services work better for workers that listen for incoming requests all day. Jobs do not need to listen on a web port and handle batch work well.
How do I stop tasks from sharing database credentials?
Assign a distinct runtime service account to each work pool or deployment. Map each service account to specific secret manager entries for that single pipeline. This prevents a marketing job from reading finance tables.
Why do my container tasks fail before Prefect shows any logs?
The container often fails to start because the worker lacks image pull permissions. Check the Google Cloud logs first to see if the image download failed. Also verify that the runtime role can read your secret entries at startup.
Related guides
In this post