| name | cloud-devsecops |
| description | Guide complet de DevSecOps cloud — CI/CD pipeline security, IaC scanning (Terraform, CloudFormation, ARM), SAST/DAST, secret scanning, SBOM, supply chain security, et Shift Left |
| category | cybersecurite |
Cloud DevSecOps — CI/CD & Pipeline Security
1. Shift Left — Principes
DevSecOps Pipeline
Code → IaC Scan → SAST → Secret Scan → Build → SBOM → DAST → Deploy → Post-Deploy
│ │ │ │ │ │ │ │ │
│ Checkov Semgrep gitleaks Docker Syft ZAP Prowler GuardDuty
│ tfsec CodeQL truffleHog Trivy Scout Defender
│ Snyk IaC SonarQube └─ Cosign └─ OPA/Gatekeeper
2. Infrastructure as Code Security
Terraform Scanning
checkov -d ./terraform/ --framework terraform -o cli,sarif,json
checkov -d ./terraform/ --skip-check CKV_AWS_1,CKV_AWS_2
checkov -d ./terraform/ --compact
checkov -f ./prod/main.tf --repo-root-for-plan-enrichment .
tfsec ./terraform/ --config-file .tfsec/config.yml
tfsec ./terraform/ --format sarif --output results.sarif
terrascan scan -d ./terraform/ -t aws
terrascan scan -i terraform -f main.tf
snyk iac test ./terraform/
snyk iac test ./terraform/ --report
AWS CloudFormation Scanning
cfn-lint template.yaml
cfn-lint templates/*.yaml --ignore-checks W
cfn_nag_scan --input-path ./templates/
cfn_nag_scan --input-path ./templates/ --output-path ./reports/
checkov -f template.yaml
Azure ARM / Bicep Scanning
bicep build main.bicep --stdout
checkov -f main.bicep
checkov -d ./arm/
Install-Module -Name PSRule.Rules.Azure -Force
Invoke-PSRule -Module PSRule.Rules.Azure -InputPath ./arm/
GitLab CI / GitHub Actions Integration
name: IaC Security Scan
on:
pull_request:
paths:
- 'terraform/**'
- '**.tf'
jobs:
checkov:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Checkov
uses: bridgecrewio/checkov-action@master
with:
directory: terraform/
framework: terraform
output_format: sarif
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
- name: tfsec
uses: aquasecurity/tfsec-action@v1.0.3
with:
working-directory: terraform/
additional_flags: --config-file .tfsec/config.yml
3. SAST (Static Application Security Testing)
CodeQL
codeql database create --language=python --source-root=./app ./codeql-db
codeql database analyze ./codeql-db --format=sarif --output=results.sarif codeql/python-queries
Semgrep
semgrep --config=auto ./app/
semgrep --config=p/python ./app/
semgrep --config=r/semgrep:ci ./app/
semgrep --config=./.semgrep/hardcoded-secrets.yml ./app/
semgrep ci --json --output results.json
SonarQube
sonar-scanner \
-Dsonar.projectKey=myapp \
-Dsonar.sources=. \
-Dsonar.host.url=http://sonarqube:9000 \
-Dsonar.login=<token>
4. Secret Scanning
gitleaks
gitleaks detect --source . --verbose
gitleaks detect --source . --report-format json --report-path report.json
cat > .pre-commit-config.yaml << 'EOF'
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.0
hooks:
- id: gitleaks
EOF
gitleaks detect --source . --no-git
gitleaks detect --source . --verbose --redact
truffleHog
trufflehog git https://github.com/org/repo --only-verified --json
trufflehog filesystem --directory . --only-verified
trufflehog github --org=mon-org --token=<gh-token>
detect-secrets
detect-secrets scan > .secrets.baseline
detect-secrets audit .secrets.baseline
detect-secrets scan --update .secrets.baseline
GitHub Secret Scanning
curl -H "Authorization: token <gh-token>" \
https://api.github.com/repos/org/repo/secret-scanning/alerts
5. Build Security
Docker Build
DOCKER_BUILDKIT=1 docker build --secret id=aws_creds,src=./aws_creds -t app:latest .
RUN --mount=type=secret,id=aws_creds aws sts get-caller-identity
SBOM (Software Bill of Materials)
syft packages app:latest -o cyclonedx-json > sbom.cdx.json
syft dir:./app -o spdx-json > sbom.spdx.json
trivy image --format cyclonedx --output sbom.json app:latest
grype sbom:sbom.cdx.json
Image Signing (Cosign)
cosign sign --key cosign.key <registry>/app:latest
cosign verify --key cosign.pub <registry>/app:latest
cosign sign <registry>/app:latest
cosign verify <registry>/app:latest
cosign attest --predicate slsa.json --type https://slsa.dev/provenance/v1 <registry>/app:latest
6. Pipeline Hardening
GitHub Actions Security
name: Deploy
on: [push]
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Configure AWS
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::<account>:role/github-actions
aws-region: us-east-1
- run: terraform apply -auto-approve
GitLab CI Security
variables:
SECRET: $CI_JOB_TOKEN
Prevent Supply Chain Attacks
export DOCKER_CONTENT_TRUST=1
docker pull alpine:latest
npm audit --audit-level=high
7. DAST (Dynamic Application Security Testing)
OWASP ZAP
docker run -t owasp/zap2docker-stable zap-baseline.py \
-t https://target.com \
-r report.html
docker run -t owasp/zap2docker-stable zap-api-scan.py \
-t https://target.com/openapi.json \
-f openapi \
-r report.html
docker run -t owasp/zap2docker-stable zap-full-scan.py \
-t https://target.com \
-r report.html \
-x report.xml
Burp Suite (CI)
curl -X POST "https://burp:1337/v0.1/scan" \
-H "Authorization: Bearer <token>" \
-d '{"urls":["https://target.com"],"scan_configurations":[{"name":"Crawl and Audit"}]}'
8. Post-Deploy Security Validation
Prowler (Runtime)
prowler aws -g cis_1.5
prowler aws -g serverless
prowler gcp -p <project>
prowler azure
OPA/Gatekeeper (Admission)
kubectl get constrainttemplates
kubectl get constraints
kubectl describe k8spspprivilegedcontainer deny-privileged
9. DevSecOps Toolchain Matrix
| Étape | Outils | Cloud |
|---|
| IaC Scan | Checkov, tfsec, Terrascan, cfn-nag | Multi |
| SAST | CodeQL, Semgrep, SonarQube, Snyk | Multi |
| Secret Scan | gitleaks, truffleHog, detect-secrets | Multi |
| Build | Docker BuildKit, Cosign, Syft | Multi |
| SBOM | Syft, Trivy, Dependency-Track | Multi |
| DAST | ZAP, Burp, Nikto | Multi |
| Container | Trivy, Grype, Clair, Docker Scout | Multi |
| Deploy | OPA Gatekeeper, Kyverno | K8s |
| Post-Deploy | Prowler, ScoutSuite, CloudSploit | Multi |
Ressources