feat(ci): add secret scanning with gitleaks and PR metadata validation #2
|
|
@ -0,0 +1,15 @@
|
|||
## Tipo de Cambio
|
||||
- [ ] `feat`: Nueva funcionalidad
|
||||
- [ ] `fix`: Corrección de bug
|
||||
- [ ] `chore`: Tarea de mantenimiento / CI
|
||||
- [ ] `refactor`: Refactorización de código
|
||||
- [ ] `docs`: Actualización de documentación
|
||||
|
||||
## Resumen del Cambio
|
||||
<!-- Explica brevemente qué resuelve o implementa este Pull Request -->
|
||||
|
||||
## Verificaciones
|
||||
- [ ] El título sigue la convención Conventional Commits (ej. `feat(auth): mensaje`, `chore(ci): mensaje`)
|
||||
- [ ] La rama de origen sigue el estándar (`feature/*`, `chore/*`, `fix/*`, etc.)
|
||||
- [ ] No contiene secretos, tokens ni contraseñas
|
||||
- [ ] Compila exitosamente en local
|
||||
|
|
@ -25,6 +25,68 @@ jobs:
|
|||
git fetch --depth 1 origin ${{ github.sha }}
|
||||
git checkout --force FETCH_HEAD
|
||||
|
||||
- name: Validate Pull Request Metadata
|
||||
if: github.event_name == 'pull_request'
|
||||
env:
|
||||
PR_HEAD_REF: ${{ github.head_ref }}
|
||||
PR_BASE_REF: ${{ github.base_ref }}
|
||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||
PR_BODY: ${{ github.event.pull_request.body }}
|
||||
run: |
|
||||
echo "==> Validando Pull Request: '$PR_TITLE'"
|
||||
echo " Rama origen: $PR_HEAD_REF -> Rama destino: $PR_BASE_REF"
|
||||
|
||||
if [[ "$PR_BASE_REF" == "develop" ]]; then
|
||||
if ! [[ "$PR_HEAD_REF" =~ ^(feature|feat|chore|fix|bugfix|refactor|docs|test|perf)/ ]]; then
|
||||
echo "❌ Error de Rama: Pull Requests hacia 'develop' deben provenir de una rama específica (feature/*, chore/*, fix/*, refactor/*, etc.)."
|
||||
echo " Rama recibida: '$PR_HEAD_REF'"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ "$PR_BASE_REF" == "main" || "$PR_BASE_REF" == "master" ]]; then
|
||||
if ! [[ "$PR_HEAD_REF" =~ ^(release|hotfix)/ || "$PR_HEAD_REF" == "develop" ]]; then
|
||||
echo "❌ Error de Rama: Pull Requests hacia producción ('main') deben provenir de 'develop', 'release/*' o 'hotfix/*'."
|
||||
echo " Rama recibida: '$PR_HEAD_REF'"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
TITLE_REGEX="^(feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([a-zA-Z0-9_\-\./]+\))?!?: .+"
|
||||
if ! [[ "$PR_TITLE" =~ $TITLE_REGEX ]]; then
|
||||
echo "❌ Error de Título: El título del PR debe seguir Conventional Commits."
|
||||
echo " Formato: <tipo>(<ámbito opcional>): <descripción>"
|
||||
echo " Ejemplos: feat(auth): add login form, fix: resolve token refresh, chore(ci): update runner"
|
||||
echo " Título recibido: '$PR_TITLE'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CLEAN_BODY=$(echo "$PR_BODY" | tr -d '[:space:]')
|
||||
if [[ ${#CLEAN_BODY} -lt 15 ]]; then
|
||||
echo "❌ Error de Descripción: La descripción del Pull Request no puede estar vacía."
|
||||
echo " Por favor explica brevemente qué cambios incluye este PR para facilitar la revisión."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Validaciones de Pull Request aprobadas."
|
||||
|
||||
- name: Scan for Leaked Secrets & Credentials
|
||||
run: |
|
||||
ARCH=$(uname -m)
|
||||
case "$ARCH" in
|
||||
x86_64) GITLEAKS_ARCH="x64" ;;
|
||||
aarch64|arm64) GITLEAKS_ARCH="arm64" ;;
|
||||
*) GITLEAKS_ARCH="x64" ;;
|
||||
esac
|
||||
|
||||
mkdir -p /tmp/bin
|
||||
if ! command -v gitleaks &> /dev/null; then
|
||||
echo "Descargando Gitleaks para $ARCH ($GITLEAKS_ARCH)..."
|
||||
curl -sSL "https://github.com/gitleaks/gitleaks/releases/download/v8.18.4/gitleaks_8.18.4_linux_${GITLEAKS_ARCH}.tar.gz" | tar -xz -C /tmp/bin gitleaks
|
||||
export PATH="/tmp/bin:$PATH"
|
||||
fi
|
||||
|
||||
echo "Ejecutando escaneo de credenciales y secretos..."
|
||||
gitleaks detect --source . --verbose --no-git
|
||||
|
||||
- name: Install Frontend Dependencies
|
||||
run: |
|
||||
cd src/frontend
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
## Tipo de Cambio
|
||||
- [ ] `feat`: Nueva funcionalidad
|
||||
- [ ] `fix`: Corrección de bug
|
||||
- [ ] `chore`: Tarea de mantenimiento / CI
|
||||
- [ ] `refactor`: Refactorización de código
|
||||
- [ ] `docs`: Actualización de documentación
|
||||
|
||||
## Resumen del Cambio
|
||||
<!-- Explica brevemente qué resuelve o implementa este Pull Request -->
|
||||
|
||||
## Verificaciones
|
||||
- [ ] El título sigue la convención Conventional Commits (ej. `feat(auth): mensaje`, `chore(ci): mensaje`)
|
||||
- [ ] La rama de origen sigue el estándar (`feature/*`, `chore/*`, `fix/*`, etc.)
|
||||
- [ ] No contiene secretos, tokens ni contraseñas
|
||||
- [ ] Compila exitosamente en local
|
||||
|
|
@ -25,6 +25,68 @@ jobs:
|
|||
git fetch --depth 1 origin ${{ github.sha }}
|
||||
git checkout --force FETCH_HEAD
|
||||
|
||||
- name: Validate Pull Request Metadata
|
||||
if: github.event_name == 'pull_request'
|
||||
env:
|
||||
PR_HEAD_REF: ${{ github.head_ref }}
|
||||
PR_BASE_REF: ${{ github.base_ref }}
|
||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||
PR_BODY: ${{ github.event.pull_request.body }}
|
||||
run: |
|
||||
echo "==> Validando Pull Request: '$PR_TITLE'"
|
||||
echo " Rama origen: $PR_HEAD_REF -> Rama destino: $PR_BASE_REF"
|
||||
|
||||
if [[ "$PR_BASE_REF" == "develop" ]]; then
|
||||
if ! [[ "$PR_HEAD_REF" =~ ^(feature|feat|chore|fix|bugfix|refactor|docs|test|perf)/ ]]; then
|
||||
echo "❌ Error de Rama: Pull Requests hacia 'develop' deben provenir de una rama específica (feature/*, chore/*, fix/*, refactor/*, etc.)."
|
||||
echo " Rama recibida: '$PR_HEAD_REF'"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ "$PR_BASE_REF" == "main" || "$PR_BASE_REF" == "master" ]]; then
|
||||
if ! [[ "$PR_HEAD_REF" =~ ^(release|hotfix)/ || "$PR_HEAD_REF" == "develop" ]]; then
|
||||
echo "❌ Error de Rama: Pull Requests hacia producción ('main') deben provenir de 'develop', 'release/*' o 'hotfix/*'."
|
||||
echo " Rama recibida: '$PR_HEAD_REF'"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
TITLE_REGEX="^(feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([a-zA-Z0-9_\-\./]+\))?!?: .+"
|
||||
if ! [[ "$PR_TITLE" =~ $TITLE_REGEX ]]; then
|
||||
echo "❌ Error de Título: El título del PR debe seguir Conventional Commits."
|
||||
echo " Formato: <tipo>(<ámbito opcional>): <descripción>"
|
||||
echo " Ejemplos: feat(auth): add login form, fix: resolve token refresh, chore(ci): update runner"
|
||||
echo " Título recibido: '$PR_TITLE'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CLEAN_BODY=$(echo "$PR_BODY" | tr -d '[:space:]')
|
||||
if [[ ${#CLEAN_BODY} -lt 15 ]]; then
|
||||
echo "❌ Error de Descripción: La descripción del Pull Request no puede estar vacía."
|
||||
echo " Por favor explica brevemente qué cambios incluye este PR para facilitar la revisión."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Validaciones de Pull Request aprobadas."
|
||||
|
||||
- name: Scan for Leaked Secrets & Credentials
|
||||
run: |
|
||||
ARCH=$(uname -m)
|
||||
case "$ARCH" in
|
||||
x86_64) GITLEAKS_ARCH="x64" ;;
|
||||
aarch64|arm64) GITLEAKS_ARCH="arm64" ;;
|
||||
*) GITLEAKS_ARCH="x64" ;;
|
||||
esac
|
||||
|
||||
mkdir -p /tmp/bin
|
||||
if ! command -v gitleaks &> /dev/null; then
|
||||
echo "Descargando Gitleaks para $ARCH ($GITLEAKS_ARCH)..."
|
||||
curl -sSL "https://github.com/gitleaks/gitleaks/releases/download/v8.18.4/gitleaks_8.18.4_linux_${GITLEAKS_ARCH}.tar.gz" | tar -xz -C /tmp/bin gitleaks
|
||||
export PATH="/tmp/bin:$PATH"
|
||||
fi
|
||||
|
||||
echo "Ejecutando escaneo de credenciales y secretos..."
|
||||
gitleaks detect --source . --verbose --no-git
|
||||
|
||||
- name: Install Frontend Dependencies
|
||||
run: |
|
||||
cd src/frontend
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
title = "Portfolio Gitleaks Configuration"
|
||||
|
||||
[allowlist]
|
||||
description = "Exclusiones globales de documentación, dependencias compiladas y falsos positivos"
|
||||
paths = [
|
||||
'''(?i)package-lock\.json$''',
|
||||
'''(?i)\.angular/.*''',
|
||||
'''(?i)node_modules/.*''',
|
||||
'''(?i)dist/.*''',
|
||||
'''(?i)\.git/.*'''
|
||||
]
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# Gitleaks Ignore List
|
||||
# Añade aquí fingerprints (huellas) de secretos detectados que sean falsos positivos confirmados.
|
||||
# Formato: una huella o regla por línea.
|
||||
#
|
||||
# Para ignorar un falso positivo directamente en el código fuente, añade el comentario:
|
||||
# const fakeToken = "example_dummy_token"; // gitleaks:allow
|
||||
Loading…
Reference in New Issue