What you will learn in this TP
- Factor with include and extends
- Add built-in security scans
- Protect a sensitive variable
- Get a job OIDC token
All steps and instructions are shown. Recommended for this lab: autonomous
Introduction #
Context. Three other teams want the same pipeline, and the security audit requires code and secret scanning on every merge request.
Prerequisites: a free GitLab.com account, Git and Python 3, the Lab 2 project · Estimated time: 45 min
A factored pipeline, SAST and secret detection reports, and an OIDC identity ready for the cloud.Setup #
Guided steps, with their solution.
1. Factor
Why? A shared definition fixes a problem once for all jobs.
Move image, cache and installation into a hidden.pythonjob inci/python.yml, include it and make thetestjob inherit it. Add the SAST and Secret-Detection templates.2. Test secret detection
Why? Checking a control really detects a problem avoids a false sense of security.
On a branch, commit a fake token in GitLab format, open a merge request and look at thegl-secret-detection-report.jsonartifact. Then delete the branch.3. Protect a variable
Why? A protected variable only exists for protected branches: a test branch cannot read it.
Create a masked, protectedDEPLOY_KEY, then check it is empty in a job run from an unprotected branch.4. Get an OIDC token
Why? The OIDC token replaces long-lived cloud keys: it expires and describes precisely who requests it.
Add a job that requests anid_tokensand prints its claims (project, branch, environment), never the token itself.
Validate your work
Check that each goal above is reached and that you get the result described in the introduction.
Difficulty level : ●●●●○ (4/5)
My progress
Sign in to track your progress and take notes. Sign in
💬 Questions about this lesson
No questions yet: be the first to ask for help or share your configuration.
Recommended Articles
Reusing and securing GitLab pipelines
Industrializing GitLab CI/CD: extends, anchors and !reference, include, CI/CD components and cata...
GitLab CI/CD best practices and troubleshooting
Running GitLab CI/CD day to day: speeding up pipelines, controlling compute minutes, organizing f...
Azure YAML pipelines: stages, tasks, variables and templates
Writing Azure pipelines in YAML: trigger and pr triggers, stages, jobs and steps, versioned tasks...
DevSecOps: securing the software supply chain end to end
Integrate security into the DevOps pipeline: shift-left, threat modeling, secret detection, SAST,...
The Twelve-Factor App
A detailed guide to the twelve-factor methodology for building modern, scalable applications in c...
GitLab CI/CD: concepts and architecture
Discover GitLab CI/CD: the DevSecOps platform, the .gitlab-ci.yml file, pipelines, stages and job...
End-to-end CI/CD (1/5): principles and anatomy of a pipeline
Understand end-to-end CI/CD: continuous integration, continuous delivery and continuous deploymen...
Terraform in CI/CD: pipelines, plan review, OIDC and GitOps
Automate Terraform: plan pipeline on merge requests and apply after approval, posting the plan as...
Building and delivering with GitLab: registry, environments and deployments
Delivering with GitLab CI/CD: building and publishing images to the project registry, package reg...