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

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use cloud run and gitlab to build code and run container apps. GitLab tests your code and sends container images to Cloud Run. This setup lets developers ship new features fast. You do not need to manage servers by hand. GitLab handles the build pipeline from start to finish. Cloud Run runs the container and scales it up or down. When traffic drops to zero, the service scales down to save money. How cloud run and gitlab share identity and data Your build pipeline needs a safe way to 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.

Teams use cloud run and gitlab to build code and run container apps. GitLab tests your code and sends container images to Cloud Run.

This setup lets developers ship new features fast. You do not need to manage servers by hand. GitLab handles the build pipeline from start to finish. Cloud Run runs the container and scales it up or down. When traffic drops to zero, the service scales down to save money.

How cloud run and gitlab share identity and data

Your build pipeline needs a safe way to talk to Google Cloud. In the past, teams stored static service account keys in GitLab variables. Static keys are risky because they do not expire on their own. Anyone who steals a key can push bad code to your cloud.

Modern teams use identity federation to link both tools without saved keys. GitLab issues a short token for each pipeline job that runs. Google Cloud checks this token against a trust rule you set up. If the token matches your rule, the job gets a temporary cloud role. The job then pushes the container image to the Google registry. After that, the job tells Cloud Run to start the new revision. Once the job finishes, the temporary token stops working right away.

Common mistakes with roles and network paths

Many teams give the GitLab runner a very broad cloud role. An editor or owner role lets one pipeline change your whole cloud project. If a bad actor changes your build script, they can delete cloud data. You should fix this by creating a small, custom role for each project. Give the build role permission to push images and update one service only. Create a second service account for the running app itself. The running app should only read the specific data it needs to work.

GitLab CI Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Another big risk comes from shared runners and unlogged admin actions. When many projects share one runner, one job might read another job's files. You should isolate runners by team or by trust level. Teams also run into trouble when engineers fix broken services by hand. Developers often log in from their laptops to run database tasks or checks. Shared roles hide who ran a command during a live outage. If a query returns customer emails or card numbers, raw data sits on laptops. Masking rules can rewrite emails and phone numbers in query results. You should also keep Cloud Run services on private networks when possible. Use private network paths so internal apps do not sit on the public web.

Keeping build pipelines and live apps safe

Good security splits build tasks from live app tasks at every step. Your GitLab pipeline should only build code and update the container service. It should never run direct database changes using a shared admin account. Separate your test projects from your live cloud projects to stop cross-talk. Check your cloud audit logs often to see which jobs changed your services. Clear rules and tight roles keep both tools working the right way.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

How should GitLab log in to Google Cloud?

Use workload identity federation instead of saved service account keys. GitLab sends a short job token that Google Cloud checks and accepts. This removes the need to rotate or hide long-lived secret keys.

Should the build job and the app share one service account?

No, you should always use two separate service accounts for this. The GitLab job needs a role that can deploy new container images. The running Cloud Run app needs a role that only reads app data.

How can teams protect private Cloud Run apps during tests?

Set the service to require cloud login for every incoming web request. Your GitLab test job can send an identity token to run checks. Public users without a valid token will get blocked right away.

The query runs. The emails stay hidden.