CI/CD Pipelines and Security Scanning
Module 4 · DevSecOps I: Pipelines and Scanning

CI/CD Pipelines and Security Scanning

Read a GitHub Actions workflow like an engineer: YAML basics, triggers, jobs, runners, steps, matrices, secrets, and permissions. Then see what an OWASP ZAP baseline scan does, how passive and active scans differ, and how to tune and read the results.

YAML: The Language of Pipelines

CI/CD pipelines are written as configuration files, almost always in YAML (“YAML Ain’t Markup Language”), a human-readable data serialization format — a way of writing structured data as text.

FormatStrengthsWeaknesses
XMLRich structure, schemas, mature toolingVerbose, hard to read
JSONConcise, universal, easy for programsNo comments; strict quoting and commas
YAMLVery readable, supports commentsIndentation mistakes change meaning silently

YAML’s building blocks:

  • Indentation defines nesting. It must use spaces — tabs are not allowed for indentation.
  • Scalars are single values: strings, numbers, booleans.
  • Mappings are key–value pairs (name: CI).
  • Sequences are lists, one item per line starting with -.
  • Comments start with #.

YAML is a superset of JSON in spirit — anything you can express in JSON, you can express in YAML — but because whitespace carries meaning, a single misaligned line can move a setting into the wrong block without any error.


Anatomy of a GitHub Actions Workflow

GitHub Actions is GitHub’s built-in CI/CD service. A workflow is a YAML file in the repository’s .github/workflows/ folder. Its structure nests like this:

Workflow · .github/workflows/ci.ymlon: push · pull_request · workflow_dispatch permissions: least privilegeJob: build_testruns-on: ubuntu-latestuses: checkout the codeuses: set up Node.jsrun: install dependenciesrun: tests (with a secret)steps run in orderJob: zap_scanruns-on: ubuntu-latestuses: checkout the codeuses: ZAP baseline scanruns in parallelJob: deployneeds: build_testruns only if tests pass —added in Module 5waits for its dependency
  • Triggers (on) decide when the workflow runs. The movie app’s workflow runs on a push to main, on a pull_request targeting main, and on workflow_dispatch — a button for running it manually.
  • Jobs are independent units of work. Each runs on a fresh runner — a temporary virtual machine (here, the latest Ubuntu) that is thrown away afterward. Jobs run in parallel unless one declares needs: on another.
  • Steps run in order inside a job. A step either uses a published, reusable action (like “check out the code” or “set up Node.js”) or runs shell commands.
  • A matrix strategy runs the same job across several configurations — for example, several Node.js versions — to catch compatibility problems.

The trigger block is short enough to read at a glance:

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  workflow_dispatch:   # manual "Run workflow" button

Installing reproducibly

npm install resolves versions and may update the lock file. npm ci installs exactly what the lock file specifies, from a clean slate, and fails if the lock file and package.json disagree. Pipelines should use npm ci so that every build tests the same dependency versions that were reviewed.

Secrets and permissions

Tests in the movie app need a database connection string. It’s stored as a repository secret (MONGODB_URI) in GitHub’s settings and injected into the step as an environment variable at runtime. GitHub masks known secret values in logs.

Every workflow also receives an automatic, short-lived GITHUB_TOKEN. The permissions: block limits what that token can do — read the code, write an issue with scan results — following least privilege. If a malicious dependency runs inside your pipeline, the token’s permissions define how much damage it can do.


OWASP ZAP: Scanning a Running App

ZAP (Zed Attack Proxy) is a free, open-source DAST tool maintained under the OWASP umbrella. It sits between a client and a web application, observes the traffic, and probes for weaknesses.

Two scan modes matter:

Baseline (passive) scanFull (active) scan
What it doesCrawls (spiders) the site and inspects responses without attackingSends crafted attack payloads to inputs
FindsMissing security headers, cookie flags, information leaks, insecure configurationInjection, cross-site scripting, and other exploitable flaws
Risk to the targetLowCan change data or degrade service
Run it againstAny environment you’re authorized to testOnly test environments you own, with permission

ZAP’s results are alerts, each with a risk level (high, medium, low, informational), a description, and the URLs where it was seen. A rules file lets you tune each rule to IGNORE, WARN, or FAIL — so a known, accepted finding doesn’t block every build, while a new high-risk one does. In the movie app’s pipeline, the report is saved as a build artifact and summarized in a GitHub issue.

A scan that ends with warnings or a failed status isn’t a broken pipeline — it’s the pipeline doing its job. The decision is what to fix, what to accept with a documented reason, and what to block on.

⚠️ Common Pitfall: Scanning the Wrong Target — or One You Don't Own

Common mistake: wiring the scanner to a convenient public demo site and treating the result as a check on your app.

A scan of someone else’s site tells you nothing about yours, and actively scanning a system you don’t own or have written permission to test can violate laws and terms of service. Point DAST at your own deployed test environment — once the API has a public address (next module), that’s the target. Run active scans only against environments built for it.

⚠️ Common Pitfall: Loose Pipeline Hygiene

Common mistakes: a step that prints all environment variables “for debugging,” and actions referenced by old, floating version tags.

Masking only hides values GitHub knows are secrets; derived or transformed values print in plain text, and logs are often widely readable. Referencing actions by outdated major versions misses security fixes, and floating tags can change underneath you. Pin third-party actions to a specific release (or a commit hash), keep them updated, and never dump the environment in CI.

🧠 Knowledge Check

1. In a GitHub Actions workflow, what runs in parallel by default?

2. Why should a pipeline use npm ci rather than npm install?

3. What is the key difference between a ZAP baseline scan and an active scan?

4. Which YAML statement is correct?


Up Next

The pipeline tests and scans the code, but the API still runs inside a development workspace. Module 5 deploys it to a rented cloud server, adds a deploy job to the pipeline, and deals with the networking problems that follow.