Integrating GitLab CI/CD with Google Cloud Platform Ecosystems

The architectural synergy between GitLab and Google Cloud Platform (GCP) represents a paradigm shift in how modern engineering teams approach the software delivery lifecycle. By leveraging GitLab's robust source code management and continuous integration capabilities alongside GCP's scalable infrastructure, organizations can achieve a seamless transition from code commit to production deployment. This integration is not merely a connection of two tools but a comprehensive orchestration of build, test, and deployment phases across various compute environments, ranging from traditional virtual machines and serverless functions to sophisticated containerized orchestrators like Google Kubernetes Engine (GKE).

For organizations utilizing the GitLab.com offering, the integration is accessible across multiple subscription tiers, including Free, Premium, and Ultimate. This accessibility ensures that both small-scale developers and large enterprises can utilize GCP's compute runtimes. The core of this integration focuses on minimizing the friction between the version control system and the cloud runtime, enabling a developer-centric workflow where infrastructure is treated as code and deployments are automated through a unified pipeline.

GitLab Self-Managed Installation on Google Compute Engine

For organizations requiring total control over their instance, GitLab Self-Managed can be deployed directly onto Google Compute Engine (GCE). This approach is particularly beneficial for migrating traditional, non-containerized workloads to the cloud or for those who need to maintain strict data sovereignty and configuration control.

The installation process utilizes the official Linux package, which allows administrators to customize the environment to meet specific organizational needs. To initiate this deployment, a user must first possess a Google account and be signed up for the GCP program. New users are typically incentivized with $300 in free credit, which is available for consumption over a 60-day period, providing a risk-free window to evaluate the performance of the GitLab instance.

The deployment of the VM involves navigating to the Google Cloud Console at https://console.cloud.google.com/compute/instances. During the creation of the VM, administrators must specify the instance name, the desired data center location to optimize latency, and the machine type. The selection of the machine type is critical, as GitLab has specific hardware requirements that vary based on the size of the intended user base. Under the Boot disk section, the user must select the appropriate operating system and disk size before finalizing the creation.

Deployment Target Architecture Type Use Case
Single GCE Instance Virtual Machine Small to medium workloads, simple setups
High Availability (HA) Cluster of VMs Enterprise-grade reliability, zero-downtime
Cloud Run Serverless Container Scalable, request-driven applications
Cloud Functions Event-driven Serverless Lightweight, trigger-based logic

Advanced Authentication via Workload Identity Federation

A critical evolution in the security posture of GitLab-to-GCP deployments is the transition from static service account keys to Workload Identity Federation using OpenID Connect (OIDC). Historically, the industry relied on service account keys stored as secrets within GitLab. However, this method introduced significant security risks, as keys required frequent rotation—a process that is often cumbersome and prone to human error, especially when projects enter maintenance mode.

Workload Identity Federation solves this by establishing a trust relationship between GitLab and GCP. In this model, every job running on a GitLab runner hosted by GitLab.com is injected with a JSON Web Token (JWT) via an environment variable. Instead of using a long-lived key, GCP is configured to trust JWT tokens signed by GitLab.com that contain specific assertions. In exchange for a valid JWT, GCP issues a short-lived service account key, drastically reducing the attack surface by eliminating long-lived credentials.

To implement this, a Terraform setup is required to define the identity pool and provider. The following configuration fragment demonstrates the creation of the service account and the identity pool:

```hcl
locals {
gitlaburl = "https://gitlab.com"
gitlab
org = "my-first-org"
wipid = "gitlab-pool"
wipp
id = "gitlab-provider"
}

resource "googleserviceaccount" "sa" {
account_id = "gitlab-deployment-runner"
}

resource "googleprojectiammember" "sa-token-creator" {
role = "roles/iam.serviceAccountTokenCreator"
member = "serviceAccount:${google
service_account.sa.email}"
}

resource "googleiamworkloadidentitypool" "wip" {
workloadidentitypoolid = local.wipid
}

resource "googleiamworkloadidentitypoolprovider" "wipp" {
workload
identitypoolid = local.wipid
workload
identitypoolproviderid = local.wippid
attributecondition = "assertion.namespacepath.startsWith(\"${local.gitlaborg}\")"
attribute
mapping = {
"google.subject" = "assertion.sub",
"attribute.aud" = "assertion.aud",
"attribute.projectpath" = "assertion.projectpath",
"attribute.projectid" = "assertion.projectid"
}
}
```

This configuration ensures that only requests originating from the specified GitLab organization can assume the identity of the service account, providing a granular layer of security that is automatically managed without manual key rotation.

