Skip to content

Multi-Cloud Deployments with GitLab

Overview

Sketch OIDC-oriented GitLab CI patterns for AWS (IAM / EKS / ECS), Azure (login / AKS), and Google Cloud (Workload Identity / GKE / Cloud Run) without embedding long-lived cloud keys in the repository.

Modern GitLab deploy jobs federate identity: the job presents a GitLab-issued OIDC token; the cloud exchanges it for a short-lived role. That role then updates EKS/ECS, AKS, GKE, or Cloud Run. Patterns differ by cloud, but the CI shape is the same — authenticate, deploy immutable artefact, protect production.

This is a core tutorial in Module 11 · Cloud Deployments of the REBASH Academy GitLab CI/CD for Cloud & DevOps Engineers series — written for Cloud, DevOps, Platform, and SRE engineers.

Prerequisites

Learning Objectives

By the end of this tutorial, you will be able to:

  • Explain OIDC federation vs static access keys
  • Map AWS IAM roles to EKS/ECS deploy jobs
  • Sketch Azure login + AKS kubectl context
  • Sketch GCP Workload Identity + GKE/Cloud Run
  • Scope identities per environment and branch

Architecture

This topic’s control points and relationships are shown below.

Multi-cloud GitLab deployments

Theory

What it is

Multi-cloud deployment from GitLab means pipelines call cloud APIs with least-privilege, short-lived credentials:

Cloud Identity pattern Common targets
AWS IAM OIDC provider → assume role EKS (aws eks update-kubeconfig), ECS update-service
Azure Federated credentials → az login AKS kubelogin / kubeconfig
Google Cloud Workload Identity Federation GKE, Cloud Run deploy

GitLab’s JWT (CI_JOB_JWT_V2 / id tokens, depending on version) is trusted by a cloud identity provider you configure once. Jobs request id_tokens and exchange them in before_script.

Why it matters

Static keys in CI variables leak, rarely rotate, and often are over-privileged. OIDC binds trust to project, branch, and environment claims so a compromised MR runner cannot assume production roles. Multi-cloud teams need one mental model — federate, deploy SHA artefact, gate production — even when CLIs differ.

How it works

  1. Configure cloud trust for your GitLab issuer and subject conditions (project path, ref, environment).
  2. Job declares an id token and assumes/exchanges into a cloud role.
  3. Deploy uses that session: update ECS task definition, helm upgrade on EKS/AKS/GKE, or gcloud run deploy with a digest.
  4. Staging roles allow MR or default-branch pipelines; production roles require protected environments.
  5. Terraform (Module 10) often creates the OIDC providers and roles; deploy pipelines only consume them.

Never print tokens. Prefer environment-scoped variables for account IDs and cluster names, not secrets, when using federation.

Key concepts and comparisons

Approach Pros Cons
OIDC / federation Short-lived, auditable, branch-aware Initial IdP setup
Static keys / PATs Simple demos Rotation, leak blast radius
Per-cloud deploy jobs Clear ownership Duplicate pipeline structure — use templates

Common pitfalls

  • Trusting * subjects on the OIDC provider (any project can assume the role).
  • Giving one role rights to all accounts and clusters.
  • Running production deploy jobs on shared MR runners.
  • Mixing long-lived keys “just for break-glass” without separate process.
  • Redeploying different image digests per cloud “environment” for the same commit.

Hands-on Lab

Create a workspace for this tutorial.

mkdir -p ~/rebash-gitlab/module-11 && cd ~/rebash-gitlab/module-11

Focus: parameterise deploy jobs per cloud with OIDC-ready stubs (file-only)

Step 1 – Multi-cloud job matrix

