111 lines
4.3 KiB
YAML
111 lines
4.3 KiB
YAML
name: "DevSecOps Enterprise Pipeline"
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
security-gate-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: 0. Checkout Code
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: 1. Build Application Image
|
|
run: docker build -f backend/Dockerfile -t apex-solutions:latest .
|
|
|
|
- name: 1.5. Execute Unit Tests (Business Logic)
|
|
run: |
|
|
echo ">>> Syncing dependencies and executing test suite..."
|
|
# O 'npm install' vai atualizar automaticamente o package-lock.json
|
|
# caso exista alguma divergência com o package.json
|
|
npm install
|
|
npm test
|
|
|
|
# ==========================================
|
|
# STATIC SECURITY ANALYSIS STAGES
|
|
# ==========================================
|
|
|
|
- name: 2. Secret Scanning (Gitleaks)
|
|
run: |
|
|
curl -sL https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz | tar -xz -C /tmp
|
|
/tmp/gitleaks detect --source . --verbose --redact --exit-code 1
|
|
|
|
- name: 3. Software Composition Analysis (Trivy)
|
|
run: |
|
|
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
|
|
trivy image --severity HIGH,CRITICAL apex-solutions:latest
|
|
|
|
- name: 4. Static Application Security Testing (SonarQube)
|
|
run: |
|
|
curl -sL https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip -o sonar-scanner.zip
|
|
unzip -q sonar-scanner.zip
|
|
./sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner \
|
|
-Dsonar.projectKey=website-apex \
|
|
-Dsonar.sources=. \
|
|
-Dsonar.exclusions=**/node_modules/** \
|
|
-Dsonar.host.url=https://sonar.each-cs.com \
|
|
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
|
|
-Dsonar.qualitygate.wait=true
|
|
|
|
# ==========================================
|
|
# DYNAMIC SECURITY ANALYSIS & DEPLOYMENT
|
|
# ==========================================
|
|
|
|
- name: 5. Dynamic Security Scan (OWASP ZAP)
|
|
if: github.event_name == 'push'
|
|
run: |
|
|
echo ">>> Provisioning ephemeral sandbox environment..."
|
|
docker rm -f apex-sandbox || true
|
|
docker run -d --name apex-sandbox apex-solutions:latest
|
|
sleep 5
|
|
|
|
echo ">>> Initiating OWASP ZAP Baseline Scan..."
|
|
mkdir -p qatests
|
|
docker rm -f zap-scanner || true
|
|
docker volume rm zap-reports || true
|
|
docker volume create zap-reports
|
|
|
|
docker run --user root --name zap-scanner \
|
|
--link apex-sandbox:apex-sandbox \
|
|
-v zap-reports:/zap/wrk/:rw \
|
|
-t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \
|
|
-t http://apex-sandbox:3000 \
|
|
-r report.html \
|
|
-I
|
|
|
|
docker cp zap-scanner:/zap/wrk/report.html qatests/report.html || true
|
|
|
|
echo ">>> Decommissioning ephemeral sandbox..."
|
|
docker rm -f zap-scanner || true
|
|
docker volume rm zap-reports || true
|
|
docker rm -f apex-sandbox || true
|
|
|
|
- name: 6. Production Deployment & Local Reports
|
|
if: github.event_name == 'push'
|
|
run: |
|
|
echo ">>> Deploying application to production environment..."
|
|
docker rm -f portal-corporativo || true
|
|
docker run -d -p 3000:3000 --name portal-corporativo apex-solutions:latest
|
|
|
|
echo ">>> Awaiting Node.js service initialization..."
|
|
sleep 5
|
|
|
|
echo ">>> Container logs (for diagnostic purposes):"
|
|
docker logs portal-corporativo
|
|
|
|
echo ">>> Performing internal health check (via wget)..."
|
|
docker exec portal-corporativo wget --spider -S http://localhost:3000
|
|
|
|
echo ">>> Publishing OWASP ZAP security report to web server..."
|
|
docker cp qatests/report.html portal-corporativo:/usr/src/app/frontend/zap-report.html || true
|
|
|
|
- name: 7. Archive ZAP Report (Gitea Artifacts)
|
|
if: always() && github.event_name == 'push'
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: owasp-zap-report
|
|
path: qatests/report.html |