diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9451769..4032ef2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: # Hooks generales - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v6.0.0 hooks: - id: trailing-whitespace args: [--markdown-linebreak-ext=md] @@ -56,7 +56,9 @@ repos: hooks: - id: pytest-check name: pytest-check - entry: bash -c 'if [ -d ".venv" ]; then .venv/Scripts/python.exe -m pytest tests/ -v --tb=short -x || exit 0; else pytest tests/ -v --tb=short -x || exit 0; fi' + # entry portable: corre en Windows (sin bash) y en Linux/macOS. + # sys.exit(0) conserva el comportamiento no bloqueante del bash -c original. + entry: python -c "import subprocess, sys; subprocess.call([sys.executable, '-m', 'pytest', 'tests/', '-v', '--tb=short', '-x']); sys.exit(0)" language: system pass_filenames: false always_run: false diff --git a/.trivyignore b/.trivyignore index bfe4b95..5be1bdf 100644 --- a/.trivyignore +++ b/.trivyignore @@ -1,11 +1,6 @@ # Ignorar vulnerabilidades específicas # Formato: CVE-YYYY-XXXXX -# CVE-2025-62727: Starlette DoS via Range header merging -# Razón: FastAPI 0.115.6 aún no soporta Starlette 0.49.1+ -# TODO: Actualizar cuando FastAPI soporte Starlette 0.49.1+ -CVE-2025-62727 - # Vulnerabilidades de la imagen base Debian que no son fixeables # CVE-2025-68973: GnuPG - affected, sin fix disponible CVE-2025-68973 diff --git a/Dockerfile b/Dockerfile index 7023255..86b5591 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ -# Imagen base con Python 3.11 (Alpine es más ligera y segura) -FROM python:3.11-slim-bookworm AS builder +# Imagen base con Python 3.11 sobre Debian 13 (trixie). Debian 12 (bookworm) +# ya es oldstable y no recibe parches para la mayoría de los CVE del SO, por lo +# que `apt-get upgrade` solo no reduce el escaneo de Trivy. +FROM python:3.11-slim-trixie AS builder # uv reemplaza pip para instalar dependencias (misma herramienta que local y CI) COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ @@ -12,7 +14,8 @@ ENV PYTHONUNBUFFERED=1 \ # rutas absolutas registradas dentro de .venv sigan siendo válidas WORKDIR /app -# Actualizar paquetes del sistema para parches de seguridad +# Paquetes del sistema necesarios para compilar (solo en builder, esta capa +# se descarta y no forma parte de la imagen final) RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ && rm -rf /var/lib/apt/lists/* @@ -27,7 +30,7 @@ COPY api/ ./api/ RUN UV_PYTHON_DOWNLOADS=never uv sync --locked # Stage 2: Runtime -FROM python:3.11-slim-bookworm +FROM python:3.11-slim-trixie ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ @@ -35,6 +38,15 @@ ENV PYTHONUNBUFFERED=1 \ WORKDIR /app +# Parchar el SO de la imagen runtime, que es la capa que Trivy escanea en el +# CI. No reduce los CVE actuales (Debian ya publicó todo lo disponible), pero +# evita que la imagen acumule vulnerabilidades si se reconstruye sin tirar la +# caché de capas. +RUN apt-get update \ + && apt-get upgrade -y --no-install-recommends \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* + # Copiar el .venv construido en el builder (misma ruta absoluta) COPY --from=builder /app/.venv /app/.venv