3 Commits

Author SHA1 Message Date
pm 71cfbf0fe9 ci: atualiza arquitetura da pipeline para fluxos paralelos e testes unitarios
DevSecOps Enterprise Pipeline / security-gate-and-deploy (push) Failing after 47s
DevSecOps Enterprise Pipeline / security-gate-and-deploy (pull_request) Failing after 6s
2026-06-10 21:49:34 +01:00
pm 48a8061909 feat: testa fluxo DevSecOps totalmente automatico
DevSecOps Enterprise Pipeline / security-gate-and-deploy (pull_request) Failing after 1m13s
2026-06-10 21:36:44 +01:00
pm 6fc1b22f7f ci: adiciona trigger de pull request para ativar a pipeline
DevSecOps Enterprise Pipeline / security-gate-and-deploy (push) Failing after 1m16s
2026-06-10 21:24:50 +01:00
2 changed files with 57 additions and 49 deletions
+55 -48
View File
@@ -1,11 +1,10 @@
name: "DevSecOps Enterprise Pipeline" name: "DevSecOps Enterprise Pipeline"
# ========================================== # ALTERADO: Agora a pipeline reage a QUALQUER alteração em QUALQUER branch,
# PONTO 4: TRIGGERS (Push vs PR) # permitindo a automação total sem intervenção manual.
# ==========================================
on: on:
push: push:
branches: [ main ] branches: ["*"] # Escuta todas as branches
pull_request: pull_request:
branches: [ main ] branches: [ main ]
@@ -13,37 +12,54 @@ jobs:
security-gate-and-deploy: security-gate-and-deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout Code - name: 0. Checkout Code
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
# ========================================== # ==========================================
# STAGE 1: STATIC SECURITY TESTING (SAST, SCA) # ETAPA 1: VALIDACAO FUNCIONAL (TESTES UNITÁRIOS)
# Correm SEMPRE, em qualquer branch.
# ==========================================
- name: 1.1. Setup Node.js Environment
uses: actions/setup-node@v3
with:
node-version: '18'
- name: 1.2. Run Unit Tests (Jest)
run: |
echo ">>> A instalar dependências e a correr testes funcionais..."
# Ajusta para a pasta onde tens o teu package.json (ex: cd backend && npm install)
npm install
npm test
- name: 1.3. Build Application Image
run: docker build -f backend/Dockerfile -t apex-solutions:latest .
# ==========================================
# ETAPA 2: ANÁLISE ESTÁTICA RÁPIDA (SAST, SCA)
# Correm SEMPRE, a cada commit de qualquer branch secundária.
# ========================================== # ==========================================
- name: Gitleaks Scan - name: 2.1. Secret Scanning (Gitleaks)
run: | 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 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 /tmp/gitleaks detect --source . --verbose --redact --log-opts="-1" --exit-code 1
# PONTO 3: Artefactos do Trivy adicionados - name: 2.2. Software Composition Analysis (Trivy)
- name: Scan Docker Image Vulnerabilities (Trivy)
run: | run: |
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
# 1. Guarda o output para um ficheiro de texto para o Artefato trivy image --severity HIGH,CRITICAL --format table --output trivy-report.txt apex-solutions:latest
trivy image --severity HIGH,CRITICAL --format table --output trivy-report.txt nginx:alpine trivy image --severity HIGH,CRITICAL --exit-code 1 apex-solutions:latest
# 2. Corre novamente no terminal para forçar a quebra da pipeline se encontrar falhas (Exit-Code 1)
trivy image --severity HIGH,CRITICAL --exit-code 1 nginx:alpine
- name: Archive Trivy Report - name: 2.3. Archive Trivy Report
if: always() if: always()
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: trivy-sca-report name: trivy-sca-report
path: trivy-report.txt path: trivy-report.txt
- name: SonarQube Analysis - name: 2.4. Static Application Security Testing (SonarQube)
run: | run: |
curl -sL https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip -o sonar-scanner.zip 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 unzip -q sonar-scanner.zip
@@ -55,17 +71,19 @@ jobs:
-Dsonar.qualitygate.wait=true -Dsonar.qualitygate.wait=true
# ========================================== # ==========================================
# STAGE 2 & 3: DYNAMIC TESTING (ZAP) # ETAPA 3: ANÁLISE DINÂMICA (DAST - OWASP ZAP)
# CRÍTICO: O condicional 'if' garante que este bloco SÓ corre na branch 'main'
# ========================================== # ==========================================
- name: Provision Ephemeral Sandbox - name: 3.1. Provision Ephemeral Sandbox
if: github.ref == 'refs/heads/main'
run: | run: |
docker rm -f website-test-sandbox || true docker rm -f website-test-sandbox || true
docker run -d --name website-test-sandbox nginx:alpine docker run -d --name website-test-sandbox apex-solutions:latest
docker cp index.html website-test-sandbox:/usr/share/nginx/html/index.html
sleep 5 sleep 5
- name: OWASP ZAP Baseline Scan - name: 3.2. OWASP ZAP Baseline Scan
if: github.ref == 'refs/heads/main'
run: | run: |
mkdir -p qatests mkdir -p qatests
docker rm -f zap-scanner || true docker rm -f zap-scanner || true
@@ -76,7 +94,7 @@ jobs:
--link website-test-sandbox:website-test-sandbox \ --link website-test-sandbox:website-test-sandbox \
-v zap-reports:/zap/wrk/:rw \ -v zap-reports:/zap/wrk/:rw \
-t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \ -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \
-t http://website-test-sandbox \ -t http://website-test-sandbox:3000 \
-r report.html \ -r report.html \
-I -I
@@ -84,18 +102,17 @@ jobs:
docker rm -f zap-scanner || true docker rm -f zap-scanner || true
docker volume rm zap-reports || true docker volume rm zap-reports || true
- name: Teardown Ephemeral Sandbox - name: 3.3. Teardown Ephemeral Sandbox
if: always() if: always() && github.ref == 'refs/heads/main'
run: | run: |
docker rm -f website-test-sandbox || true docker rm -f website-test-sandbox || true
# ========================================== # ==========================================
# STAGE 4: PRODUCTION DEPLOYMENT (SSH) # ETAPA 4: DEPLOY SEGURO VIA SSH
# CRÍTICO: Só executa se passar em TUDO e for um push final na branch 'main'
# ========================================== # ==========================================
# PONTO 6: Deploy Seguro Condicional - name: 4.1. Hardened Production Deployment via SSH
# Só executa se for um Push (não PR) e se for na branch main
- name: Hardened Production Deployment via SSH
if: github.ref == 'refs/heads/main' && github.event_name == 'push' if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: appleboy/ssh-action@v1.0.0 uses: appleboy/ssh-action@v1.0.0
with: with:
@@ -103,38 +120,28 @@ jobs:
username: ${{ secrets.SSH_USER }} username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }} key: ${{ secrets.SSH_PRIVATE_KEY }}
script: | script: |
echo ">>> A iniciar Deploy Seguro no Servidor de Produção..." echo ">>> A iniciar o Deploy Remoto em Produção via SSH..."
# 1. Navegar para a pasta do projeto (Ajusta o caminho para o teu servidor real)
cd /opt/website-test cd /opt/website-test
# 2. Puxar as últimas alterações do repositório
git pull origin main git pull origin main
# 3. Tratamento do ficheiro .ENV dinâmico (Frente 2) # Tratamento do .env em produção usando os Secrets do Gitea
# Isto injeta os Secrets do Gitea num ficheiro .env temporário no servidor echo "PORT=3000" > .env
echo "PORT=80" > .env
echo "API_SECRET=${{ secrets.API_SECRET_PROD }}" >> .env echo "API_SECRET=${{ secrets.API_SECRET_PROD }}" >> .env
# 4. Construir e iniciar o contentor de Produção # Reconstrói a imagem e reinicia o serviço refletindo o espelho da main
docker build -t website-test-backend:latest . docker build -f backend/Dockerfile -t apex-solutions:production .
docker rm -f website-test-backend || true docker stop portal-corporativo || true
docker run -d -p 80:80 --env-file .env --name website-test-backend website-test-backend:latest docker rm portal-corporativo || true
docker run -d -p 3000:3000 --env-file .env --name portal-corporativo apex-solutions:production
echo ">>> Deploy em Produção concluído com sucesso!" echo ">>> Deploy em Produção finalizado com sucesso!"
# ========================================== # ==========================================
# STAGE 5: ARTIFACT MANAGEMENT & REPORTING # ETAPA 5: GESTÃO DE ARTEFACTOS
# ========================================== # ==========================================
- name: Archive ZAP Report (Raw HTML) - name: Archive ZAP Report (Raw HTML)
if: always() if: always() && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: owasp-zap-report name: owasp-zap-report
path: qatests/report.html path: qatests/report.html
- name: Pipeline Status Notification
if: always()
run: |
echo "Pipeline finished with status: ${{ job.status }}"
+1
View File
@@ -0,0 +1 @@
> Teste de fluxo 100% automatizado: Branch criada a partir da main atualizada.