GitLab CI/CD
DevOps / CI-CD GitLab CI, id_tokens OIDC
Delivery Constraint & Opportunity Analysis · Updated 1 month, 2 weeks ago
Content
Skill: GitLab CI/CD
Capability Domain: DevOps / CI-CD
Technology Stack: GitLab CI, id_tokens OIDC
Linked Activities: Deploy via GitLab CI
When to use
Lake Scope Contract ci is gitlab_ci. Skip this skill if the lake repo lives on GitHub.
Copy-this
Starter file: .gitlab-ci.yml.example in https://github.com/FeatureFactory-io/ops-lake-starter. Copy to .gitlab-ci.yml only if ci: gitlab_ci. Do not also keep a live GitHub deploy.yml against the same AWS account.
Chicken-and-egg (parity with GitHub Actions)
- Laptop, same region as the contract:
cdk bootstrapthen onecdk deploy OpsLakeDeployto mint the GitLab OIDC IAM role. ReadDeployRoleArnfrom stack outputs. - GitLab project → Settings → CI/CD → Variables →
AWS_DEPLOY_ROLE_ARN(masked). NeverAWS_ACCESS_KEY_ID. - Trust
aud=https://gitlab.com(or this GitLab instance URL) and the projectsub(project_path:{group}/{project}:ref_type:branch:ref:main). - After that, never
cdk deploya shared env from a laptop.
Recipe
.gitlab-ci.yml: adeploystage withrules: if: $CI_COMMIT_BRANCH == "main", using GitLab'sid_tokensblock to mint an OIDC token and assume an AWS role — noAWS_ACCESS_KEY_IDCI/CD variable.id_tokens:
yaml id_tokens: GITLAB_OIDC_TOKEN: aud: https://gitlab.com
Thenaws sts assume-role-with-web-identity --role-arn $AWS_DEPLOY_ROLE_ARN --role-session-name gitlab-deploy --web-identity-token $GITLAB_OIDC_TOKEN --duration-seconds 3600.- Steps: pytest →
cdk synth→cdk diff→cdk deploy --require-approval never, withwhen: manualin front of the production deploy job. Fail the job ifcdk diffis not empty and you have not approved the manual job — do not invent a line-count number. - Register a GitLab Environment (
production) against the deploy job so GitLab's environment view shows current deployment state. - After first pipeline, record
DeployRoleArn, webhook URL,StreamlitMartUrlindocs/deploy-manifest.yaml. - Prove: a
mainpipeline log showsAssumedRole/ successfulcdk deploy, not an AccessKey login.
Pitfalls
- This and GitHub Actions CI/CD are alternative paths to the same outcome — running both against the same AWS account invites split-brain deploys; pick the one matching where the repo actually lives, don't stand up the other "just in case."
- Skipping the laptop mint: GitLab OIDC cannot assume a role that does not exist yet.
Details
- Capability Domain:
- DevOps / CI-CD
- Technology Stack:
- GitLab CI, id_tokens OIDC
- Created:
- 2 months ago
- Updated:
- 1 month, 2 weeks ago
Playbook
Activities Using This Skill 1
- Deploy via GitLab CI Model and Deploy Infrastructure as Code