DevSecOps lab: build a security pipeline and a gate
This lab gives each student a small web shop with mistakes left in on purpose, the Git server that holds it, and the open-source scanners a security pipeline runs. Students scan the code, the Git history, the libraries, the running shop and its Dockerfile and Terraform, then build a gate that stops a risky change being merged.
Every image is pinned by digest. The shop, its one account and the payments key in its history are made up for the exercises. A copy reaches only an allow-list of package sites, which is how pip-audit is installed from PyPI, and none of any other student.
What students learn
Semgrep finds four flaws in the shop's code with the team's own rules, and a sharper rule removes a false positive. Gitleaks finds nothing in today's files and a made-up key in an old commit. pip-audit lists the advisories against three old libraries and their fix versions.
A baseline scan finds 7 warnings on the shop as first written and none on the hardened one. Trivy fails four Dockerfile checks and seven high ones in the Terraform. A gate reads every report, sets a commit status, and a protected branch refuses the merge until it passes.
Run it in your browser
The lab starts six services: gitea, shop, ci, semgrep, gitleaks and trivy. The terminal beside the lab runs each tool with docker exec. Open in the browser shows Gitea on port 3000 (student and student) and the shop on port 8000.
- Open the Container page. Open Build on the bar and choose Run a container. Anybody may open it, and the Git lab and the SQL lab start with no account. Every other lab needs a free account: create one, sign in, then press Start.
- Find the lab. The Sample labs card lists every sample. Find DevSecOps: a security pipeline to build and break.
- Press Start. Start runs it as it is, in one press. Edit the file first opens the compose file so you can change it before you start. The lab is ready in under a minute.
- Open it. On the lab's page, press Open terminal and run a scanner, for example: docker exec semgrep semgrep scan --config /work/tuckshop/.semgrep.yml --metrics=off /work/tuckshop
What to ask students to hand in
Each scanner's main finding, the fix they would make, and what the gate decided before and after their change. Nothing is marked automatically: judging a finding shows whether it was understood.
A basic lesson on this lab
DevSecOps Basics is a small lesson worked in this lab. In it a student lists the shop's commits, scans its code with Semgrep, finds the key in its history with Gitleaks, and scans the running shop on both ports.
Free personal accounts have it in the Basics module, which is on Home, and every college can copy it from the Library's Basics folder. It is deliberately small: the module DevSecOps pipelines goes further, with rules, hooks, pip-audit, Trivy and the gate.
The code on GitHub
The compose file has no Dockerfile of its own: it runs the public images of Gitea, Semgrep, Gitleaks, Trivy and Python, unmodified and not distributed by us. The shop, the baseline scanner and the gate are written by the file when the lab starts. The repository and the shared folder are kept when the lab stops.
Set it as work
Say in the task what to hand in.
- Make the lab. In your module add a task and choose the Container lab card, then In a GitHub repository. Give https://github.com/mitsurutech/lab-devsecops-lab with the branch main. The compose file is the default, compose.yaml. Fork the repository first if you want to change it, for example to add a rule or a check of your own.
- Publish and try it. Publish pins the commit you were shown, so a later change in the repository does not alter a lab you have already set. Start your own copy first.
- Hand it out. Assign it like any task, with a due date if you want one, and say in the task what to do and what to hand in.
- Mark what is handed in. Open a student’s copy and the work they handed in, mark it, and send it back with a reason if it needs more.
Try this lab, and what it costs
A free personal account can work through the basic lessons in this lab, with enough free credit each month to follow most lessons and no card. For a class, a school or college has its first 365 days free for up to 50 students, then pays per student a year, with every lab included and staff free.
Questions people ask
- Why is OWASP ZAP not in the lab?
- Its image is over a gigabyte of Java and needs more memory than a lab service is given. The lab's dast.py is a small scanner written for it in the manner of ZAP's baseline scan: a crawl, passive checks, one harmless probe and a rules file.
- Is the key in the history real?
- No. It is a planted fixture, made up so that the secret scanning lesson has something to find. Nothing in the lab is a real credential.
- Why does my pip-audit count differ from the lesson's?
- pip-audit asks PyPI for the advisories published today, and new ones keep arriving. The old advisories the lessons name stay the same.
- Where is the CI runner?
- The lab's Gitea has no Actions runner, so a student runs the pipeline file in the terminal, which is what a runner does. The commit status and the protected branch are Gitea's own.
- Does it cost anything or use credits for AI?
- No AI is used, so nothing is charged for it. The lab runs like any other container lab.