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.
| Format | Strengths | Weaknesses |
|---|---|---|
| XML | Rich structure, schemas, mature tooling | Verbose, hard to read |
| JSON | Concise, universal, easy for programs | No comments; strict quoting and commas |
| YAML | Very readable, supports comments | Indentation 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:
- Triggers (
on) decide when the workflow runs. The movie app’s workflow runs on apushtomain, on apull_requesttargetingmain, and onworkflow_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) scan | Full (active) scan | |
|---|---|---|
| What it does | Crawls (spiders) the site and inspects responses without attacking | Sends crafted attack payloads to inputs |
| Finds | Missing security headers, cookie flags, information leaks, insecure configuration | Injection, cross-site scripting, and other exploitable flaws |
| Risk to the target | Low | Can change data or degrade service |
| Run it against | Any environment you’re authorized to test | Only 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 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 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.
1. In a GitHub Actions workflow, what runs in parallel by default?
Steps run in order inside a job; separate jobs run in parallel on their own runners unless a dependency is declared.
2. Why should a pipeline use npm ci rather than npm install?
Reproducible installs mean the pipeline tests the exact dependency tree that was reviewed.
3. What is the key difference between a ZAP baseline scan and an active scan?
Passive scanning inspects traffic without attacking; active scanning tries exploits and must only target systems you're authorized to test.
4. Which YAML statement is correct?
YAML forbids tabs for indentation, and indentation determines structure.
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.