Lesson 1 of 7 in Security basics for DevOps
Shift left and think like a defender
Shifting left means finding and fixing security problems at the earliest stage of the delivery path, in design and code review, instead of after release. Threat modelling is the habit that drives it: you write down what you protect, who might attack it, and which controls stand in the way.
Draft. This lesson is written and waiting for a person to run every command and review it. It is safe to learn from, but check the official documentation for anything you depend on.
Read these first: CI/CD pipelines, Cloud fundamentals with AWS
The problem this solves
Security work that starts after release is expensive. A leaked key or an open port found in production means an incident, a rotation and an apology. The same problem found in a pull request means a one line change.
Without a shared picture of what matters, teams also guess. They harden things nobody wants and leave the one database that holds customer data wide open. You cannot protect everything equally, so you need a short list of what is valuable and how someone could reach it.
How it works
- People and clients
- Network
- Data
- Security
An attacker tries an entry point to reach an asset, and a control placed on that entry point blocks or detects the attempt.
- Attacker to Entry point: 1 tries
- Entry point to Asset: 2 reaches
- Control to Entry point: 3 guards
- Other
- Security
- Control
- Runs code
You describe the system, list what can go wrong, decide what to do about it, check the result, and repeat when the system changes.
- What are we building to What can go wrong: 1 describe
- What can go wrong to What will we do: 2 decide
- What will we do to Did it work: 3 apply
- Did it work to Repeat: 4 revisit
Start with the asset, the thing whose loss would hurt: customer data, a deploy key, the ability to push to production. Then name who could realistically go after it. That may be an outsider on the internet, a bot scanning public repos, or a well meaning colleague with too much access.
Each path from attacker to asset passes through entry points: a login form, an exposed port, a CI token, a dependency you install. A control is anything placed on that path that blocks the attempt or at least tells you about it. The rest of this topic is mostly a tour of controls for the entry points DevOps engineers own.
The second diagram is a small routine you can run in ten minutes on any design, for example in a pull request that adds a new service. Four questions, written down, beat an unwritten feeling that things are probably fine. Shifting left means asking them before the code ships.
Try it yourself
These steps only read your own laptop and write notes into a throwaway folder. Nothing is sent anywhere. Run them in Linux, macOS or WSL.
- 1List what an attacker would want on your machine
env | grep -iE 'token|secret|key|password' | cut -d= -f1
cutremoves everything after the=, so you see variable names and never the values. Every name here is an asset. Ask yourself which of them are long lived. - 2Check whether a repo remote carries a password
git remote -v
Run this inside any git repo of yours. A URL shaped like
https://user:token@host/...stores a credential in plain text in.git/config. If you see one, plan to replace it with SSH or a credential helper. - 3Write a four-line threat model for something you know
mkdir -p ~/threat-demo && cd ~/threat-demo cat > notes-app.md <<'EOF' Building: a notes web app, a database, and a CI job that deploys it. Goes wrong: database password leaks from the repo; stale deploy token is reused; an outdated base image has a known flaw. We will: keep secrets out of git, use short lived deploy credentials, scan images on every build. Check: a scanner runs in CI; we review this file when a new service is added. EOF cat notes-app.md
The format matters more than the example. Replace the content with a real project of yours. Delete the folder afterwards with
rm -r ~/threat-demo.
What breaks, and where to look
The threat model is a long document nobody reads, and it is out of date after one release.
- WHY IT HAPPENS
- It tried to list every possible threat in full detail. Large documents are not revisited, so they stop describing the real system.
- CHECK FIRST
- Cut it to one page with the four questions. Keep it next to the code, for example in the repo, and add a line to your pull request template asking whether the design changed.
A scanner reports hundreds of findings and the team starts ignoring all of them.
- WHY IT HAPPENS
- Findings were never ranked against what you actually protect, so a minor warning in a test tool looks as loud as an exposed database.
- CHECK FIRST
- Go back to your asset list. Sort findings by whether they touch an asset through a real entry point, and fix those first.
When not to use this
- A formal threat model for a throwaway script or a local experiment is overkill. Spend the time when something holds real data, faces the internet or can deploy to production.
- Threat thinking does not replace compliance or a professional security review for regulated systems. It is the habit that makes those reviews cheaper.
Check yourself
What does shifting left mean?
Finding and fixing security problems earlier in the delivery path, such as in design and code review, because early fixes are cheaper than production incidents.
Why list assets before picking tools?
Without knowing what is valuable and how it can be reached, you cannot tell which controls matter, and you may harden the wrong things.
What is a control?
Anything placed between an attacker and an asset that blocks the attempt or detects it, such as a login check, a firewall rule or a scanner in the pipeline.
Keep going
Lesson 86 of 92 in the DevOps path