RousselTMLEARNING

TP · GitLab CI/CD: from discovery to expertise

Lab: Factor and secure the pipeline

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
Mode :

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. 1. Factor

    Why? A shared definition fixes a problem once for all jobs.

    Move image, cache and installation into a hidden .python job in ci/python.yml, include it and make the test job inherit it. Add the SAST and Secret-Detection templates.
  2. 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 the gl-secret-detection-report.json artifact. Then delete the branch.
  3. 3. Protect a variable

    Why? A protected variable only exists for protected branches: a test branch cannot read it.

    Create a masked, protected DEPLOY_KEY, then check it is empty in a job run from an unprotected branch.
  4. 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 an id_tokens and 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

  • ⏱ Estimated time : ≈ 45 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

4.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

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...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!