Compare commits
23 Commits
0.2.0
...
3932aa56f7
| Author | SHA1 | Date | |
|---|---|---|---|
| 3932aa56f7 | |||
| 9657bd7a36 | |||
| 574e2eb9a5 | |||
| 21a8023bf1 | |||
| 328f69ea5e | |||
| c0077e3dd8 | |||
| af6ea11079 | |||
| 5a7f32541f | |||
| dd3f18bb06 | |||
| f4b18b6cf1 | |||
| a220e5de99 | |||
| a5ffafaf9e | |||
| d17752b611 | |||
| fe05c40426 | |||
| 5a0478f47d | |||
| 1cea82f5d9 | |||
| 418034f639 | |||
| 489dde812f | |||
| c2e4e614e0 | |||
| 344071193c | |||
| 03118e59d7 | |||
| 15fea78505 | |||
| 89d3a39679 |
158
.github/workflows/container-cve-scan-development.yml
vendored
Normal file
158
.github/workflows/container-cve-scan-development.yml
vendored
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
name: Container CVE Scan (development)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["development"]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
cve-scan:
|
||||||
|
name: Scan backend/frontend images for CVEs
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Docker Hub login (for Scout)
|
||||||
|
if: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }}
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Prepare Docker auth config for Scout container
|
||||||
|
if: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }}
|
||||||
|
run: |
|
||||||
|
mkdir -p "$RUNNER_TEMP/scout-docker-config"
|
||||||
|
cp "$HOME/.docker/config.json" "$RUNNER_TEMP/scout-docker-config/config.json"
|
||||||
|
chmod 600 "$RUNNER_TEMP/scout-docker-config/config.json"
|
||||||
|
|
||||||
|
- name: Build backend image (local)
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: ./backend
|
||||||
|
file: ./backend/Dockerfile
|
||||||
|
push: false
|
||||||
|
load: true
|
||||||
|
tags: nexapg-backend:dev-scan
|
||||||
|
provenance: false
|
||||||
|
sbom: false
|
||||||
|
|
||||||
|
- name: Build frontend image (local)
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: ./frontend
|
||||||
|
file: ./frontend/Dockerfile
|
||||||
|
push: false
|
||||||
|
load: true
|
||||||
|
tags: nexapg-frontend:dev-scan
|
||||||
|
build-args: |
|
||||||
|
VITE_API_URL=/api/v1
|
||||||
|
provenance: false
|
||||||
|
sbom: false
|
||||||
|
|
||||||
|
- name: Trivy scan (backend)
|
||||||
|
uses: aquasecurity/trivy-action@0.24.0
|
||||||
|
with:
|
||||||
|
image-ref: nexapg-backend:dev-scan
|
||||||
|
format: json
|
||||||
|
output: trivy-backend.json
|
||||||
|
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
|
||||||
|
ignore-unfixed: false
|
||||||
|
exit-code: 0
|
||||||
|
|
||||||
|
- name: Trivy scan (frontend)
|
||||||
|
uses: aquasecurity/trivy-action@0.24.0
|
||||||
|
with:
|
||||||
|
image-ref: nexapg-frontend:dev-scan
|
||||||
|
format: json
|
||||||
|
output: trivy-frontend.json
|
||||||
|
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
|
||||||
|
ignore-unfixed: false
|
||||||
|
exit-code: 0
|
||||||
|
|
||||||
|
- name: Summarize Trivy severities
|
||||||
|
run: |
|
||||||
|
python - <<'PY'
|
||||||
|
import json
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
def summarize(path):
|
||||||
|
c = Counter()
|
||||||
|
with open(path, "r", encoding="utf-8") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
for result in data.get("Results", []):
|
||||||
|
for v in result.get("Vulnerabilities", []) or []:
|
||||||
|
c[v.get("Severity", "UNKNOWN")] += 1
|
||||||
|
for sev in ["CRITICAL", "HIGH", "MEDIUM", "LOW", "UNKNOWN"]:
|
||||||
|
c.setdefault(sev, 0)
|
||||||
|
return c
|
||||||
|
|
||||||
|
for label, path in [("backend", "trivy-backend.json"), ("frontend", "trivy-frontend.json")]:
|
||||||
|
s = summarize(path)
|
||||||
|
print(f"===== Trivy {label} =====")
|
||||||
|
print(f"CRITICAL={s['CRITICAL']} HIGH={s['HIGH']} MEDIUM={s['MEDIUM']} LOW={s['LOW']} UNKNOWN={s['UNKNOWN']}")
|
||||||
|
print()
|
||||||
|
PY
|
||||||
|
|
||||||
|
- name: Docker Scout scan (backend)
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
if [ -z "${{ secrets.DOCKERHUB_USERNAME }}" ] || [ -z "${{ secrets.DOCKERHUB_TOKEN }}" ]; then
|
||||||
|
echo "Docker Hub Scout scan skipped: DOCKERHUB_USERNAME/DOCKERHUB_TOKEN not set." > scout-backend.txt
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
docker run --rm \
|
||||||
|
-u root \
|
||||||
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
|
-v "$RUNNER_TEMP/scout-docker-config:/root/.docker" \
|
||||||
|
-e DOCKER_CONFIG=/root/.docker \
|
||||||
|
-e DOCKER_SCOUT_HUB_USER="${{ secrets.DOCKERHUB_USERNAME }}" \
|
||||||
|
-e DOCKER_SCOUT_HUB_PASSWORD="${{ secrets.DOCKERHUB_TOKEN }}" \
|
||||||
|
docker/scout-cli:latest cves nexapg-backend:dev-scan \
|
||||||
|
--only-severity critical,high,medium,low > scout-backend.txt 2>&1 || {
|
||||||
|
echo "" >> scout-backend.txt
|
||||||
|
echo "Docker Scout backend scan failed (non-blocking)." >> scout-backend.txt
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Docker Scout scan (frontend)
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
if [ -z "${{ secrets.DOCKERHUB_USERNAME }}" ] || [ -z "${{ secrets.DOCKERHUB_TOKEN }}" ]; then
|
||||||
|
echo "Docker Hub Scout scan skipped: DOCKERHUB_USERNAME/DOCKERHUB_TOKEN not set." > scout-frontend.txt
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
docker run --rm \
|
||||||
|
-u root \
|
||||||
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
|
-v "$RUNNER_TEMP/scout-docker-config:/root/.docker" \
|
||||||
|
-e DOCKER_CONFIG=/root/.docker \
|
||||||
|
-e DOCKER_SCOUT_HUB_USER="${{ secrets.DOCKERHUB_USERNAME }}" \
|
||||||
|
-e DOCKER_SCOUT_HUB_PASSWORD="${{ secrets.DOCKERHUB_TOKEN }}" \
|
||||||
|
docker/scout-cli:latest cves nexapg-frontend:dev-scan \
|
||||||
|
--only-severity critical,high,medium,low > scout-frontend.txt 2>&1 || {
|
||||||
|
echo "" >> scout-frontend.txt
|
||||||
|
echo "Docker Scout frontend scan failed (non-blocking)." >> scout-frontend.txt
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Print scan summary
|
||||||
|
run: |
|
||||||
|
echo "===== Docker Scout backend ====="
|
||||||
|
test -f scout-backend.txt && cat scout-backend.txt || echo "scout-backend.txt not available"
|
||||||
|
echo
|
||||||
|
echo "===== Docker Scout frontend ====="
|
||||||
|
test -f scout-frontend.txt && cat scout-frontend.txt || echo "scout-frontend.txt not available"
|
||||||
|
|
||||||
|
- name: Upload scan reports
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: container-cve-scan-reports
|
||||||
|
path: |
|
||||||
|
trivy-backend.json
|
||||||
|
trivy-frontend.json
|
||||||
|
scout-backend.txt
|
||||||
|
scout-frontend.txt
|
||||||
50
.github/workflows/docker-release.yml
vendored
50
.github/workflows/docker-release.yml
vendored
@@ -16,6 +16,8 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
attestations: write
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# Optional repo variable. If unset, DOCKERHUB_USERNAME is used.
|
# Optional repo variable. If unset, DOCKERHUB_USERNAME is used.
|
||||||
@@ -25,6 +27,20 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: "3.13"
|
||||||
|
|
||||||
|
- name: Dependency security gate (pip-audit)
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install pip-audit
|
||||||
|
pip-audit -r backend/requirements.txt --format json --aliases --output pip-audit-backend.json || true
|
||||||
|
python backend/scripts/pip_audit_gate.py \
|
||||||
|
--report pip-audit-backend.json \
|
||||||
|
--allowlist ops/security/pip-audit-allowlist.json
|
||||||
|
|
||||||
- name: Resolve version/tag
|
- name: Resolve version/tag
|
||||||
id: ver
|
id: ver
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -49,10 +65,28 @@ jobs:
|
|||||||
if [ -z "$NS" ]; then
|
if [ -z "$NS" ]; then
|
||||||
NS="${{ secrets.DOCKERHUB_USERNAME }}"
|
NS="${{ secrets.DOCKERHUB_USERNAME }}"
|
||||||
fi
|
fi
|
||||||
if [ -z "$NS" ]; then
|
|
||||||
|
# Normalize accidental input like spaces or uppercase.
|
||||||
|
NS="$(echo "$NS" | tr '[:upper:]' '[:lower:]' | xargs)"
|
||||||
|
|
||||||
|
# Reject clearly invalid placeholders/config mistakes early.
|
||||||
|
if [ -z "$NS" ] || [ "$NS" = "-" ]; then
|
||||||
echo "Missing Docker Hub namespace. Set repo var DOCKERHUB_NAMESPACE or secret DOCKERHUB_USERNAME."
|
echo "Missing Docker Hub namespace. Set repo var DOCKERHUB_NAMESPACE or secret DOCKERHUB_USERNAME."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Namespace must be a single Docker Hub account/org name, not a path/url.
|
||||||
|
if [[ "$NS" == *"/"* ]] || [[ "$NS" == *":"* ]]; then
|
||||||
|
echo "Invalid Docker Hub namespace '$NS'. Use only the account/org name (e.g. 'nesterovicit')."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [[ "$NS" =~ ^[a-z0-9]+([._-][a-z0-9]+)*$ ]]; then
|
||||||
|
echo "Invalid Docker Hub namespace '$NS'. Allowed: lowercase letters, digits, ., _, -"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Using Docker Hub namespace: $NS"
|
||||||
echo "value=$NS" >> "$GITHUB_OUTPUT"
|
echo "value=$NS" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
@@ -70,6 +104,13 @@ jobs:
|
|||||||
context: ./backend
|
context: ./backend
|
||||||
file: ./backend/Dockerfile
|
file: ./backend/Dockerfile
|
||||||
push: true
|
push: true
|
||||||
|
provenance: mode=max
|
||||||
|
sbom: true
|
||||||
|
labels: |
|
||||||
|
org.opencontainers.image.title=NexaPG Backend
|
||||||
|
org.opencontainers.image.vendor=Nesterovic IT-Services e.U.
|
||||||
|
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||||
|
org.opencontainers.image.version=${{ steps.ver.outputs.clean }}
|
||||||
tags: |
|
tags: |
|
||||||
${{ steps.ns.outputs.value }}/nexapg-backend:${{ steps.ver.outputs.clean }}
|
${{ steps.ns.outputs.value }}/nexapg-backend:${{ steps.ver.outputs.clean }}
|
||||||
${{ steps.ns.outputs.value }}/nexapg-backend:latest
|
${{ steps.ns.outputs.value }}/nexapg-backend:latest
|
||||||
@@ -82,8 +123,15 @@ jobs:
|
|||||||
context: ./frontend
|
context: ./frontend
|
||||||
file: ./frontend/Dockerfile
|
file: ./frontend/Dockerfile
|
||||||
push: true
|
push: true
|
||||||
|
provenance: mode=max
|
||||||
|
sbom: true
|
||||||
build-args: |
|
build-args: |
|
||||||
VITE_API_URL=/api/v1
|
VITE_API_URL=/api/v1
|
||||||
|
labels: |
|
||||||
|
org.opencontainers.image.title=NexaPG Frontend
|
||||||
|
org.opencontainers.image.vendor=Nesterovic IT-Services e.U.
|
||||||
|
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||||
|
org.opencontainers.image.version=${{ steps.ver.outputs.clean }}
|
||||||
tags: |
|
tags: |
|
||||||
${{ steps.ns.outputs.value }}/nexapg-frontend:${{ steps.ver.outputs.clean }}
|
${{ steps.ns.outputs.value }}/nexapg-frontend:${{ steps.ver.outputs.clean }}
|
||||||
${{ steps.ns.outputs.value }}/nexapg-frontend:latest
|
${{ steps.ns.outputs.value }}/nexapg-frontend:latest
|
||||||
|
|||||||
5
.github/workflows/pg-compat-matrix.yml
vendored
5
.github/workflows/pg-compat-matrix.yml
vendored
@@ -2,7 +2,7 @@ name: PostgreSQL Compatibility Matrix
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["main", "master"]
|
branches: ["main", "master", "development"]
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -11,6 +11,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
max-parallel: 3
|
||||||
matrix:
|
matrix:
|
||||||
pg_version: ["14", "15", "16", "17", "18"]
|
pg_version: ["14", "15", "16", "17", "18"]
|
||||||
|
|
||||||
@@ -32,6 +33,8 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
|
|||||||
53
.github/workflows/python-dependency-security.yml
vendored
Normal file
53
.github/workflows/python-dependency-security.yml
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
name: Python Dependency Security
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["main", "master", "development"]
|
||||||
|
paths:
|
||||||
|
- "backend/**"
|
||||||
|
- ".github/workflows/python-dependency-security.yml"
|
||||||
|
- "ops/security/pip-audit-allowlist.json"
|
||||||
|
- "docs/security/dependency-exceptions.md"
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- "backend/**"
|
||||||
|
- ".github/workflows/python-dependency-security.yml"
|
||||||
|
- "ops/security/pip-audit-allowlist.json"
|
||||||
|
- "docs/security/dependency-exceptions.md"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pip-audit:
|
||||||
|
name: pip-audit (block high/critical)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: "3.13"
|
||||||
|
|
||||||
|
- name: Install pip-audit
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install pip-audit
|
||||||
|
|
||||||
|
- name: Run pip-audit (JSON report)
|
||||||
|
run: |
|
||||||
|
pip-audit -r backend/requirements.txt --format json --aliases --output pip-audit-backend.json || true
|
||||||
|
|
||||||
|
- name: Enforce vulnerability policy
|
||||||
|
run: |
|
||||||
|
python backend/scripts/pip_audit_gate.py \
|
||||||
|
--report pip-audit-backend.json \
|
||||||
|
--allowlist ops/security/pip-audit-allowlist.json
|
||||||
|
|
||||||
|
- name: Upload pip-audit report
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: pip-audit-security-report
|
||||||
|
path: pip-audit-backend.json
|
||||||
13
README.md
13
README.md
@@ -21,6 +21,7 @@ It combines FastAPI, React, and PostgreSQL in a Docker Compose stack with RBAC,
|
|||||||
- [`pg_stat_statements` Requirement](#pg_stat_statements-requirement)
|
- [`pg_stat_statements` Requirement](#pg_stat_statements-requirement)
|
||||||
- [Reverse Proxy / SSL Guidance](#reverse-proxy--ssl-guidance)
|
- [Reverse Proxy / SSL Guidance](#reverse-proxy--ssl-guidance)
|
||||||
- [PostgreSQL Compatibility Smoke Test](#postgresql-compatibility-smoke-test)
|
- [PostgreSQL Compatibility Smoke Test](#postgresql-compatibility-smoke-test)
|
||||||
|
- [Dependency Exception Flow](#dependency-exception-flow)
|
||||||
- [Troubleshooting](#troubleshooting)
|
- [Troubleshooting](#troubleshooting)
|
||||||
- [Security Notes](#security-notes)
|
- [Security Notes](#security-notes)
|
||||||
|
|
||||||
@@ -206,7 +207,7 @@ Note: Migrations run automatically when the backend container starts (`entrypoin
|
|||||||
|
|
||||||
| Variable | Description |
|
| Variable | Description |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `FRONTEND_PORT` | Host port mapped to frontend container port `80` |
|
| `FRONTEND_PORT` | Host port mapped to frontend container port `8080` |
|
||||||
|
|
||||||
## Core Functional Areas
|
## Core Functional Areas
|
||||||
|
|
||||||
@@ -387,6 +388,16 @@ PG_DSN_CANDIDATES='postgresql://postgres:postgres@postgres:5432/compatdb?sslmode
|
|||||||
python backend/scripts/pg_compat_smoke.py
|
python backend/scripts/pg_compat_smoke.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Dependency Exception Flow
|
||||||
|
|
||||||
|
Python dependency vulnerabilities are enforced by CI via `pip-audit`.
|
||||||
|
|
||||||
|
- CI blocks unresolved `HIGH` and `CRITICAL` findings.
|
||||||
|
- Missing severity metadata is treated conservatively as `HIGH`.
|
||||||
|
- Temporary exceptions must be declared in `ops/security/pip-audit-allowlist.json`.
|
||||||
|
- Full process and required metadata are documented in:
|
||||||
|
- `docs/security/dependency-exceptions.md`
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
### Backend container keeps restarting during `make migrate`
|
### Backend container keeps restarting during `make migrate`
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
FROM python:3.13-slim AS base
|
ARG PYTHON_BASE_IMAGE=python:3.13-alpine
|
||||||
|
FROM ${PYTHON_BASE_IMAGE} AS base
|
||||||
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
@@ -6,11 +7,17 @@ ENV PIP_NO_CACHE_DIR=1
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apt-get update \
|
RUN if command -v apt-get >/dev/null 2>&1; then \
|
||||||
&& apt-get upgrade -y \
|
apt-get update && apt-get upgrade -y && rm -rf /var/lib/apt/lists/*; \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
elif command -v apk >/dev/null 2>&1; then \
|
||||||
|
apk upgrade --no-cache; \
|
||||||
|
fi
|
||||||
|
|
||||||
RUN addgroup --system app && adduser --system --ingroup app app
|
RUN if addgroup --help 2>&1 | grep -q -- '--system'; then \
|
||||||
|
addgroup --system app && adduser --system --ingroup app app; \
|
||||||
|
else \
|
||||||
|
addgroup -S app && adduser -S -G app app; \
|
||||||
|
fi
|
||||||
|
|
||||||
COPY requirements.txt /app/requirements.txt
|
COPY requirements.txt /app/requirements.txt
|
||||||
RUN pip install --upgrade pip && pip install -r /app/requirements.txt
|
RUN pip install --upgrade pip && pip install -r /app/requirements.txt
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from functools import lru_cache
|
|||||||
from pydantic import field_validator
|
from pydantic import field_validator
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
NEXAPG_VERSION = "0.2.0"
|
NEXAPG_VERSION = "0.2.2"
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
|
|||||||
192
backend/scripts/pip_audit_gate.py
Normal file
192
backend/scripts/pip_audit_gate.py
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Gate pip-audit results with an auditable allowlist policy.
|
||||||
|
|
||||||
|
Policy:
|
||||||
|
- Block unresolved HIGH/CRITICAL vulnerabilities.
|
||||||
|
- If severity is missing, treat as HIGH by default.
|
||||||
|
- Allow temporary exceptions via allowlist with expiry metadata.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import datetime as dt
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
SEVERITY_ORDER = {"unknown": 0, "low": 1, "medium": 2, "high": 3, "critical": 4}
|
||||||
|
BLOCKING_SEVERITIES = {"high", "critical"}
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_date(s: str) -> dt.date:
|
||||||
|
return dt.date.fromisoformat(s)
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_severity(value: object) -> str:
|
||||||
|
"""Normalize various pip-audit/osv-style severity payloads."""
|
||||||
|
if isinstance(value, str):
|
||||||
|
v = value.strip().lower()
|
||||||
|
if v in SEVERITY_ORDER:
|
||||||
|
return v
|
||||||
|
try:
|
||||||
|
# CVSS numeric string fallback
|
||||||
|
score = float(v)
|
||||||
|
if score >= 9.0:
|
||||||
|
return "critical"
|
||||||
|
if score >= 7.0:
|
||||||
|
return "high"
|
||||||
|
if score >= 4.0:
|
||||||
|
return "medium"
|
||||||
|
return "low"
|
||||||
|
except ValueError:
|
||||||
|
return "unknown"
|
||||||
|
|
||||||
|
if isinstance(value, (int, float)):
|
||||||
|
score = float(value)
|
||||||
|
if score >= 9.0:
|
||||||
|
return "critical"
|
||||||
|
if score >= 7.0:
|
||||||
|
return "high"
|
||||||
|
if score >= 4.0:
|
||||||
|
return "medium"
|
||||||
|
return "low"
|
||||||
|
|
||||||
|
if isinstance(value, list):
|
||||||
|
# OSV sometimes returns a list of dicts. Pick the max-known severity.
|
||||||
|
best = "unknown"
|
||||||
|
for item in value:
|
||||||
|
if isinstance(item, dict):
|
||||||
|
sev = _normalize_severity(item.get("severity"))
|
||||||
|
if SEVERITY_ORDER.get(sev, 0) > SEVERITY_ORDER.get(best, 0):
|
||||||
|
best = sev
|
||||||
|
return best
|
||||||
|
|
||||||
|
if isinstance(value, dict):
|
||||||
|
return _normalize_severity(value.get("severity"))
|
||||||
|
|
||||||
|
return "unknown"
|
||||||
|
|
||||||
|
|
||||||
|
def _load_allowlist(path: Path) -> tuple[list[dict], list[str]]:
|
||||||
|
if not path.exists():
|
||||||
|
return [], []
|
||||||
|
|
||||||
|
data = json.loads(path.read_text(encoding="utf-8"))
|
||||||
|
entries = data.get("entries", [])
|
||||||
|
today = dt.date.today()
|
||||||
|
active: list[dict] = []
|
||||||
|
errors: list[str] = []
|
||||||
|
|
||||||
|
required = {"id", "reason", "approved_by", "issue", "expires_on"}
|
||||||
|
for idx, entry in enumerate(entries, start=1):
|
||||||
|
missing = required - set(entry.keys())
|
||||||
|
if missing:
|
||||||
|
errors.append(f"allowlist entry #{idx} missing keys: {', '.join(sorted(missing))}")
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
expires = _parse_date(str(entry["expires_on"]))
|
||||||
|
except ValueError:
|
||||||
|
errors.append(f"allowlist entry #{idx} has invalid expires_on: {entry['expires_on']}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if expires < today:
|
||||||
|
errors.append(
|
||||||
|
f"allowlist entry #{idx} ({entry['id']}) expired on {entry['expires_on']}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
|
active.append(entry)
|
||||||
|
|
||||||
|
return active, errors
|
||||||
|
|
||||||
|
|
||||||
|
def _iter_findings(report: object):
|
||||||
|
# pip-audit JSON can be list[dep] or dict with dependencies.
|
||||||
|
deps = report if isinstance(report, list) else report.get("dependencies", [])
|
||||||
|
for dep in deps:
|
||||||
|
package = dep.get("name", "unknown")
|
||||||
|
version = dep.get("version", "unknown")
|
||||||
|
for vuln in dep.get("vulns", []):
|
||||||
|
vuln_id = vuln.get("id", "unknown")
|
||||||
|
aliases = vuln.get("aliases", []) or []
|
||||||
|
severity = _normalize_severity(vuln.get("severity"))
|
||||||
|
if severity == "unknown":
|
||||||
|
severity = "high" # conservative default for policy safety
|
||||||
|
yield {
|
||||||
|
"package": package,
|
||||||
|
"version": version,
|
||||||
|
"id": vuln_id,
|
||||||
|
"aliases": aliases,
|
||||||
|
"severity": severity,
|
||||||
|
"fix_versions": vuln.get("fix_versions", []),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _is_allowlisted(finding: dict, allowlist: list[dict]) -> bool:
|
||||||
|
ids = {finding["id"], *finding["aliases"]}
|
||||||
|
pkg = finding["package"]
|
||||||
|
for entry in allowlist:
|
||||||
|
entry_pkg = entry.get("package")
|
||||||
|
if entry["id"] in ids and (not entry_pkg or entry_pkg == pkg):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--report", required=True, help="Path to pip-audit JSON report")
|
||||||
|
parser.add_argument("--allowlist", required=True, help="Path to allowlist JSON")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
report_path = Path(args.report)
|
||||||
|
allowlist_path = Path(args.allowlist)
|
||||||
|
if not report_path.exists():
|
||||||
|
print(f"[pip-audit-gate] Missing report: {report_path}")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
report = json.loads(report_path.read_text(encoding="utf-8"))
|
||||||
|
allowlist, allowlist_errors = _load_allowlist(allowlist_path)
|
||||||
|
if allowlist_errors:
|
||||||
|
print("[pip-audit-gate] Allowlist validation failed:")
|
||||||
|
for err in allowlist_errors:
|
||||||
|
print(f" - {err}")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
unresolved_blocking: list[dict] = []
|
||||||
|
summary = {"critical": 0, "high": 0, "medium": 0, "low": 0, "unknown": 0}
|
||||||
|
ignored = 0
|
||||||
|
|
||||||
|
for finding in _iter_findings(report):
|
||||||
|
sev = finding["severity"]
|
||||||
|
summary[sev] = summary.get(sev, 0) + 1
|
||||||
|
if _is_allowlisted(finding, allowlist):
|
||||||
|
ignored += 1
|
||||||
|
continue
|
||||||
|
if sev in BLOCKING_SEVERITIES:
|
||||||
|
unresolved_blocking.append(finding)
|
||||||
|
|
||||||
|
print("[pip-audit-gate] Summary:")
|
||||||
|
print(
|
||||||
|
f" CRITICAL={summary['critical']} HIGH={summary['high']} "
|
||||||
|
f"MEDIUM={summary['medium']} LOW={summary['low']} ALLOWLISTED={ignored}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if unresolved_blocking:
|
||||||
|
print("[pip-audit-gate] Blocking vulnerabilities found:")
|
||||||
|
for f in unresolved_blocking:
|
||||||
|
aliases = ", ".join(f["aliases"]) if f["aliases"] else "-"
|
||||||
|
fixes = ", ".join(f["fix_versions"]) if f["fix_versions"] else "-"
|
||||||
|
print(
|
||||||
|
f" - {f['severity'].upper()} {f['package']}=={f['version']} "
|
||||||
|
f"id={f['id']} aliases=[{aliases}] fixes=[{fixes}]"
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
print("[pip-audit-gate] No unresolved HIGH/CRITICAL vulnerabilities.")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
@@ -54,7 +54,7 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
ports:
|
ports:
|
||||||
- "${FRONTEND_PORT}:80"
|
- "${FRONTEND_PORT}:8080"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
pg_data:
|
pg_data:
|
||||||
|
|||||||
53
docs/security/dependency-exceptions.md
Normal file
53
docs/security/dependency-exceptions.md
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# Dependency Security Exception Flow (pip-audit)
|
||||||
|
|
||||||
|
This document defines the auditable exception process for Python dependency vulnerabilities.
|
||||||
|
|
||||||
|
## Policy
|
||||||
|
|
||||||
|
- CI blocks unresolved `HIGH` and `CRITICAL` dependency vulnerabilities.
|
||||||
|
- If a vulnerability does not provide severity metadata, it is treated as `HIGH` by policy.
|
||||||
|
- Temporary exceptions are allowed only through `ops/security/pip-audit-allowlist.json`.
|
||||||
|
|
||||||
|
## Allowlist Location
|
||||||
|
|
||||||
|
- File: `ops/security/pip-audit-allowlist.json`
|
||||||
|
- Format:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"entries": [
|
||||||
|
{
|
||||||
|
"id": "CVE-2026-12345",
|
||||||
|
"package": "example-package",
|
||||||
|
"reason": "Upstream fix not released yet",
|
||||||
|
"approved_by": "security-owner",
|
||||||
|
"issue": "NX-202",
|
||||||
|
"expires_on": "2026-12-31"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Required Fields
|
||||||
|
|
||||||
|
- `id`: Vulnerability ID (`CVE-*`, `GHSA-*`, or advisory ID)
|
||||||
|
- `reason`: Why exception is necessary
|
||||||
|
- `approved_by`: Approver identity
|
||||||
|
- `issue`: Tracking issue/ticket
|
||||||
|
- `expires_on`: Expiry date in `YYYY-MM-DD`
|
||||||
|
|
||||||
|
Optional:
|
||||||
|
|
||||||
|
- `package`: Restrict exception to one dependency package
|
||||||
|
|
||||||
|
## Rules
|
||||||
|
|
||||||
|
- Expired allowlist entries fail CI.
|
||||||
|
- Missing required fields fail CI.
|
||||||
|
- Exceptions must be time-limited and linked to a tracking issue.
|
||||||
|
- Removing an exception is required once an upstream fix is available.
|
||||||
|
|
||||||
|
## Auditability
|
||||||
|
|
||||||
|
- Every exception change is tracked in Git history and code review.
|
||||||
|
- CI logs include blocked vulnerabilities and allowlisted findings counts.
|
||||||
@@ -7,9 +7,12 @@ ARG VITE_API_URL=/api/v1
|
|||||||
ENV VITE_API_URL=${VITE_API_URL}
|
ENV VITE_API_URL=${VITE_API_URL}
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
FROM nginx:1.29-alpine-slim
|
FROM nginx:1-alpine-slim
|
||||||
RUN apk upgrade --no-cache
|
RUN apk upgrade --no-cache \
|
||||||
|
&& mkdir -p /var/cache/nginx /var/run /var/log/nginx /tmp/nginx \
|
||||||
|
&& chown -R nginx:nginx /var/cache/nginx /var/run /var/log/nginx /tmp/nginx
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
COPY --from=build /app/dist /usr/share/nginx/html
|
COPY --from=build /app/dist /usr/share/nginx/html
|
||||||
EXPOSE 80
|
USER 101
|
||||||
|
EXPOSE 8080
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --retries=5 CMD nginx -t || exit 1
|
HEALTHCHECK --interval=30s --timeout=3s --retries=5 CMD nginx -t || exit 1
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 8080;
|
||||||
server_name _;
|
server_name _;
|
||||||
|
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
|
|||||||
3
ops/security/pip-audit-allowlist.json
Normal file
3
ops/security/pip-audit-allowlist.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"entries": []
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user