The DevSecOps CI/CD pipeline implements a 6-stage security-first approach:
- Lint & Test - Code quality and unit tests
- Build - Container image creation with security labels
- Security Scan - Vulnerability scanning with Trivy/Grype + SBOM generation
- Security Gate - Policy-based deployment decisions
- Publish - Artifact publishing to Nexus (conditional on gate pass)
- Record - Audit trail and notifications
- Push to main/develop: Full pipeline execution
- Pull Request: Full pipeline with PR comments
- Schedule: Daily security scans at 2 AM UTC
- Workflow Dispatch: Manual execution with bypass options
- Security Scan Only: Standalone security scanning
- Checkout code
- Setup Node.js environment
- Install dependencies
- Run ESLint/Prettier
- Execute unit tests
- Generate version number- Setup Docker Buildx
- Build with security labels:
- org.opencontainers.image.created
- org.opencontainers.image.revision
- org.opencontainers.image.version
- security.scan.required=true
- Save image artifact- Install Trivy, Grype, Syft
- Scan container for vulnerabilities
- Generate SBOM (SPDX + CycloneDX)
- Parse results and set outputs
- Upload scan artifacts- Download scan results
- Run policy evaluation
- Support bypass mechanism
- Generate gate report
- Comment on PR with results
- Block pipeline if gate fails- Only runs if security gate passes
- Push image to Nexus Docker registry
- Upload SBOM to generic repository
- Upload scan results
- Create build metadata- Generate pipeline summary
- Send notifications on failure
- Cleanup temporary artifacts- Critical: 0 allowed (fail immediately)
- High: 5 allowed maximum
- Medium: No limit (configurable)
- Low: No limit (configurable)
Emergency bypass available with:
- Manual workflow dispatch
- Bypass reason required
- Full audit trail
- Approval workflow (optional)
- Tagged with version and git SHA
- Stored in Nexus Docker registry
- Security labels attached
- Trivy JSON results
- Grype JSON results (alternative)
- Human-readable reports
- Policy gate decisions
- SPDX format (primary)
- CycloneDX format (alternative)
- Linked to container images
- Stored in Nexus generic repository
{
"build": {
"name": "devsecops-app",
"number": "123",
"version": "v20231201-abc123",
"timestamp": "2023-12-01T10:30:00Z",
"vcs": {
"revision": "abc123...",
"branch": "main",
"url": "https://github.com/user/repo"
}
},
"security": {
"gate": {
"status": "PASS",
"vulnerabilities": {
"critical": 0,
"high": 2,
"medium": 5,
"low": 10
}
}
}
}Test the pipeline locally:
# Simulate full pipeline
./scripts/simulate-ci.sh
# Test individual components
./scripts/security/integrate-gate.sh myapp:latest
# Test policy gate only
./scripts/security/policy-gate.sh -s trivy- Workflow status notifications
- PR comments with security results
- Job summaries with key metrics
- Slack notifications (optional)
- Email alerts (optional)
- Custom webhooks (configurable)
-
Security Gate Fails
- Check vulnerability counts in scan results
- Review policy thresholds in workflow
- Use bypass mechanism if emergency deployment needed
-
Nexus Push Fails
- Verify Nexus credentials in GitHub Secrets
- Check network connectivity to Nexus
- Ensure repository exists and permissions are correct
-
Scan Tools Installation Fails
- Check internet connectivity in runner
- Verify tool download URLs are accessible
- Consider using pre-built runner images
Enable debug logging:
env:
ACTIONS_STEP_DEBUG: true
ACTIONS_RUNNER_DEBUG: trueEdit workflow environment variables:
env:
GATE_MAX_CRITICAL: 0
GATE_MAX_HIGH: 3
GATE_FAIL_ON_MEDIUM: trueExtend the security-scan job:
- name: Run Custom Scanner
run: |
custom-scanner --format json --output results.json ${{ needs.build.outputs.image-tag }}Add notification steps:
- name: Send Custom Notification
if: failure()
run: |
curl -X POST -H 'Content-Type: application/json' \
-d '{"text":"Pipeline failed"}' \
${{ secrets.WEBHOOK_URL }}