Skip to main content

DevSecOps and CI/CD Security: Securing Software From Code to Production

Updated 6 min readMarkdown

Fast Releases

Applications can be built, tested and released to production many times a day using automated CI/CD.

As little as one change in a pull request can result in unit testing, building a container image, and the deployment of a new version of service in minutes.

However, if any security checks are absent or the build pipeline is poorly secured, vulnerabilities and malicious code can be deployed at a similar speed.

DevSecOps and CI/CD Security

DevSecOps means ensuring security is built into development and operations processes.

CI/CD security means ensuring that tools, repos, dependencies and pipelines are secure as source code is transformed into software.

This ensures that:

  • Vulnerabilities are caught early in software development.
  • Secrets are not leaked into version control.
  • Third party libraries and container images are verified before deployment.
  • Build pipelines are not hacked, and malicious code cannot be injected.
  • All production deployments can be traced back to checked commits.

Security built in early in the pipeline improves efficiency and reduces the costs of fixing vulnerabilities.

Why is CI/CD Security Important?

CI/CD pipelines contain highly privileged secrets to cloud platforms, container registries, and package managers.

If a CI/CD pipeline or dependency is compromised, malicious software could be deployed to all users.

Common issues include:

  • Malicious code being deployed due to compromised third party packages or plugins.
  • Leaked secrets in build logs, environment variables or pull requests.
  • Unreviewed malicious commits being deployed to production branches.
  • Tampered build artefacts (containers/binaries).

Securing the CI/CD pipeline improves security for the engineering team and end users.

Common Issues in CI/CD and Supply Chain Security

3.1 Vulnerable Dependencies

Many modern applications use many third party packages. Projects can have hundreds of indirect dependencies.

Prevention:

  • Use Software Composition Analysis (SCA) tools to scan for vulnerabilities in every PR.
  • Ensure version numbers of dependencies are fixed using lock files.
  • Monitor for security alerts, and quickly patch any critical vulnerabilities.
  • Audit all new dependencies before adding to core services.

3.2 Leaked Secrets

Secrets such as API keys, SSH keys, or cloud tokens can be leaked in commit history, or accidentally output in CI pipeline debugging steps.

Prevention:

  • Enforce pre-commit hooks and secret detection in all repos.
  • Do not print sensitive environment variables in CI/CD logs.
  • Use short lived OpenID Connect (OIDC) federations between CI runners and cloud platforms, rather than static secrets.

3.3 Poor Repo/Branch Security

If developers or compromised users can directly commit to main branches, malicious code can be deployed without quality or security checks.

Prevention:

  • Require PRs to be reviewed, and pass status checks before merging.
  • Enforce Multi-Factor Authentication on all source control accounts.
  • Enforce signed commits to verify authorship.
  • Only allow certain people to make changes to CI/CD pipeline config files.

3.4 Poor Container Security

Using outdated OS packages or running as the root user in containers increases the risk of privilege escalation should there be a vulnerability in the application.

Prevention:

  • Minimise the size of container base images (distroless, slim).
  • Scan for vulnerabilities in container images before pushing to registries.
  • Where possible, run containers as non-root users, with read only root file systems.

3.5 Over Privileged CI/CD Runners

Over privileged shared or self-hosted runners can be exploited by malicious PRs from external forks.

Prevention:

  • Use temporary runners to isolate builds. The runners should be destroyed between runs.
  • Only allow maintainer approved CI runs on external PRs.
  • Give strict permissions to only allow deployment to specific targets.

Shift Left Security vs Runtime Security

Application security should be enforced in both shift-left (development), and run-time (production).

Shift Left Security (Development)

  • Detects bugs, secrets and known vulnerabilities in packages early in the development process.
  • Fixing vulnerabilities at this stage is quick and cheap, as developers will be immediately alerted.
  • Fewer preventable vulnerabilities will be present In Production.

Runtime Security (Production)

  • Detects active attacks, zero-day exploits, and suspicious activity.
  • Protects live services via web application firewalls, rate limiting and run-time monitoring.
  • Provides visibility into incidents.

Both security methods compliment each other and should be used together by strong teams.

Best Practice

To ensure security is well integrated in CI/CD:

  • Run quick security checks in all PRs. This includes secret detection, linting and dependency checks.
  • Avoid static secrets in deployment. Use OIDC tokens to allow temporary authentication to cloud platforms.
  • Create a Software Bill of Materials (SBOM). Keep track of all components in each release.
  • Sign deployment artefacts. Sign container images, and validate signatures before deployment.
  • Ensure tools in pipelines are up to date. Regularly patch CI servers, CI runners and plugins.
  • Give clear feedback to developers. Ensure security checks do not cause friction for developers.

Testing

Teams should regularly test security in their deployment pipelines:

  • Check that test secrets in a PR have been blocked by secret detection.
  • Check that unreviewed commits cannot be merged into protected branches.
  • Check that critical vulnerabilities in containers cause deployment jobs to fail.
  • Check that runners have appropriate permissions, and that environment variables are not exposed.

Always ensure testing is performed safely in test repositories/staging environments.

OWASP and Industry Standards

There are several standards available to help teams implement security in CI/CD and supply chains.

  • OWASP Top 10 CI/CD Security Risks: Identifies security issues in CI/CD pipelines. These include poisoned pipeline executions, poor flow control, and poor credential management.
  • SLSA: A framework for ensuring secure and verifiable builds.
  • OWASP DevSecOps Guideline: Practical information for integrating security tools with automation.

These standards can help improve security in CI/CD pipelines.

Future of DevSecOps

Securing supply chains is a key focus in software engineering at the moment.

Trends include:

  • Provenance by default: Knowing exactly how, where, and from what commit all artefacts were built.
  • AI assisted fixing: Suggesting secure fixes for vulnerabilities.
  • Zero trust ephemeral build environments: Avoiding any long lasting credentials at any stage of delivery.
  • Automated SBOM validation: Blocking unverified or tampered with third party components.

Security is increasingly becoming a transparent automated feature in modern engineering platforms.

Conclusion

CI/CD pipelines allow very quick delivery of software. However, if not properly secured, attackers can quickly exploit vulnerabilities.

By securing repos, scanning dependencies, removing static secrets, securing containers, and signing artefacts, secure software can be rapidly delivered.

References

About the author

  • Full-stack developer and cybersecurity student focusing on secure web apps, Linux configurations, and automation.

No comments yet. Be the first to comment.