π§ͺ CI/CD Security Lab
Practice endβtoβend pipeline security: detect secrets, federate identity with OIDC, automate security testing, and generate attestations.
AdvancedLab Objectives
- Scan repositories and history for leaked secrets
- Configure OIDC to authenticate to a cloud provider without static keys
- Integrate SAST/DAST/SCA and container scanning gates
- Generate SBOMs and sign build artifacts with provenance
- Set up alerts and run an incident response drill
Prerequisites
- GitHub account with a test repository
- Cloud account (AWS/Azure/GCP) to configure OIDC trust
- Optional: Docker installed locally
Part 1: Secret Scanning
- Enable GitHub Secret Scanning and Dependabot alerts
- Run local scans:
# TruffleHog trufflehog git file://. # Gitleaks gitleaks detect -v
Part 2: OIDC Federation
- Create a cloud role for GitHub OIDC with restricted policies
- Add a workflow using OIDC, scoped to the repo/ref:
# .github/workflows/oidc-deploy.yml name: OIDC Deploy on: workflow_dispatch permissions: id-token: write contents: read jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: arn:aws:iam::123456789012:role/GHAOIDCRole aws-region: us-east-1 - run: aws sts get-caller-identity
Part 3: Security Gates
- Add SAST with Semgrep/CodeQL, fail on critical
# Semgrep example semgrep --config p/owasp-top-ten --error
- Container scan with Trivy
trivy image --exit-code 1 --severity CRITICAL,HIGH myapp:latest
- IaC checks with Checkov
checkov -d . --soft-fail-exit-code 0 --hard-fail-on HIGH,CRITICAL
Part 4: SBOM & Provenance
- Generate SBOM with Syft and sign artifacts with Sigstore
syft packages dir:./ -o cyclonedx-json > sbom.json cosign generate-key-pair cosign sign-blob --key cosign.key dist/app.tar.gz > app.sig
- Create build provenance attestation in CI
- uses: actions/attest-build-provenance@v1 with: subject-path: 'dist/*.tar.gz'
Part 5: Monitoring & IR Drill
- Forward GitHub audit logs to SIEM and configure alerts
- Simulate a token leak and validate rotation playbook
- Document timelines and corrective actions