Skip to content
EncryptTechBD
Home Industries Our Work Blog Pricing About Contact Discuss Your Project
বাংলা (BN)
Cloud, DevOps & FinOps 6 min read

CI/CD pipeline security: a step-by-step guide

A step-by-step guide to securing CI/CD pipelines: identity, secrets, dependencies, runners, provenance, deployment controls and monitoring.

E
EncryptTechBD · 0 comments
IBM Blue Gene supercomputer cabinets
Photo: Argonne National Laboratory's Flickr page / Wikimedia Commons (BY-SA)

A CI/CD pipeline is a privileged system. It can read source code, use deployment credentials, build an artefact and publish it to production. If an attacker takes over the pipeline, they do not need to find a bug in the application; they can ship their own code with the organisation's approval process attached.

Securing the pipeline is therefore part of application security, not an infrastructure detail left to one engineer. This guide sets out a practical sequence for a small or mid-sized team in Bangladesh. It assumes the team already uses a source repository and some form of automated build or deployment.

Prerequisites

  • An inventory of repositories, pipelines, runners and deployment targets.
  • A named owner for each production pipeline.
  • Access to the identity provider, secret store and artefact registry.
  • Audit logging enabled for the source repository and the CI/CD platform.
  • Agreement on which environments are production and who can approve a release.

Step 1: map the pipeline and its trust boundaries

Draw the path from a developer's commit to a running production system. Mark every place where code, credentials or artefacts cross a boundary: the repository, the build runner, the package registry, the container registry, the deployment tool and the cloud account. For each boundary, write who can write, who can read and what evidence is logged.

Step 2: harden source control

Require multi-factor authentication for every account that can push or approve code. Protect the main branch with reviews, status checks and a rule that prevents force pushes. Limit who can change pipeline definitions, because a pipeline change can bypass every code review. Remove dormant accounts and personal access tokens, and review repository visibility so internal code is not public by accident.

Step 3: give each pipeline its own identity

Do not share a human administrator account across pipelines. Create a workload identity for each pipeline and grant only the permissions that pipeline needs. Prefer short-lived tokens issued through OpenID Connect or the cloud provider's workload identity federation over long-lived access keys. If a static key is unavoidable, store it in a secret manager, rotate it on a schedule and record who used it.

Step 4: manage secrets properly

  • Keep secrets out of source code, build logs, test fixtures and container images.
  • Use a secret manager with access control and audit logging, not a plaintext variable in a pipeline settings page.
  • Scope each secret to one environment and one pipeline; do not reuse a production key in staging.
  • Rotate secrets after staff changes, suspected exposure or a vendor incident.
  • Enable secret scanning on repositories and block commits that contain a detected credential.

Step 5: control dependencies and build tools

Pin dependency versions with a lockfile and verify the source registry. Use a private or approved registry where possible, and review new packages before adding them. Enable software composition analysis and fail the build on a policy breach, not just warn. Keep build images and runner tools patched, and rebuild them from a maintained base rather than a hand-modified server.

Step 6: isolate build runners

Use ephemeral runners that are destroyed after each job. Do not run untrusted pull-request code on a runner that holds production credentials. Separate the runner pools for trusted main-branch builds and for contributions from forks or external contractors. Restrict outbound network access from the runner, and do not mount the host Docker socket unless the design genuinely requires it.

Step 7: produce provenance and a software bill of materials

Generate a record of what went into the build: source commit, dependency versions, build command, builder identity and time. Produce a software bill of materials for the artefact. Sign the artefact and the provenance, and verify the signature before deployment. Frameworks such as SLSA describe progressive levels for this work; start with a verifiable build for production and expand from there.

Step 8: secure the deployment path

  • Require a separate approval for production when the change is high risk.
  • Use environment protection rules so a deployment cannot start from an unreviewed branch.
  • Give the deployment identity permission to update the target service, not to administer the whole cloud account.
  • Record the artefact digest, approver, time and change reference for every production release.
  • Keep a tested rollback or forward-fix path that does not depend on rebuilding from a developer laptop.

Step 9: add security tests with clear thresholds

Run static analysis, dependency scanning, infrastructure-as-code scanning and container scanning in the pipeline. Define which findings block a release and which create a ticket. A pipeline that reports hundreds of findings and blocks nothing trains the team to ignore it. Start with a small set of high-confidence checks and expand as the team fixes the backlog.

Step 10: monitor and respond

Alert on failed authentication to the CI/CD platform, new deploy keys, changes to pipeline definitions, unusual artefact publishes and deployments outside the approved window. Keep audit logs long enough to investigate an incident. Write a short runbook for a compromised pipeline: revoke tokens, disable the pipeline, identify affected artefacts, notify the owners and redeploy from a trusted commit.

Evidence checklist

  • Inventory of pipelines with an owner and a production flag.
  • Branch protection and MFA evidence for every repository that can deploy.
  • Workload identity configuration and a list of long-lived credentials with rotation dates.
  • Secret scanning enabled and a sample blocked commit.
  • Runner configuration showing ephemeral instances and network restrictions.
  • Signed artefact and provenance verification result.
  • Audit log excerpt for a production deployment.
  • Incident runbook tested in a tabletop exercise.

Common mistakes

  • Storing a cloud key in a pipeline variable because it was quick.
  • Letting pull requests from forks run on a privileged runner.
  • Giving the CI service account owner access to the cloud subscription.
  • Pinning a dependency by tag instead of a digest or verified version.
  • Building once for staging and again for production, so the artefact differs.
  • Treating a green pipeline as proof of security.

Metrics

Track the share of pipelines using short-lived identity, the number of secrets outside the secret manager, the percentage of production artefacts with verified provenance, mean time to patch a critical dependency and the number of deployments that bypassed approval. Add the time to revoke a compromised credential, because that is the measure that matters during an incident.

Where this fits in our work

Pipeline security connects software delivery, cloud access and incident response. If you need help reviewing the current setup, start with Managed Technology & Cybersecurity and review the scope options on our pricing page. For the wider process, read secure software development lifecycle cost in Bangladesh.

Sources

Services that deliver this

Want this implemented properly?

Pricing →

Every engagement starts with a written scope. If a requirement is outside it, we quote it separately before starting.

Responses (0)

No comments yet. Add the first one below.

Leave a response

Your email address will not be published. Required fields are marked *.

Keep reading

More field notes