GitLab Google Cloud Platform Infrastructure Orchestration

The integration of GitLab CI/CD with Google Cloud Platform (GCP) represents a shift toward highly automated, secure, and scalable application delivery pipelines. By leveraging the synergy between GitLab's source code management and CI/CD capabilities and Google's diverse suite of compute and serverless offerings, organizations can achieve a seamless transition from code commit to production deployment. This integration encompasses a wide spectrum of deployment targets, ranging from traditional virtual machines and managed Kubernetes clusters to event-driven serverless functions and hybrid cloud environments via Anthos. The primary objective of this ecosystem is to reduce the friction associated with infrastructure provisioning and application deployment while maintaining a rigorous security posture through modern authentication frameworks.

Google Cloud Compute and Deployment Targets

GitLab provides a versatile range of integration points with GCP, allowing teams to select the compute abstraction that best fits their architectural requirements. This flexibility ensures that both legacy monolithic applications and modern microservices can be managed through a single CI/CD interface.

Google Compute Engine (GCE)

Google Compute Engine delivers configurable, high-performance virtual machines running within Google’s global data centers. In the context of GitLab CI/CD, GCE serves as a primary deployment target for application delivery.

The impact for the user is the ability to migrate traditional, non-containerized workloads to the cloud without needing to rewrite the application for a containerized environment. This allows for a phased migration strategy where "lift-and-shift" operations can be automated via GitLab pipelines.

From a contextual perspective, GCE deployments can be initiated by installing GitLab on a single GCE instance for smaller projects or utilizing a High Availability (HA) architecture for enterprise-grade stability and redundancy. For users who prefer a self-hosted approach, GitLab Runners can be configured on a GCP VM using a shell (bash) executor, allowing the runner to execute scripts directly on the virtual machine to deploy code from GitLab to the target environment.

Google Kubernetes Engine (GKE) and Anthos

For containerized workloads, GitLab offers deep integration with Google Kubernetes Engine (GKE). Teams can provision new GKE clusters or import existing ones through the GitLab interface with minimal manual overhead.

The use of GitLab’s Auto DevOps functionality further lowers the barrier to entry, automating the build, test, and deployment phases for containerized applications. This is particularly impactful for teams moving toward a microservices architecture, as it removes the complexity of manual manifest management.

Beyond standard GKE, GitLab supports Anthos, a modern application platform designed for consistency across on-premise and cloud environments. This includes support for:

  • GKE On Premise (GKE-OP)
  • CloudRun for Anthos
  • Anthos Configuration Management

The integration with Anthos allows enterprises to achieve scalability across heterogeneous environments, ensuring that the operational experience remains identical whether the workload is running in a Google data center or a local data center.

Serverless Architectures: Cloud Run and Cloud Functions

GitLab CI/CD extends its reach into serverless compute, removing the need for users to manage the underlying server infrastructure.

Google Cloud Functions (GCF) provides an event-driven serverless compute platform. Developers can store their code in GitLab SCM and deploy directly to GCF. This is highly effective for automating development for Firebase and creating a cloud-native, event-driven architecture.

Cloud Run offers a fully managed serverless platform that scales stateless containers automatically. GitLab Serverless provides a comprehensive CI/CD workflow to build and test these applications. This integration simplifies management across various infrastructures, including Knative and Cloud Run for Anthos, all manageable through a single unified UI.

Workload Identity Federation and Keyless Authentication

The evolution of security in CI/CD has moved away from static secrets toward short-lived, federated identities. Workload Identity Federation (WIF) is the cornerstone of this modern approach, allowing GitLab pipelines to authenticate to GCP without the use of long-lived service account keys.

The Mechanics of OIDC Authentication

Workload Identity Federation utilizes OpenID Connect (OIDC) tokens. Instead of storing a .json key file within GitLab CI/CD variables—which creates a security risk if the key is leaked—GitLab generates a short-lived OIDC token. Google Cloud verifies this token, and if trusted, grants the pipeline access to the requested resources.

The real-world consequence of this setup is a significantly reduced attack surface. Since no static credentials are stored or passed around, there is no "secret" to be stolen from the GitLab environment. The authentication flow is short-lived, scoped, and fully automated.

