For IT professionals and developers
Free for every learner
About 10 minutes

Lesson 02 of 7 · DevSecOps for IT professionals and developers

Secure a CI/CD pipeline

Build a practical review of pipeline permissions, dependencies, secrets, release gates, and artifact integrity.

Anyone can read this lesson. Completion is saved to a learner account.

Lesson objective

By the end, you can

Given a software delivery workflow, identify its trust boundaries and apply least privilege, protected credentials, reviewed dependencies, and controlled artifact promotion before release.

Practical instruction

Secure the path from change to release

Map the pipeline and its trust boundaries

A CI/CD pipeline is privileged automation: it reads source, downloads dependencies, runs tools, creates artifacts, and may deploy to systems. Start by mapping those steps and the identities, permissions, data, and environments each one can reach. A pull request from outside the trusted team is a different trust boundary from a reviewed change on a protected branch.

Keep verification separate from release. Tests and scans can run early on proposed changes with read-only access. A production release should use a reviewed source revision, a protected environment, and the approval process your organization requires.

Limit permissions and protect credentials

Start with the minimum repository permissions needed, then grant additional access only to the job that requires it. Avoid broad write permissions for an entire workflow. Untrusted contribution code must not receive production credentials or a token that can alter protected branches, release packages, or change infrastructure.

Prefer short-lived, narrowly scoped identities, such as workload federation when the platform supports it. Store any approved secret in the platform’s protected secret store, scope it to the required environment, and prevent it from reaching pull-request jobs. Masking a value in logs does not make it safe to expose to code that can use it.

Make dependencies and checks reviewable

Use a lockfile and reproducible install mode so a build resolves the dependencies that were reviewed. Pin third-party pipeline actions or plugins to a reviewed immutable revision, and update those pins through a controlled review process. Keep the tool versions and scan configuration visible to maintainers.

Run appropriate tests and security checks, such as secret detection, dependency analysis, and static analysis, before release. Decide how findings are handled: define which results block a release, who can approve an exception, and where the decision is recorded. A scanner is a signal to review, not proof that a build is secure.

Promote the exact artifact you reviewed

Build an artifact once, identify it by a digest, and promote that same artifact through test and production environments. Rebuilding separately for production can produce different bytes from the ones that passed checks. Keep provenance, scan results, source revision, and approvals available so an operator can explain what was released.

Use protected branches and environment approvals for consequential releases. If a required check fails or its result cannot be verified, keep the release blocked and follow the organization’s documented exception path rather than silently skipping the control.

Safe hands-on exercise

Review a fictional pipeline

A fictional team reviews this workflow before adopting it. The file is a teaching sample only: do not run it, connect it to a repository, or add real credentials.

on:
  pull_request_target:
  push:
    branches: [main]
permissions: write-all
jobs:
  verify:
    steps:
      - uses: actions/checkout@v4
      - uses: example/security-scan@main
      - run: npm ci
  deploy:
    if: github.event_name == "pull_request_target"
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - run: ./deploy.sh
        env:
          CLOUD_KEY: ${{ secrets.CLOUD_KEY }}

Apply the lesson

Select the controls this workflow needs before it can be trusted. Include controls for contribution permissions, credentials, third-party code, and release integrity.

Select the missing pipeline safeguards

A complete review identifies all four required safeguards and rejects both unsafe recommendations. Read the feedback for each choice to compare your review with the lesson. This check runs only in your browser; it does not execute or save a workflow.

Knowledge check

Check your understanding

A pull request from an external contributor needs automated checks. Which plan best protects the release boundary?

Choose the best answer