DevOps CI/CD Security
CI/CD Security is the practice of embedding security controls throughout the Continuous Integration (CI) and Continuous Delivery/Deployment (CD) pipeline. The goal is to deliver software quickly without sacrificing security.
This concept is often referred to as DevSecOps, where security becomes a shared responsibility across development, operations, and security teams.
Why CI/CD Security Matters
Section titled βWhy CI/CD Security MattersβModern applications are deployed frequently, sometimes multiple times per day. Without automated security controls:
- Vulnerabilities can be introduced into production rapidly.
- Secrets (API keys, passwords, tokens) may be exposed.
- Malicious dependencies can enter the software supply chain.
- Infrastructure misconfigurations can create security risks.
- Attackers can compromise build systems and inject malicious code.
CI/CD security aims to detect and prevent these issues before deployment.
CI/CD Pipeline Security Overview
Section titled βCI/CD Pipeline Security OverviewβDeveloper β βΌSource Control (Git) β βββ SAST βββ Secret Scanning βΌBuild Stage β βββ Dependency Scanning βββ SBOM Generation βΌTest Stage β βββ Security Tests βββ IaC Scanning βΌContainer Build β βββ Container Scanning βΌDeployment β βββ Approval Gates βββ Policy Enforcement βΌProduction β βββ Runtime Monitoring βββ Threat DetectionSecurity Controls in the CI Stage
Section titled βSecurity Controls in the CI Stageβ1. Source Code Scanning (SAST)
Section titled β1. Source Code Scanning (SAST)βStatic Application Security Testing (SAST) analyses source code without executing it.
Detects:
- SQL Injection
- Cross-Site Scripting (XSS)
- Hard-coded credentials
- Authentication flaws
- Insecure coding patterns
- SonarQube
- Checkmarx
- Veracode
- Semgrep
- Microsoft Security Code Analysis
2. Secret Scanning
Section titled β2. Secret ScanningβDevelopers sometimes accidentally commit:
API KeysPasswordsCertificatesDatabase connection stringsJWT signing keysSecurity scanners detect such secrets before code is merged.
- GitGuardian
- TruffleHog
- GitHub Secret Scanning
- Gitleaks
Example:
// Badstring apiKey = "abc123-secret-key";The pipeline should fail if this is detected.
3. Dependency Scanning
Section titled β3. Dependency ScanningβApplications depend heavily on third-party libraries.
Example:
Newtonsoft.JsonLog4NetEntityFrameworkA vulnerable package can compromise the application.
- Snyk
- Dependabot
- OWASP Dependency-Check
- GitHub Advanced Security
Checks:
- Known CVEs
- Outdated packages
- License violations
Security Controls in the Build Stage
Section titled βSecurity Controls in the Build Stageβ4. Supply Chain Security
Section titled β4. Supply Chain SecurityβAttackers increasingly target software supply chains.
Examples:
- Malicious package uploads
- Build server compromise
- Dependency hijacking
Mitigations:
- Package signing
- Trusted repositories
- Dependency pinning
- Build provenance verification
5. Software Bill of Materials (SBOM)
Section titled β5. Software Bill of Materials (SBOM)βAn SBOM is an inventory of every component used in the application.
Example:
Application:βββ ASP.NET Core 9βββ Serilog 4.0βββ AutoMapperβββ Newtonsoft.JsonBenefits:
- Faster vulnerability investigations
- Compliance support
- Supply-chain visibility
Tools:
- Syft
- CycloneDX
- SPDX
Security Controls in the Testing Stage
Section titled βSecurity Controls in the Testing Stageβ6. DAST
Section titled β6. DASTβDynamic Application Security Testing analyses a running application.
Detects:
- Authentication issues
- Session vulnerabilities
- XSS
- Security misconfigurations
Tools:
- OWASP ZAP
- Burp Suite
- Acunetix
7. Infrastructure as Code (IaC) Scanning
Section titled β7. Infrastructure as Code (IaC) ScanningβInfrastructure definitions should be checked before deployment.
Example Terraform/Azure Bicep:
Azure Storage AccountAzure SQL DatabaseKubernetes ClusterDetects:
- Publicly exposed databases
- Weak network rules
- Missing encryption
- Excessive permissions
Tools:
- Checkov
- tfsec
- Terrascan
Container Security
Section titled βContainer Securityβ8. Container Image Scanning
Section titled β8. Container Image ScanningβContainer images can contain vulnerabilities.
Example Docker image:
FROM ubuntu:22.04The base image may include vulnerable packages.
Scanners analyse:
- Operating system packages
- Installed libraries
- Known CVEs
Tools:
- Trivy
- Clair
- Anchore
- Microsoft Defender for Containers
9. Container Hardening
Section titled β9. Container HardeningβBest practices:
FROM mcr.microsoft.com/dotnet/aspnet:9.0
RUN adduser appuserUSER appuserAvoid:
- Running as root
- Unnecessary packages
- Open ports not required
CD (Deployment) Security
Section titled βCD (Deployment) Securityβ10. Secure Deployment Gates
Section titled β10. Secure Deployment GatesβBefore production deployment:
β Unit tests passedβ Security scans passedβ Vulnerabilities below thresholdβ Approvals completedThe deployment should automatically stop if requirements are not met.
11. Least Privilege Access
Section titled β11. Least Privilege AccessβCI/CD systems should have only necessary permissions.
Bad:
Contributor access to entire Azure subscriptionBetter:
Deployment permission onlyto specific resource group12. Secrets Management
Section titled β12. Secrets ManagementβNever store secrets in:
Git repositoriesBuild scriptsConfiguration filesUse dedicated secret stores:
- Azure Key Vault
- HashiCorp Vault
- AWS Secrets Manager
Example:
connectionString: $(SQL_CONNECTION_STRING)The secret is injected at runtime.
Runtime Security
Section titled βRuntime SecurityβSecurity should continue after deployment.
Monitor for:
- Unusual logins
- Privilege escalation
- Malware
- Container escapes
- Suspicious network traffic
Tools:
- Microsoft Defender for Cloud
- Microsoft Sentinel
- Falco
- CrowdStrike
CI/CD Security Best Practices
Section titled βCI/CD Security Best Practicesββ Shift security left
β Automate all security scans
β Scan every pull request
β Use signed artifacts
β Generate SBOMs
β Rotate secrets regularly
β Apply least-privilege access
β Continuously monitor production
Donβt
Section titled βDonβtββ Hard-code credentials
β Ignore dependency updates
β Deploy without security gates
β Run containers as root
β Give pipelines excessive permissions
β Rely solely on manual security reviews
CI/CD Security in Azure DevOps Example
Section titled βCI/CD Security in Azure DevOps Exampleβ1. Developer creates Pull Request β2. SAST Scan β3. Secret Scan β4. Dependency Scan β5. Build Application β6. Create SBOM β7. Container Scan β8. Deploy to Test β9. DAST Scan β10. Approval Gate β11. Deploy to Production β12. Continuous MonitoringKey Takeaway
Section titled βKey TakeawayβCI/CD Security (DevSecOps) means integrating automated security checks into every stage of the software delivery pipeline, from code commit to production deployment. The objective is to identify vulnerabilities, misconfigurations, secrets, and supply chain risks as early as possible while enabling fast, reliable, and secure software releases.