cat > .gitlab-ci.yml << 'EOF'
stages: [deploy]
.oidc_aws:
  id_tokens:
    GITLAB_OIDC_TOKEN: {aud: https://gitlab.com}
  variables: {CLOUD: aws}
.oidc_gcp:
  id_tokens:
    GITLAB_OIDC_TOKEN: {aud: https://gitlab.com}
  variables: {CLOUD: gcp}
deploy_aws:
  extends: .oidc_aws
  stage: deploy
  image: alpine:3.20
  rules:
    - if: $CLOUD_TARGET == "aws"
      when: manual
  script: ["echo Assume AWS role via OIDC — file-only", "echo cloud=$CLOUD"]
deploy_gcp:
  extends: .oidc_gcp
  stage: deploy
  image: alpine:3.20
  rules:
    - if: $CLOUD_TARGET == "gcp"
      when: manual
  script: ["echo Exchange OIDC for GCP WIF — file-only", "echo cloud=$CLOUD"]
EOF

Step 2 – Confirm separate cloud jobs

grep -c 'id_tokens:' .gitlab-ci.yml
grep -E 'deploy_aws:|deploy_gcp:|CLOUD_TARGET' .gitlab-ci.yml

Final step – Cleanup note

# File-only — no cloud credentials
# Keep ~/rebash-gitlab/ for later tutorials

Validation

  • Lab commands run under ~/rebash-gitlab/module-11/
  • You can explain each Theory section in your own words
  • You used modern tooling where it applies to this topic
  • You can describe one production failure mode for this topic

Code Walkthrough

Production practice for Multi-Cloud Deployments with GitLab always combines:

  1. Inspect before you change (status, plan, logs, dry-run)
  2. Prefer reversible, documented changes (Git, IaC, drop-ins, version pins)
  3. Capture evidence (command output, pipeline logs) for handovers
  4. Prefer current tools and APIs over legacy shortcuts
  5. Least privilege — escalate credentials only when required

Keep runbooks short enough to follow under pressure. Automate checks; keep humans for judgement.

Security Considerations

  • Treat credentials and tokens for gitlab as privileged — never commit them
  • Prefer short-lived auth (OIDC, roles, SSO) over long-lived keys
  • Validate blast radius before apply/deploy/delete operations
  • Restrict who can approve production changes
  • Collect audit logs; limit who can read sensitive traces

Common Mistakes

Trusting * subjects on the OIDC provider (any project can assume the role).

Validate assumptions against the Theory section and official docs before changing production.

Giving one role rights to all accounts and clusters.

Lab shortcuts (open security groups, admin roles, skip approvals) must not ship unchanged.

Changing production without a rollback path

Always know how to revert (previous artefact, prior release, state rollback, DNS failback).

Best Practices

  • Encode Multi-Cloud Deployments with GitLab changes as code and review them in pull requests
  • Pin versions (images, modules, actions, provider plugins)
  • Separate environments with clear promotion gates
  • Alert on symptoms with runbooks attached
  • Destroy lab resources; tag everything with owner and expiry where possible

Troubleshooting

Symptom Likely cause Fix
Auth / permission denied Wrong identity, policy, or scope Check caller identity, roles, and least-privilege policies
Timeout / no route Network, DNS, security group, or endpoint Trace path, DNS, and allow-lists before retrying
Drift / unexpected plan Manual change or wrong state/workspace Reconcile desired vs actual; avoid click-ops on managed resources
Pipeline/job red Flaky step, cache, or missing secret Read failing step logs; bisect recent workflow/config changes
Cost spike Idle load balancer, NAT, oversized compute Inventory billable resources; stop/delete labs promptly

Summary

Multi-Cloud Deployments with GitLab is essential for Cloud and DevOps engineers working with gitlab. Practise the lab until the inspection and change path is muscle memory, then continue the track.

Interview Questions

  1. How do you parameterise one pipeline for AWS and GCP deploys?
  2. What OIDC claim conditions should differ per cloud role?
  3. When is a matrix job better than separate deploy jobs?
  4. How do you avoid cross-cloud credential mix-ups in logs?
  5. What shared gates should every cloud deploy still pass?

Sample answer — question 2

Verify the job's cloud selector variables, matching OIDC trust, and that the correct provider CLI is in the image.

Sample answer — question 4

Isolate roles per cloud and environment; keep deploy jobs manual for production. File-only validation is enough until cloud trusts exist.

References