The Simplest Way to Make Cloud Run and Cloud Storage Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

You pair cloud run and cloud storage to give stateless containers a durable place for files. Cloud Run handles compute tasks, while Cloud Storage holds uploads, exports, and logs across restarts. Cloud Run containers start up fast and shut down when traffic stops. Any file you write to local container memory disappears when the instance stops. By sending files to a storage bucket, your app keeps state safe across every run. This setup supports image uploads, report generation, and batch data ta

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.

You pair cloud run and cloud storage to give stateless containers a durable place for files. Cloud Run handles compute tasks, while Cloud Storage holds uploads, exports, and logs across restarts.

Cloud Run containers start up fast and shut down when traffic stops. Any file you write to local container memory disappears when the instance stops. By sending files to a storage bucket, your app keeps state safe across every run. This setup supports image uploads, report generation, and batch data tasks.

How cloud run and cloud storage share roles and data

Every Cloud Run service runs as a specific Google Cloud service account. This identity controls what the container can read or write in your cloud project. You grant this service account a storage role on the target bucket. When the app runs, the client library fetches a short-lived token from the metadata server. You do not need to save static key files inside your container image.

Data flows between the two tools in two main ways. First, your app code can call the storage API directly to read or write objects. Second, you can mount a bucket as a local folder using the built-in file system driver. Direct API calls work best for high traffic and fine control over retries. Volume mounts help when older apps expect standard local file paths.

You can also trigger a container run when a new file lands in a bucket. Event routing watches the bucket for object creation or deletion events. When a user uploads a file, the event system sends a request to your container. Your app processes the file, writes the output back, and scales down to zero.

Common failure modes and how to scope roles

The most common mistake is using the default compute service account for your container. That default identity often holds broad editor rights across your entire cloud project. If an attacker compromises one web app, they can read every bucket you own. Always create a dedicated service account for each individual Cloud Run service.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Another frequent issue is granting storage permissions at the project level instead of the bucket level. Project-wide storage roles let a single app read sensitive backups and finance buckets. You should bind roles directly to the single bucket that the app needs. Split read and write duties into separate roles whenever your workflow allows it.

Large file transfers can also crash containers if you buffer whole objects in memory. In-memory file writes count against the total RAM limit of your container instance. Always stream large uploads and downloads directly between the client and the storage bucket. For direct user uploads, generate signed URLs so files bypass the container completely.

Unlogged bucket reads make security reviews hard when teams debug data leaks. By default, Google Cloud logs admin changes to buckets, not individual object reads or writes. Turn on data read and write audit logs for buckets that hold sensitive customer files. Keep your container and bucket in the same region to avoid cross-region network fees. Also check that private Google access is active on your subnet so traffic stays internal.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Should I use the storage client library or a volume mount in Cloud Run?

Use the client library for most apps because it handles retries and streaming well. Use a volume mount only when an existing app requires standard local file paths.

How do I let users upload large files without hitting request limits?

Have your Cloud Run app generate a signed URL for the target storage bucket. The user uploads the file straight to Cloud Storage without passing through your container.

Why does my container fail to read a bucket even with the right role?

Check that your service uses the custom service account instead of the default one. Also verify that bucket policies or vpc rules do not block the service identity.

The query runs. The emails stay hidden.