OneNym.idDiscuss deployment
English

THE HARDENED STACK / Chapter 9

Secure Development and DevSecOps

If your team builds apps, scripts or infrastructure as code, it is a software team, and its code and dependencies are part of the attack surface. This chapter shows how to let automated checks catch the quiet mistakes before they ship.

This page summarises the chapter. The full text is in the book.

Shift left and a lightweight secure SDLC

The chapter opens with a pipeline scan at Meridian that caught two ordinary problems before merge: a vulnerable library three levels deep in the dependency tree and a live SMS-provider API key left in an old test file. The book's argument is that recent damaging breaches have come through poisoned dependencies and leaked secrets more than through firewalls, and that machines should catch these mistakes on every change.

Shifting left rests on a simple observation: a flaw costs more to fix at each later stage, from design to review to scan to production. A secure SDLC adds a security consideration at each stage rather than at the end. For a small team this means a few automated gates plus treating security findings like any other bug. The design-stage threat model can be three questions asked aloud: what data does this touch, who should and should not reach it, and what happens if input or callers are hostile.

Secrets never belong in code

API keys, passwords, tokens, private keys and connection strings must never sit in source code, committed configuration or container images. Code is cloned and backed up widely, and version control keeps history, so a secret committed once must be treated as compromised and rotated, not merely deleted. Applications should hold a reference and fetch the value at runtime from a secret manager such as Azure Key Vault, AWS Secrets Manager or HashiCorp Vault. Encrypted secrets in the repository or files kept out only by a gitignore rule are described as half-measures that lack central rotation and an access log.

Supply-chain and dependency risk

Most of an application is other people's code, and every dependency runs with the application's privileges. The risks include known vulnerabilities (CVEs), abandoned packages, deliberately poisoned releases and typosquatted names. Since nobody can vet transitive dependencies by hand, the defence has to be systematic: generate a software bill of materials (SBOM) in the build, pin versions with a lockfile, scan on every build and on a schedule, and update deliberately rather than pulling every new release blindly. At Meridian, the flawed parser had been pulled in by the web framework; checking the SBOM, confirming the code path was reachable and upgrading the framework took about twenty minutes.

Scanning in the pipeline, code review and branch protection

The CI/CD pipeline is the natural home for security gates because it runs on every change. The book ranks four kinds of scanning by value: dependency scanning (software composition analysis) first, then secret scanning, then static analysis (SAST), then dynamic testing (DAST) when it earns its place. Scans should run on pull requests, fail on high and critical findings and on any committed secret, and report the rest without blocking. To avoid drowning in false positives, start by scanning new and changed code, record a reason for each suppression, and surface findings as comments on the pull request.

Scanners miss flawed logic and missing authorisation checks, so a human review is still needed. Branch protection on main should require pull requests, at least one approval from someone other than the author, a passing security pipeline, an up-to-date branch, and no force-push or deletion; sensitive repositories can add code owners and signed commits. Very small teams can apply this most strictly to production and to code touching authentication, payments or customer data, with a logged self-approval path for genuine gaps. An expert section adds that the CI/CD system is itself a target: use short-lived OIDC credentials, scope pipeline permissions tightly, pin actions and images to digests, and consider signing build artifacts.

Container and image hygiene

Carelessly built images carry shells, package managers, build tools and leftover credentials that help an intruder. The guidance is to start from a minimal base pinned to a digest, prefer slim or distroless images, run as a non-root user, use multi-stage builds so build tools stay out of the final image, inject secrets at runtime and scan images for vulnerabilities. Containers share the host kernel, so genuinely untrusted workloads need stronger isolation; for your own reviewed application, a hardened image is a proportionate posture.

KEY POINTS

Key points

  • Add dependency scanning to the build this week as the first security gate.
  • Scan the full Git history for secrets and rotate, not just delete, anything found.
  • Move secrets out of code and configuration into a secret manager read at runtime.
  • Generate an SBOM in the build and pin dependencies with a lockfile.
  • Protect main: pull requests only, one independent review, passing security checks, no force-push.
  • Build containers from a pinned minimal base, run as non-root, and scan every image.

QUESTIONS

Common questions

What does shift left mean in application security?
Shift left means moving security checks as early as possible in development, because a flaw becomes more expensive to fix at each later stage, from design through code review and scanning to production. In practice it means a quick threat model at design time, secure coding habits, automated scans before merge and human review. For a small team the goal is a handful of automated gates rather than a heavyweight process.
What should I do if a secret was committed to a Git repository?
Treat it as compromised and rotate it. Deleting the secret in a later commit does not remove it, because version control keeps it in history and the repository has already been cloned and backed up. After rotating, move the value into a secret manager and have the application fetch it at runtime, then add secret scanning so the next one is caught before it is committed.
Which security scans should be added to a CI/CD pipeline first?
The Hardened Stack recommends dependency scanning first, because it gives the most value for the least effort, then secret scanning, since together they catch the two most common real-world failures. Static analysis (SAST) comes next, and dynamic testing (DAST) later if it is worth the setup. Run the scans on pull requests before merge, fail the build on high and critical findings and on committed secrets, and report the rest.
What is an SBOM and why does it matter?
A software bill of materials (SBOM) is an inventory of every component in an application, both direct and transitive, with versions. Without it you cannot tell whether a newly announced vulnerability affects you. Generate it automatically in the build and combine it with a lockfile, scanning on every build and deliberate, reviewed updates.
How should container images be hardened?
Start from a minimal, trusted base image pinned to a digest, preferably slim or distroless so there is no shell or package manager for an intruder to use. Run as an unprivileged user, use multi-stage builds so compilers and source never reach the final image, inject secrets at runtime instead of baking them in, and scan images for known vulnerabilities as the base ages.