96 lines
4.1 KiB
YAML
96 lines
4.1 KiB
YAML
name: "DevSecOps Pipeline"
|
|
on:
|
|
push:
|
|
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 .
|
|
|
|
# ==========================================
|
|
# BLOCO AGRUPADO: SAST, SCA e SECRET SCANNING
|
|
# ==========================================
|
|
- name: 2. Static Security Scans (SAST, SCA, Secrets)
|
|
run: |
|
|
echo ">>> 2.1 Iniciando Gitleaks (Secret Scanning)..."
|
|
curl -sL https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz | tar -xz -C /tmp
|
|
# Removido o log-opts="-1" para forçar um Full Scan. O || true impede que a pipeline pare aqui.
|
|
/tmp/gitleaks detect --source . --verbose --redact --exit-code 1 || echo "[ALERTA] Credenciais detetadas! Ignorado temporariamente."
|
|
|
|
echo ">>> 2.2 Iniciando Trivy (SCA)..."
|
|
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 || echo "[ALERTA] Vulnerabilidades na imagem!"
|
|
|
|
echo ">>> 2.3 Iniciando SonarQube (SAST)..."
|
|
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=apex-solutions \
|
|
-Dsonar.sources=. \
|
|
-Dsonar.host.url=https://sonar.each-cs.com \
|
|
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
|
|
-Dsonar.qualitygate.wait=true || echo "[ALERTA] SonarQube falhou no Quality Gate."
|
|
|
|
# ==========================================
|
|
# BLOCO AGRUPADO: DAST (ZAP + SANDBOX)
|
|
# ==========================================
|
|
- name: 3. Dynamic Security Scan (OWASP ZAP)
|
|
run: |
|
|
echo ">>> Lançando Sandbox Efêmero..."
|
|
docker rm -f apex-sandbox || true
|
|
docker run -d --name apex-sandbox apex-solutions:latest
|
|
sleep 5
|
|
|
|
echo ">>> Executando OWASP ZAP Baseline Scan..."
|
|
mkdir -p qatests
|
|
docker rm -f zap-scanner || true
|
|
docker volume rm zap-reports || true
|
|
docker volume create zap-reports
|
|
|
|
# A flag -I faz o ZAP ignorar os avisos (warnings) e apenas reportar no HTML
|
|
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 ">>> Destruindo Sandbox..."
|
|
docker rm -f zap-scanner || true
|
|
docker volume rm zap-reports || true
|
|
docker rm -f apex-sandbox || true
|
|
|
|
# ==========================================
|
|
# BLOCO AGRUPADO: DEPLOY DE PRODUÇÃO
|
|
# ==========================================
|
|
- name: 4. Production Deployment & Local Reports
|
|
run: |
|
|
echo ">>> Atualizando Produção..."
|
|
docker rm -f portal-corporativo || true
|
|
docker run -d -p 3000:3000 --name portal-corporativo apex-solutions:latest
|
|
sleep 3
|
|
curl --silent --show-error --fail http://localhost:3000 || exit 1
|
|
|
|
echo ">>> Publicando Relatório ZAP no servidor Web..."
|
|
docker cp qatests/report.html portal-corporativo:/usr/src/app/frontend/zap-report.html || true
|
|
|
|
# ==========================================
|
|
# ARQUIVO DE RELATÓRIOS
|
|
# ==========================================
|
|
- name: 5. Archive ZAP Report (Gitea Artifacts)
|
|
if: always()
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: owasp-zap-report
|
|
path: qatests/report.html |