Orchestrating Delivery with Cloud Deploy and Artifact Registry

The integration between GitLab and GCP extends beyond basic compute to a fully managed software delivery pipeline involving Artifact Registry and Cloud Deploy.

Artifact Registry serves as the centralized repository for managing container images. The integration allows developers to upload GitLab artifacts directly to the Artifact Registry. Once a container image is pushed, it can be viewed and managed from either the GitLab UI or the Google Cloud Console, providing dual-visibility into the metadata and versioning of the artifacts. This streamlined flow is essential for maintaining a clear audit trail of what code is currently deployed in which environment.

Cloud Deploy further facilitates this by allowing GitLab CI/CD pipelines to create Cloud Deploy releases. This is managed via the create-cloud-deploy-release GitLab Component, which automates the delivery of applications to targets such as Google Kubernetes Engine (GKE) Enterprise edition or Cloud Run. By separating the build phase (creating the image in Artifact Registry) from the deployment phase (promoting the release via Cloud Deploy), teams can implement more rigorous approval gates and canary deployment strategies.

For those utilizing serverless architectures, the deploy-cloud-run GitLab Component provides a direct path to automate the deployment of Cloud Run services. This allows for a highly elastic architecture where the application scales automatically based on incoming traffic, all triggered by a commit in the GitLab repository.

Serverless and Event-Driven Integration with Cloud Functions

Beyond containers, GitLab provides a direct pathway to Google Cloud Functions (GCF), which is Google's event-driven serverless compute platform. This is particularly powerful for teams adopting a cloud-native architecture where specific pieces of logic need to execute in response to events—such as a file upload to a bucket or a database change.

Developers can store their function code in GitLab SCM and utilize GitLab CI/CD to deploy these functions directly. This capability enables the automation of development for services like Firebase, allowing teams to treat their serverless functions with the same rigor as their primary applications, including automated testing and staged rollouts.

Operationalizing the Pipeline Flow

A standard end-to-end software delivery pipeline in this ecosystem typically follows a structured sequence of events. The process begins when a developer creates a feature branch from the application repository. As the developer makes changes to the code, they open a merge request to merge the updated code into the main branch.

The GitLab pipeline is then triggered to execute a series of jobs. These jobs often include the use of the gcloud component, which facilitates the execution of gcloud commands directly within the CI/CD pipeline. This allows for the dynamic configuration of GCP resources, such as updating environment variables or triggering a manual deployment step, as part of the pipeline's logic.

To successfully implement this flow, the following requirements must be met:
- A GitLab account (available in Free, Premium, or Ultimate tiers).
- A Google Cloud project where the user has Project Owner access.
- A local clone or fork of the example repository (such as https://gitlab.com/galloro/cd-on-gcp-gl) to provide the necessary configuration templates.

Infrastructure as Code for GitLab Runners

The deployment of GitLab runners on Google Cloud can be fully automated using Terraform. This allows organizations to define their runner settings within the GitLab UI and have the actual infrastructure deployed to their Google Cloud project. By treating the runner infrastructure as code, teams can ensure consistency across multiple environments and easily scale their build capacity by adjusting the Terraform configuration.

This approach solves the "bootstrap" problem. In many scenarios, there is a dependency loop where a pipeline is needed to deploy the runner that executes the pipeline. By using a combination of Terraform and the Google Cloud API, the initial runner setup can be performed independently, after which the runners can manage their own updates and scaling through the CI/CD pipeline.

Conclusion

The integration of GitLab with Google Cloud Platform transforms the DevOps process from a series of fragmented steps into a cohesive, automated pipeline. By moving away from insecure static keys toward Workload Identity Federation, organizations not only improve their security posture but also reduce the operational overhead associated with credential management. The ability to target diverse compute environments—from the raw power of Compute Engine VMs to the agility of Cloud Run and the event-driven nature of Cloud Functions—ensures that GitLab remains a versatile hub for any cloud strategy.

The synergy provided by Artifact Registry and Cloud Deploy creates a professional-grade delivery mechanism that supports the most demanding enterprise requirements, including GKE Enterprise deployments. Ultimately, the transition to this integrated architecture allows developers to focus on writing code rather than managing the plumbing of the cloud, resulting in faster lead times for changes and a more resilient deployment process.

Sources

  1. Installing GitLab on Google Cloud Platform
  2. Securely Deploy Using Google Cloud Identity Federation and GitLab
  3. Software Delivery Pipelines with GitLab CI/CD and Cloud Deploy
  4. GitLab Technology Partners: Google Cloud Platform
  5. Google Cloud GitLab Integration Documentation

Related Posts