diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 07dedfe..e6b92c5 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: "DevSecOps Enterprise Pipeline" +name: "DevSecOps Pipeline" on: push: branches: [ main ] @@ -7,40 +7,29 @@ jobs: security-gate-and-deploy: runs-on: ubuntu-latest steps: - - name: Checkout Code + - name: 0. Checkout Code uses: actions/checkout@v3 with: fetch-depth: 0 - # ========================================== - # STAGE 0: BUILD DA IMAGEM DOCKER - # ========================================== - - name: Build Docker Image - run: | - docker build -f backend/Dockerfile -t apex-solutions:latest . + - name: 1. Build Application Image + run: docker build -f backend/Dockerfile -t apex-solutions:latest . # ========================================== - # STAGE 1: STATIC SECURITY TESTING (SAST, SCA, SECRETS) + # BLOCO AGRUPADO: SAST, SCA e SECRET SCANNING # ========================================== - - # 1.1. Secret Scanning: Deteta as credenciais de email no server.js - - name: Gitleaks Scan - # O true permite que a pipeline continue mesmo após detetar a vulnerabilidade (para poderes ver o ZAP a funcionar também) - continue-on-error: true + - 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 - /tmp/gitleaks detect --source . --verbose --redact --log-opts="-1" --exit-code 1 - - # 1.2. Software Composition Analysis (SCA): Analisa a NOSSA imagem - - name: Scan Docker Image Vulnerabilities (Trivy) - run: | + # 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 - - # 1.3. Static Application Security Testing (SAST) - - name: SonarQube Analysis - continue-on-error: true - run: | + 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 \ @@ -48,81 +37,60 @@ jobs: -Dsonar.sources=. \ -Dsonar.host.url=https://sonar.each-cs.com \ -Dsonar.token=${{ secrets.SONAR_TOKEN }} \ - -Dsonar.qualitygate.wait=true + -Dsonar.qualitygate.wait=true || echo "[ALERTA] SonarQube falhou no Quality Gate." # ========================================== - # STAGE 2: DYNAMIC TEST ENVIRONMENT (SANDBOX) + # BLOCO AGRUPADO: DAST (ZAP + SANDBOX) # ========================================== - - - name: Provision Ephemeral Sandbox + - name: 3. Dynamic Security Scan (OWASP ZAP) run: | + echo ">>> Lançando Sandbox Efêmero..." docker rm -f apex-sandbox || true - # Lança a imagem que acabámos de construir e testar docker run -d --name apex-sandbox apex-solutions:latest sleep 5 - - # ========================================== - # STAGE 3: DYNAMIC APPLICATION SECURITY TESTING (DAST) - # ========================================== - - - name: OWASP ZAP Baseline Scan - run: | + + 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 - # Ataca a porta 3000 do nosso backend Node.js + # 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 + -r report.html \ + -I - docker cp zap-scanner:/zap/wrk/report.html qatests/report.html + 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 - - - name: Teardown Ephemeral Sandbox - if: always() - run: | docker rm -f apex-sandbox || true # ========================================== - # STAGE 4: PRODUCTION DEPLOYMENT + # BLOCO AGRUPADO: DEPLOY DE PRODUÇÃO # ========================================== - - - name: Hardened Production Deployment + - name: 4. Production Deployment & Local Reports run: | - # Remove o contentor de produção antigo + echo ">>> Atualizando Produção..." docker rm -f portal-corporativo || true - - # Lança o novo contentor expondo para a porta 3000 do teu servidor docker run -d -p 3000:3000 --name portal-corporativo apex-solutions:latest - - # Healthcheck para garantir que o Node.js está a responder sleep 3 curl --silent --show-error --fail http://localhost:3000 || exit 1 - - # ========================================== - # STAGE 5: ARTIFACT MANAGEMENT & REPORTING - # ========================================== - - - name: Publish ZAP Report to Production Web Server - if: always() - run: | - # Coloca o relatório ZAP na pasta pública frontend do Node.js + + echo ">>> Publicando Relatório ZAP no servidor Web..." docker cp qatests/report.html portal-corporativo:/usr/src/app/frontend/zap-report.html || true - - name: Archive ZAP Report (Raw HTML) + # ========================================== + # 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 - - - name: Pipeline Status Notification - if: always() - run: | - echo "Pipeline finished with status: ${{ job.status }}" \ No newline at end of file + path: qatests/report.html \ No newline at end of file