The Simplest Way to Make Cloud Functions and GitLab CI Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use cloud functions and gitlab ci to build and ship serverless code on every commit. GitLab runners test your app code and push updates straight to your cloud project. This setup removes manual steps from your daily release work. Developers merge a branch, and the pipeline updates the live function within minutes. Still, linking a runner to a cloud account brings real security risks. If you store static keys in your project, anyone with repo access might misuse them. How cloud functions

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 functions and gitlab ci to build and ship serverless code on every commit. GitLab runners test your app code and push updates straight to your cloud project.

This setup removes manual steps from your daily release work. Developers merge a branch, and the pipeline updates the live function within minutes. Still, linking a runner to a cloud account brings real security risks. If you store static keys in your project, anyone with repo access might misuse them.

How cloud functions and gitlab ci handle keys and roles

A pipeline needs two distinct identities to do its job well. First, the deployment runner needs a role that can upload code and update function settings. Second, the function itself needs a separate runtime role to talk to databases or storage.

In a clean setup, GitLab uses workload identity federation to log in to the cloud. The runner swaps a short job token for a temporary cloud token at run time. This means you do not have to save static service account keys in your project.

Data flows in one clear direction during the release step. The runner packages the source code, sends it to cloud storage, and triggers the build. Once the build finishes, the cloud platform routes live traffic to the new function version.

Common failure modes and how to scope roles

The most common mistake is using one broad service account for all pipeline jobs. Teams often give this single account full admin rights across the whole cloud project. If a bad actor changes a build script, they can steal that broad permission.

Another failure mode happens when the deploy role and the runtime role are the same. Your function only needs to read or write specific data during its normal run. It should never have the power to deploy new code or change network rules.

GitLab CI Security + Cloud Functions IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Unlogged database queries and hidden debug runs also hurt security during pipeline tests. When a runner runs integration tests against live data, standard build logs miss the details. You can see that a job ran, but you cannot see which rows it read. If test results contain emails or card numbers, masking rewrites matched fields in results.

To fix these issues, create one deploy role per project and scope it tightly. Allow the runner to update only the specific functions owned by that single repo. Next, lock down the network path between your GitLab runners and your private cloud resources. Use private runners inside your own network when jobs must test internal endpoints.

Auditing pipeline runs and runtime actions

Good security requires clear logs for both the deploy step and the live function. Cloud audit logs show when a runner creates or updates a function in production. You should check these logs often to spot odd deploy times or failed role checks.

You also need a clear plan for emergency fixes when a pipeline breaks. Sometimes an engineer must check a live function or query a backend database by hand. If they share the runner's cloud role for manual fixes, your audit trail breaks. Give human users their own scoped roles so every action links to a real person.

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

Should I store cloud service account keys in GitLab variables?

No, static keys are hard to rotate and easy to leak in build logs. Use workload identity federation so runners get short-lived tokens for each job.

Should the GitLab runner and the function share the same role?

No, keep the deploy role and the runtime role separate at all times. The runner needs rights to update code, while the function only needs app data rights.

How do I protect sensitive data during pipeline test runs?

Use separate test databases with fake data whenever you run automated pipeline checks. If you must touch real systems, use data masking to rewrite emails and phone numbers.

The query runs. The emails stay hidden.