Files
website-test/.gitea/workflows/deploy.yaml
T
pm 5a061a13fc
DevSecOps Enterprise Pipeline / security-gate-and-deploy (push) Failing after 1m33s
Modificar .gitea/workflows/deploy.yaml
atualizar porta sandbox
2026-05-08 15:38:20 +00:00

115 lines
4.6 KiB
YAML

name: "DevSecOps Enterprise Pipeline"
on:
push:
branches: [ main ]
jobs:
security-gate-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
# ==========================================
# ETAPA 1: TESTES ESTÁTICOS DE SEGURANÇA
# ==========================================
# 1.1. SECRET SCANNING (Protege contra novas fugas de chaves)
- name: Gitleaks Scan
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 protect --source . --verbose --redact --staged --exit-code 1
# 1.2. SCA - Verifica vulnerabilidades conhecidas no Nginx
- name: Scan Docker Image Vulnerabilities (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 nginx:alpine
# 1.3. SAST - Análise de Código Fonte
- name: SonarQube Analysis
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-test \
-Dsonar.sources=. \
-Dsonar.host.url=http://51.89.40.2:9000 \
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
-Dsonar.qualitygate.wait=true
# ==========================================
# ETAPA 2: SANDBOX (AMBIENTE DE TESTE DINÂMICO)
# ==========================================
- name: Criar Sandbox Temporária
run: |
# Remover qualquer resíduo de sandbox anterior
docker rm -f website-test-sandbox || true
# Levantar a Sandbox na porta temporária 8282
docker run -d --name website-test-sandbox -p 8282:80 nginx:alpine
# Copiar o index.html atual para a Sandbox para poder ser testado
docker cp index.html website-test-sandbox:/usr/share/nginx/html/index.html
# Aguardar 5 segundos para o servidor Nginx iniciar
sleep 5
# ==========================================
# ETAPA 3: DAST - TESTE DINÂMICO (OWASP ZAP)
# ==========================================
# Ataca a Sandbox (8282) e não a produção. Se encontrar falhas graves, a pipeline para aqui.
- name: OWASP ZAP Baseline Scan
run: |
mkdir -p qatests
chmod 777 qatests
docker run --user root -v $(pwd)/qatests:/zap/wrk/:rw -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \
-t http://51.89.40.2:8282 \
-r report.html
# Garante que a Sandbox é desmantelada mesmo que o passo do ZAP falhe
- name: Destruir Sandbox
if: always()
run: |
docker rm -f website-test-sandbox || true
# ==========================================
# ETAPA 4: DEPLOY EM PRODUÇÃO (SÓ SE TUDO PASSAR)
# ==========================================
- name: Hardened Deploy (Produção - Porta 3000)
run: |
# Backup do ficheiro anterior em Produção
docker exec website-test-backend tar -czf /tmp/index_backup.tar.gz -C /usr/share/nginx/html index.html || true
# Limpar a pasta de produção e copiar o novo código aprovado
docker exec website-test-backend sh -c "rm -rf /usr/share/nginx/html/*"
docker cp index.html website-test-backend:/usr/share/nginx/html/index.html
# Aplicar Hardening de permissões
docker exec website-test-backend chown root:root /usr/share/nginx/html/index.html
docker exec website-test-backend chmod 444 /usr/share/nginx/html/index.html
# Testar se o site responde localmente em produção
docker exec website-test-backend curl --silent --show-error --fail http://localhost:80 || exit 1
# ==========================================
# ETAPA 5: ARTEFACTOS E NOTIFICAÇÕES
# ==========================================
# Guarda o relatório interativo gerado pelo OWASP ZAP para poderes descarregar no Gitea
- name: Guardar Relatorio ZAP
if: always()
uses: actions/upload-artifact@v3
with:
name: owasp-zap-report
path: qatests/report.html
- name: Slack/Discord Notification
if: always()
run: |
echo "Pipeline finalizada com status: ${{ job.status }}"