Traditional security testing happens after development is complete. DevSecOps integrates security from the beginning of development.
- Early Detection: Find vulnerabilities before production
- Cost Savings: Cheaper to fix early
- Development Speed: Security doesn't slow deployment
- Compliance: Meet requirements throughout process
Never commit secrets to version control:
# ❌ Wrong
password = "my-secret-key-12345"
api_token = env("DATABASE_PASSWORD") # in code
# ✅ Right
password = os.environ.get("DB_PASSWORD")
# Set via environment variables or secret managerScan repositories for accidentally committed secrets:
# Git pre-commit hook
git secrets --scan
# CI/CD integration
truffleHog scan filesystem /- AWS Secrets Manager: AWS credentials
- HashiCorp Vault: Multi-cloud secret storage
- Azure Key Vault: Azure secrets
- GitHub Secrets: Repository secrets
Analyze source code for vulnerabilities before compilation.
SonarQube
# Analyze code
sonar-scanner \
-Dsonar.projectKey=myapp \
-Dsonar.sources=srcSnyk
# Test dependencies
snyk test
# Fix vulnerabilities
snyk fixCheckmarx
- Enterprise SAST platform
- Multi-language support
- Policy-based scanning
# GitHub Actions example
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@master
with:
args: >
-Dsonar.projectName=myapp
-Dsonar.projectKey=myapp
-Dsonar.qualitygate.wait=trueMonitor dependencies for vulnerabilities:
Dependabot (GitHub)
# .github/dependabot.yml
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 5Snyk
# Check for vulnerable dependencies
snyk test --all-projectsOWASP Dependency-Check
dependency-check.sh \
--project "MyApp" \
--scan /path/to/projectScan container images for vulnerabilities:
# Trivy
trivy image myregistry/myapp:1.0
# Grype
grype myregistry/myapp:1.0
# Aqua Security
aqua scan myregistry/myapp:1.0# ✅ Secure Dockerfile
FROM alpine:3.18
RUN apk add --no-cache ca-certificates
# Create non-root user
RUN addgroup -S appuser && adduser -S appuser -G appuser
COPY --chown=appuser:appuser app /app
WORKDIR /app
USER appuser
ENTRYPOINT ["./app"]Test running applications for vulnerabilities.
OWASP ZAP
docker run -t owasp/zap2docker-stable zap-baseline.py \
-t https://myapp.example.comBurp Suite
- Manual and automated testing
- Vulnerability scanning
- Enterprise capabilities
Regularly change credentials:
# AWS Secrets Manager - automatic rotation
aws secretsmanager rotate-secret \
--secret-id my-database-secret \
--rotation-rules AutomaticallyAfterDays=30Monitor container behavior for anomalies:
- rule: Unauthorized Process
desc: Detect unauthorized process execution
condition: >
spawned_process and container and
not (proc.name in (allowed_processes))
output: >
Unauthorized process
(user=%user.name command=%proc.cmdline)
priority: WARNINGEnforce security policies:
package kubernetes.admission
deny[msg] {
container := input_containers[_]
not container.securityContext.runAsNonRoot
msg := sprintf("Container %v must run as non-root", [container.name])
}
deny[msg] {
image := container_images[_]
contains(image, ":latest")
msg := sprintf("Image %v must not use latest tag", [image])
}- HIPAA: Healthcare data protection
- PCI-DSS: Payment card security
- SOC 2: Service organization controls
- GDPR: Data privacy (EU)
- CCPA: Data privacy (California)
# CloudTrail (AWS)
aws cloudtrail list-events
# Azure Audit Logs
az monitor activity-log list
# Kubernetes audit logs
kubectl get eventsCIS Benchmarks
- Security configurations
- Best practices
- Automated testing
# CIS Kubernetes Benchmark
kube-bench run --targets node,policies- ✓ Detect and identify
- ✓ Contain the threat
- ✓ Preserve evidence
- ✓ Remediate
- ✓ Monitor for recurrence
- ✓ Post-incident review
# Rotate compromised secret
aws secretsmanager put-secret-value \
--secret-id prod/db-password \
--secret-string "new-secure-password"
# Review secret access logs
aws secretsmanager describe-secret --secret-id prod/db-password- OWASP Top 10
- Secure coding practices
- Threat modeling
- Security tools usage
- Security is everyone's responsibility
- Regular security reviews
- Blameless incident postmortems
- Security champions program
stages:
- build:
- Compile code
- Run SAST
- Check dependencies
- test:
- Run unit tests
- Run integration tests
- security:
- Scan container image
- Runtime security check
- deploy:
- Deploy to staging
- DAST testing
- Deploy to production| Category | Tools |
|---|---|
| Secret Management | Vault, AWS Secrets, Azure Key Vault |
| SAST | SonarQube, Snyk, Checkmarx |
| Dependency Scanning | Dependabot, Snyk, OWASP Dep-Check |
| Container Scanning | Trivy, Grype, Aqua |
| DAST | OWASP ZAP, Burp Suite |
| Policy Enforcement | OPA/Gatekeeper, Kyverno |
| Compliance | CIS Benchmarks, Chef InSpec |