Configuring the Workload Identity Pool

To establish this federation, specific configuration steps must be followed within the GCP Console and GitLab.

The address of the GitLab instance must be manually set in the allowed audiences list. This address must use the https:// protocol. For example, the audience might be https://gitlab.com or https://gitlab.example.com. It is critical that the address does not end in a trailing slash.

Provider attributes mapping is required to link GitLab claims to Google tokens. The following mappings are essential:

Attribute (on Google) Assertion (from GitLab)
google.subject assertion.sub
attribute.X assertion.X

If permissions need to be granted based on a user's email, the mapping must include attribute.user_email mapped to assertion.user_email. For projects hosted on GitLab.com, GCP requires that access be limited specifically to tokens issued by the organization's GitLab group to prevent unauthorized tenants from accessing the project.

Authorization and Service Account Impersonation

Authentication (proving who you are) is distinct from authorization (what you are allowed to do). Once the workload identity pool and provider are defined, the GitLab CI/CD job can authenticate, but it possesses no permissions by default.

To grant permissions, a Google Cloud Service Account must be created. The federated identity from GitLab is then bound to this service account using IAM roles. This allows the GitLab pipeline to "impersonate" the service account to perform actions.

IAM Best Practices and the Principle of Least Privilege

Scaling federated identity requires a disciplined approach to IAM (Identity and Access Management) to avoid "permission creep."

The principle of least privilege dictates that federated service accounts should not be treated as root users. Instead, they should be bound only to the roles absolutely necessary for the specific task.

  • For deploying Cloud Run services: Use roles/run.admin.
  • For pulling artifacts from the registry: Use roles/artifactregistry.reader.

Every federated identity should be paired with a minimal service account that performs exactly one function. This ensures that if a token is leaked or misused, the blast radius is confined to a single function rather than the entire GCP project.

Furthermore, it is critical to isolate Workload Identity Pools per environment. Organizations should avoid placing development, staging, and production environments under the same identity pool to prevent cross-environment contamination and accidental deployments to production from a development branch.

Implementation Comparison: WIF vs. Service Account Keys

The choice between Workload Identity Federation and traditional service account keys depends on the nature of the workload.

Feature Workload Identity Federation (WIF) Service Account Keys (.json)
Secret Storage Keyless (Short-lived tokens) Static keys stored in GitLab Variables
Security Risk Low (Token expires quickly) High (Key is long-lived)
Setup Complexity Moderate (Requires OIDC config) Low (Upload JSON file)
Ideal Use Case Stateless CI/CD pipelines Legacy systems, local development
Auditability High (OIDC claims) Moderate (Key usage logs)

While WIF is superior for short-lived, stateless jobs in CI pipelines, traditional service accounts or secret managers may still be appropriate for long-running services or local development environments where an OIDC provider is not available.

Technical Execution and Tooling

In a modern GitLab-to-GCP pipeline, the interaction is fully automated. For example, when using Terraform for infrastructure as code, the process flows as follows:

  1. GitLab generates an OIDC token.
  2. GCP verifies the token via the Workload Identity Pool.
  3. GCP issues a temporary access token.
  4. Terraform uses this federated token to provision resources.

This flow ensures that no static credentials ever touch the runner's file system or the GitLab database.

Conclusion

The integration of GitLab CI/CD with Google Cloud Platform transforms the deployment process from a manual, risk-prone activity into a secure, automated pipeline. By utilizing Google Compute Engine for legacy workloads, GKE and Anthos for containerized orchestration, and Cloud Run and Cloud Functions for serverless agility, organizations can tailor their infrastructure to their specific needs. The transition to Workload Identity Federation marks a critical security milestone, replacing dangerous static keys with a dynamic, OIDC-based trust relationship. This architecture, when combined with a strict adherence to the principle of least privilege and environment isolation, provides a scalable framework capable of supporting complex, multi-environment enterprise deployments while minimizing the security risks associated with cloud authentication.

Sources

  1. Google Cloud Platform Technology Partners
  2. Setting Up Workload Identity Federation between GitLab CI/CD and Google Cloud
  3. GitLab Runner in GCP VM Issue
  4. GitLab Google Cloud Documentation

Related Posts