๐งช DevSecOps Pipeline Lab
Build a complete secure CI/CD pipeline with automated security testing, container security, and infrastructure as code
Advanced LevelLab Overview
This comprehensive lab exercise will guide you through building a complete DevSecOps pipeline that integrates security at every stage of the software development lifecycle. You'll implement automated security testing, container security scanning, infrastructure as code security, and continuous security monitoring.
๐ฏ Learning Objectives
- Implement automated security testing in CI/CD pipelines
- Configure container security scanning and vulnerability management
- Set up infrastructure as code security with automated scanning
- Integrate secrets management into development workflows
- Implement security monitoring and observability
- Configure compliance automation and policy enforcement
๐๏ธ Lab Environment Setup
Prerequisites Installation
Required Tools:
- Docker and Docker Compose
- Git and GitHub account
- Cloud provider account (AWS/GCP/Azure)
- VS Code or preferred IDE
- Terraform (latest version)
- Kubectl (if using Kubernetes)
Environment Configuration
1. Clone the Lab Repository
git clone https://github.com/your-org/devsecops-lab.git
cd devsecops-lab
2. Set up Environment Variables
# Copy environment template
cp .env.template .env
# Edit with your configuration
nano .env
3. Initialize Infrastructure
# Initialize Terraform
terraform init
terraform plan
terraform apply
๐ Lab Exercises
Exercise 1: Secure CI/CD Pipeline Setup
Objective
Create a GitHub Actions workflow that integrates multiple security testing tools.
Tasks
- Set up GitHub Actions workflow file
- Configure SAST scanning with CodeQL
- Integrate DAST testing with OWASP ZAP
- Implement dependency scanning with Dependabot
- Configure security policy enforcement
Sample Workflow Configuration:
name: DevSecOps Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run CodeQL Analysis
uses: github/codeql-action/init@v2
with:
languages: javascript, python
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Run OWASP ZAP Scan
uses: zaproxy/action-full-scan@v0.4.0
with:
target: 'https://your-app.com'
rules_file_name: '.zap/rules.tsv'
Exercise 2: Container Security Implementation
Objective
Implement comprehensive container security scanning and hardening.
Tasks
- Create secure Dockerfile with multi-stage builds
- Configure Trivy for vulnerability scanning
- Implement container image signing
- Set up runtime security monitoring with Falco
- Configure Kubernetes security policies
Secure Dockerfile Example:
# Multi-stage build for security
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
FROM node:18-alpine AS runtime
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodejs -u 1001
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY --chown=nodejs:nodejs . .
USER nodejs
EXPOSE 3000
CMD ["node", "server.js"]
Exercise 3: Infrastructure as Code Security
Objective
Implement secure infrastructure provisioning with automated security scanning.
Tasks
- Create Terraform configurations for cloud infrastructure
- Configure Checkov for Terraform security scanning
- Implement policy as code with Open Policy Agent
- Set up infrastructure compliance monitoring
- Configure automated drift detection
Terraform Security Configuration:
# Secure S3 bucket configuration
resource "aws_s3_bucket" "secure_bucket" {
bucket = "my-secure-bucket-${random_string.suffix.result}"
# Enable versioning
versioning {
enabled = true
}
# Enable server-side encryption
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
# Block public access
public_access_block {
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
}
Exercise 4: Secrets Management Integration
Objective
Implement secure secrets management throughout the pipeline.
Tasks
- Set up HashiCorp Vault or cloud-native secrets management
- Configure secrets scanning in CI/CD
- Implement secret rotation automation
- Set up secure secret injection into containers
- Configure audit logging for secret access
Vault Integration Example:
# GitHub Actions secret retrieval
- name: Retrieve secrets from Vault
uses: hashicorp/vault-action@v2
with:
url: ${{ secrets.VAULT_URL }}
token: ${{ secrets.VAULT_TOKEN }}
secrets: |
secret/data/app config | CONFIG_FILE
secret/data/app api-key | API_KEY
- name: Use retrieved secrets
run: |
echo "Config: $CONFIG_FILE"
echo "API Key: $API_KEY"
Exercise 5: Security Monitoring & Observability
Objective
Implement comprehensive security monitoring and alerting.
Tasks
- Set up centralized logging with ELK Stack
- Configure security metrics collection
- Implement real-time threat detection
- Set up automated incident response
- Configure compliance reporting
Security Monitoring Configuration:
# Falco rules for container security
- rule: Unauthorized Process in Container
desc: Detect unauthorized processes in containers
condition: >
spawned_process and container and
not proc.name in (nginx, apache, node, python)
output: >
Unauthorized process in container
(user=%user.name command=%proc.cmdline container=%container.name)
priority: WARNING
# Prometheus security metrics
security_vulnerabilities_total{severity="critical"}
security_vulnerabilities_total{severity="high"}
security_vulnerabilities_total{severity="medium"}
security_vulnerabilities_total{severity="low"}
๐งช Lab Validation
Security Checklist
Performance Metrics
Pipeline Execution Time
Target: < 10 minutes
Security Scan Coverage
Target: > 95%
False Positive Rate
Target: < 5%
Mean Time to Remediation
Target: < 24 hours
๐ Additional Resources
- OWASP DevSecOps Maturity Model - Framework for measuring DevSecOps maturity
- Secure Code Warrior - Developer security training platform
- Checkov - Infrastructure as code security scanning
- Trivy - Comprehensive vulnerability scanner
- Falco - Runtime security monitoring
- Open Policy Agent - Policy as code framework
๐ Lab Progress
Track your DevSecOps lab completion:
Complete the exercises above to track your progress