Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 38 ยท DevSecOps

Shift-Left Security

Learn shift-left security and DevSecOps: threat modelling, security checks across the CI/CD pipeline (SAST, SCA, secrets, IaC, DAST), quality gates and developer-friendly practice.

Traditional security worked like a final inspection: developers built the product, and a few weeks before release a security team tested it and handed back a long list of problems. Fixing them was expensive, because the design was already fixed and the deadline was close. Shift left means moving security activities earlier in the timeline (to the left on a diagram that runs from idea to production), where problems are cheap to fix and developers still remember the code.

DevSecOps is the culture and set of practices built on that idea. Security is a shared responsibility of developers, operations and security specialists, supported by automation inside the delivery pipeline. In this lesson you will meet the checks that belong at each stage, learn a lightweight way to think about threats before writing code and build a pipeline "quality gate" in Python.

Run security scanners only on code and systems you own or are authorised to test. Dynamic testing in particular must target your own test environment.

Why earlier is cheaper

A flaw found in the design stage costs a conversation. The same flaw found in production can cost an incident, emergency patches and a customer notification. Studies and experience agree on the direction of the curve, even if exact multipliers vary: the later the discovery, the higher the cost. Shifting left also gives developers fast feedback, in the editor or in the pull request, instead of a report weeks later.

Shifting left does not mean abandoning later checks. You still need runtime protection, monitoring and periodic penetration tests (see monitoring and detection). The aim is a layered, continuous approach: "shift left and keep going right".

Security checks along the pipeline

flowchart LR
    A["Plan and design<br/>threat model"] --> B["Code<br/>IDE linting, pre-commit secrets scan"]
    B --> C["Build<br/>SAST, SCA, SBOM"]
    C --> D["Package<br/>IaC scan, container scan, sign"]
    D --> E["Test<br/>DAST, API and integration security tests"]
    E --> F["Deploy<br/>policy gates, admission control"]
    F --> G["Operate<br/>monitoring, CSPM, patching"]
    G --> A

A loop, not a line: operations findings feed the next design.

Check What it looks at Finds Typical tools
Threat modelling The design Design flaws, missing controls STRIDE workshops, OWASP Threat Dragon
Secret scanning Code and history Keys, tokens, passwords gitleaks, TruffleHog, platform push protection
SAST (static analysis) Source code Injection, unsafe functions, weak crypto Semgrep, CodeQL, SonarQube
SCA (composition analysis) Dependencies Known vulnerable libraries, licence issues Dependabot, OSV-Scanner, Trivy
IaC scanning Terraform, templates, Kubernetes YAML Public buckets, open ports Checkov, tfsec/Trivy, KICS
Container scanning Images Vulnerable OS packages, root user Trivy, Grype
DAST (dynamic testing) A running test app Runtime flaws: XSS, misconfigured headers OWASP ZAP (on your own test system)
Runtime Production Attacks, drift Detection tools, CSPM

Each of the middle categories has a dedicated lesson in this chapter: IaC scanning, secrets in pipelines and supply chain and SBOM.

Threat modelling in ten minutes

Threat modelling asks four questions: What are we building? What can go wrong? What are we going to do about it? Did we do a good job? A simple way to answer the second question is STRIDE, a mnemonic for six threat types:

Letter Threat Property violated Example in a cloud API
S Spoofing Authentication Stolen token used to call the API
T Tampering Integrity Changing an order amount in transit
R Repudiation Non-repudiation User denies deleting data and there is no audit log
I Information disclosure Confidentiality Verbose errors leak database names
D Denial of service Availability Unbounded request rate drives up cost
E Elevation of privilege Authorisation Normal user calls an admin endpoint

Draw a data-flow diagram (users, services, data stores, trust boundaries) and walk each element through the six letters. The next exercise automates the walk-through for a small design, to produce a checklist of questions.

Python Generate STRIDE questions for a data-flow diagram

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The output is a conversation guide, not a verdict. The value lies in discussing each question with the team and recording decisions, such as "mutual TLS on the flow" or "rate limiting on the API".

Quality gates

A quality gate is an automatic decision at a pipeline stage: pass, warn or fail. A good gate is:

  • Objective: based on thresholds (for example no critical vulnerabilities with a fix available, no secrets, no public buckets).
  • Fast: developers will route around a gate that takes an hour.
  • Explainable: the failure message says what to fix and how.
  • Tunable: new rules start as warnings, then become blocking.
  • Overridable with accountability: an exception needs an owner, a reason and an expiry date.

Try it: a pipeline gate

Python Evaluate scanner results against a gate

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Three findings block the build, one is only a warning and one is an approved exception. In a real pipeline each blocked finding would link to documentation, and the pull request would stay red until fixed.

Making it work for people

Tools alone do not create secure software. The practices that make shift-left succeed:

  • Fast feedback in the developer's workflow: IDE plugins, pre-commit hooks and pull-request comments rather than separate portals.
  • Low noise: tune rules, deduplicate and show only what the author can act on. A scanner that cries wolf gets muted.
  • Paved roads: provide secure templates, base images, pipeline snippets and libraries, so the secure way is the easy way.
  • Security champions: developers in each team with extra training act as a link to the security team.
  • Training with real examples from your own codebase and incidents.
  • Metrics: track mean time to fix by severity, the number of open critical findings, the percentage of repositories with scanning enabled and how often builds fail on security gates.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does 'shift left' mean?

    Shifting left moves security earlier, where fixes are cheaper, while still keeping later controls such as monitoring.
  2. 2. Which tool category looks for known vulnerabilities in the libraries your project uses?

    Software composition analysis (SCA) matches dependencies against vulnerability databases. SAST analyses your own source code.
  3. 3. In STRIDE, what does the 'R' stand for?

    Repudiation: someone can deny an action because there is no reliable record of it. Audit logs address it.
  4. 4. Which is a feature of a good quality gate?

    Gates must be fast, tuned and understandable. Documented exceptions keep delivery moving without hiding risk.

Summary

  • Shift left moves security checks earlier, where they are cheap, while keeping runtime controls: shift left and keep going right.
  • Pipeline stages have matching checks: threat modelling, secret scanning, SAST, SCA, IaC and container scanning, DAST and runtime monitoring.
  • STRIDE is a quick way to find design threats before code exists.
  • Quality gates need objective thresholds, clear messages, tuning and accountable exceptions.
  • Success depends on fast feedback, low noise, paved roads and shared ownership.

Next: Infrastructure as Code Scanning