The first pipeline I ever built was proud, green, and completely unsafe.
It pulled my code, built a Docker image, pushed it, and deployed. Every step passed. I remember staring at that wall of green ticks feeling like a real engineer. Then I scrolled through my own repo and found an API key sitting in a config file I’d committed three weeks earlier. The pipeline hadn’t noticed. Why would it? I’d never asked it to look.
That’s what DevSecOps really is, at least to me: asking your pipeline to look. Not a new job title, not a pile of expensive tools, just building the habit of checking for security problems at the same speed you ship code.
I’m still learning this, so this isn’t a “twenty years in the trenches” post. It’s what I’ve picked up building pipelines and labs while studying software engineering and security, written for anyone who knows a little Git and Docker and wants to know where security actually fits.
Why “shift left” isn’t just a buzzword
You’ll hear the phrase “shift left” constantly. It just means: find problems earlier. A secret caught when you commit it takes a minute to fix. The same secret found after it’s been in production for a month means rotating credentials, checking logs, and a very uncomfortable conversation.
The pipeline is the perfect place for this, because it already runs on every change. You don’t have to remember anything. You teach the machine what to check once, and it checks every time.
I think about it in three layers: the code and its dependencies, the container, and the infrastructure underneath. Let’s go through them.
Layer 1: Secure the code and dependencies
Step 1: Catch secrets before they land. This was my wake-up call. A secrets scanner such as Gitleaks looks through your commits for things that look like keys, tokens, and passwords. Run it in the pipeline, and ideally as a pre-commit hook on your own machine too.
The lesson I learned the hard way: if a secret has ever been committed, deleting it in a new commit isn’t enough. It’s still in the history. Treat it as leaked, rotate it, and only then clean up.
Step 2: Scan your dependencies.
Most of your app isn’t code you wrote. It’s libraries. Tools like Dependabot, npm audit, or Trivy’s filesystem scan flag packages with known vulnerabilities. I was surprised how many warnings appeared the first time I ran this on a small side project. Dozens, from a handful of direct dependencies.
Step 3: Add static analysis. Tools like SonarQube or Semgrep read your source code looking for risky patterns: SQL built from strings, unsafe deserialization, hard-coded credentials. They’re not perfect, and they do produce false positives, which I’ll get to in the mistakes section.
Layer 2: Secure the container
Containers feel safe because they’re “isolated.” That isolation is weaker than people assume, and a lot of container security comes down to boring choices.
Step 4: Choose a smaller base image.
My early Dockerfiles used a full-fat base image because it “just worked.” A slimmer image (like an -alpine or -slim variant, or a distroless image) has fewer packages, which means fewer things that can have vulnerabilities. When I switched one image, the scanner’s findings dropped dramatically without me changing a line of my own code.
Step 5: Don’t run as root. By default, many containers run as root. Add a user in your Dockerfile and switch to it:
FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
RUN useradd -m appuser
USER appuser
CMD ["node", "server.js"]
It’s a two-line change that limits the damage if someone gets into the container.
Step 6: Pin your versions.
Using latest as a tag feels convenient until the image changes under you and your build behaves differently, or worse, pulls something you didn’t expect. Pin to a specific version, and update on purpose.
Step 7: Scan the image before you push it. Trivy is the one I’ve used most. It scans the built image for known vulnerabilities in OS packages and libraries. Put it in the pipeline between “build” and “push,” so a bad image never reaches your registry.
Layer 3: Secure infrastructure as code
If you use Terraform, CloudFormation, or Kubernetes manifests, your infrastructure is code, which means it can be scanned like code.
Step 8: Scan your IaC before you apply it. Tools like Checkov or Trivy’s config scanning read your Terraform and flag things like a public S3 bucket, a security group open to the whole internet, or an unencrypted database. The first time I ran Checkov on a Terraform setup I thought was fine, it found a security group allowing SSH from anywhere. I’d written it “temporarily” during a test and forgot. That’s the kind of mistake that gets people breached, and it was caught before it existed.
Step 9: Apply least privilege. Give each pipeline, role, and service only the permissions it needs. My early IAM policies used wildcards because they were quicker to write. Tightening them was tedious, and it’s one of the most valuable habits in this whole field.
Putting it together: a simple pipeline
Here’s a stripped-down GitHub Actions workflow that covers the main ideas. Treat it as a starting point, not a finished product:
name: ci-security
on:
pull_request:
push:
branches: [main]
jobs:
security:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Scan for secrets
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Scan dependencies and config
uses: aquasecurity/trivy-action@master
with:
scan-type: fs
severity: CRITICAL,HIGH
exit-code: "1"
- name: Build image
run: docker build -t myapp:${{ github.sha }} .
- name: Scan image
uses: aquasecurity/trivy-action@master
with:
image-ref: myapp:${{ github.sha }}
severity: CRITICAL,HIGH
exit-code: "1"
Two notes. First, I used @master for brevity, but in a real project, pin action versions to a specific release or commit, because a compromised or changed action runs with your pipeline’s permissions. Second, check each action’s documentation, since inputs and licensing details change over time.
Mistakes I made (and keep seeing)
Failing the build on everything. My first version blocked the pipeline on every single finding, including low-severity ones in packages I couldn’t even update. Within a week I was annoyed enough to want to turn the scanner off. That’s the real danger: if security gets in the way constantly, people bypass it. Start by failing only on critical and high findings, and track the rest.
Treating the scanner as the finish line. A green scan doesn’t mean “secure.” It means “no known issues that this tool can detect.” Tools miss things, especially logic flaws and misconfigurations they don’t have rules for.
Ignoring false positives. Static analysis tools raise things that aren’t real problems. Learn to read a finding, decide whether it’s real, and document why you’re accepting or suppressing it. Blindly dismissing everything is as bad as blindly obeying it.
Putting secrets in pipeline files. Use your CI platform’s secret storage, or a proper secrets manager. Never write keys directly into a workflow file or Dockerfile.
Adding everything at once. I tried to bolt on five tools in one afternoon and couldn’t tell which one was causing which failure. Add one check, get it stable, then add the next.
Forgetting the pipeline itself is a target. Your CI system has access to your code, secrets, and often your cloud account. Lock down who can change workflows, use branch protection, and give the pipeline the minimum permissions it needs.
How I’d start if I had to do it again
If you’re beginning from zero, this is the order I’d go in:
- Build a basic pipeline for a small project (GitHub Actions is free and easy).
- Add secret scanning first, since it prevents the most embarrassing mistakes.
- Add dependency and image scanning with Trivy.
- Harden your Dockerfile: slim base, non-root user, pinned versions.
- If you use Terraform, add IaC scanning.
- Only then think about static analysis and fancier tooling.
Do it on a practice project, not a work system you don’t have permission to modify. The point is to make mistakes safely.
Where this leaves me
DevSecOps used to sound to me like a role reserved for people with a decade of experience and a wall of certificates. It isn’t. It’s a set of small habits applied consistently: don’t commit secrets, don’t trust defaults, scan before you ship, and give everything the least access it needs.
I’m still early in this, and my pipelines are still full of things I’ll look back on and wince at. But the leap from “everything passed” to “everything passed and I know what was checked” is one of the most satisfying shifts I’ve made so far. Start with one scanner on one project this week. You’ll almost certainly find something that surprises you, and that’s exactly the point.