Lab 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.

Duration: 8-10 hours
Difficulty: Advanced
Prerequisites: Basic Docker, Git, CI/CD knowledge
Environment: Docker, GitHub Actions, AWS/GCP/Azure

๐ŸŽฏ Learning Objectives

๐Ÿ—๏ธ 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

  1. Set up GitHub Actions workflow file
  2. Configure SAST scanning with CodeQL
  3. Integrate DAST testing with OWASP ZAP
  4. Implement dependency scanning with Dependabot
  5. 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

  1. Create secure Dockerfile with multi-stage builds
  2. Configure Trivy for vulnerability scanning
  3. Implement container image signing
  4. Set up runtime security monitoring with Falco
  5. 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

  1. Create Terraform configurations for cloud infrastructure
  2. Configure Checkov for Terraform security scanning
  3. Implement policy as code with Open Policy Agent
  4. Set up infrastructure compliance monitoring
  5. 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

  1. Set up HashiCorp Vault or cloud-native secrets management
  2. Configure secrets scanning in CI/CD
  3. Implement secret rotation automation
  4. Set up secure secret injection into containers
  5. 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

  1. Set up centralized logging with ELK Stack
  2. Configure security metrics collection
  3. Implement real-time threat detection
  4. Set up automated incident response
  5. 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

๐Ÿ“ง Stay Updated with New Labs

Get notified when we add new hands-on lab exercises and practical content!

๐Ÿ“ˆ Lab Progress

Track your DevSecOps lab completion:

Complete the exercises above to track your progress

โ† Back to DevSecOps Roadmap