Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

DevSecOps Basics

The whole lesson is free and interactive. Read it here, or press Start lab to run it for real in a live lab, with no account needed.

Container lab8 min read6 commands

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

A check on every push

A college tuck shop has a small web shop. Every time somebody pushes a change, tools can read the code, look for keys, check the libraries and test the running site. That chain of tools is a DevSecOps pipeline, and this lab holds one.

The one rule

Warning

This lab runs a shop that is insecure on purpose. Scan it, and nothing else. It is your own private copy. Never scan a site or code that is not yours without written permission: in the UK that can be a crime under the Computer Misuse Act 1990.

By the end of this lesson

Note

I can run a security scanner against code and read what it finds.

Key words

  • Pipeline: the steps that run on every push.
  • SAST: checking source code without running it.
  • Secret: a key or password that grants access.
  • DAST: testing the running app from outside.
  • Finding: one problem a scanner reports.

Starter: what you already know

Note

Answer in your head. 1. What does git log show? 2. Why is a password in code a risk? 3. What does a web server send before the page? Answers: the commits, newest first; anybody who can read the code can use it; headers.

Before you start

Note

Press Start the lab on the bar at the top of this lesson and wait until it says it is running. The scanners read the shop's repository in /work/tuckshop. Each Run button below types its command into your lab's terminal, one after another in the same session. To watch them, or to type your own, press Open terminal on the bar.

1. The repository every scanner reads

The first command lists the shop's four commits: Start the tuck shop, Add card payments, Read the payments key from the environment, and Describe the cloud it runs in. The second lists its files: app.py, settings.py, requirements.txt, a Dockerfile and a deploy folder.

Command
docker exec gitleaks git -C /work/tuckshop log --oneline

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Command
docker exec gitleaks ls /work/tuckshop

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

2. A code scanner reads the code

Semgrep checks app.py against the team's three rules in .semgrep.yml. It prints 4 Code Findings: MD5 for passwords on line 32, SQL joined from a search term on line 41, and two commands run through the shell, on lines 54 and 58.

Command
docker exec semgrep semgrep scan --config /work/tuckshop/.semgrep.yml --metrics=off /work/tuckshop

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

3. A history scan finds a key

The files look clean today, but Gitleaks reads every commit. It finds a made-up payments key in settings.py, added on 12 January and removed the next day, under the rule generic-api-key. --redact hides the value.

Command
docker exec gitleaks gitleaks git /work/tuckshop --no-banner --redact -v

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

4. The running shop, weak and fixed

The lab's own small scanner crawls the shop as a visitor would. Port 8000 gets 7 warnings, such as a missing security policy header and a crash report shown on one page. Port 8001, the same shop with its fixes, passes all 7 checks.

Command
docker exec ci python3 dast.py http://shop:8000/

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Command
docker exec ci python3 dast.py http://shop:8001/

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

A common mistake

Warning

Many people think that once a key is deleted from a file it is gone. Every commit is still in the history, and every clone has a copy. A key that was ever pushed must be replaced and the old one cancelled.

Exit check

Tip

Answer without looking back. 1. Which tool read the code? 2. Where did Gitleaks find the key? 3. Which port passed every check? 4. What do you do with a pushed key? Answers: Semgrep; in settings.py, in an old commit; port 8001; replace it and cancel the old one.

For teachers

Tip

This lesson is a small example of a lesson worked in a lab: the steps and the Run buttons are the lesson, and the lab is each student's own copy. The lab holds a Git server, the shop and four scanners, and nothing here marks itself: the student hands in what each scanner found. The module DevSecOps pipelines goes further: writing rules, a pre-commit hook, pip-audit, Trivy and a gate that blocks a merge. Key learning points: 1. A pipeline runs scanners on every push. 2. A history scan finds what the files no longer show. 3. A running app is tested from outside. Common mistake: thinking a deleted key is gone. Equipment: the lab and its terminal. Tip: ask students to read the commit messages and guess where the key is before the history scan. Copy it into your own module and change it, or build one from scratch with the Lab menu in the lesson builder.

Teaching a class? Set these lessons for your students with marking and a lab for every student.