A Grype scan of the backend image reported 1576 findings, 16 critical. Most came from build headers nothing uses: every requirement ships a wheel (xmlsec and lxml bundle their own libxml2 2.14), so libxml2-dev, libxmlsec1-dev, libsasl2-dev, libldap2-dev, libssl-dev and pkg-config only pulled in linux-libc-dev (1161 findings), libunbound8 and Debian's libxml2. The rest were Debian fixes the python:3.11-slim base had not picked up yet (perl, libc6, gzip, pcre2, sqlite, libevent) and old pip / setuptools / wheel. The image now runs apt-get upgrade, upgrades pip, setuptools and wheel, and installs requirements with --only-binary=:all:, so a requirement without a wheel fails the build instead of needing a compiler. Rebuilt image: 187 findings, none critical, no High with a fix available; the remaining fixable ones are Python 3.11 CVEs fixed only in 3.13+. App import, SAML/xmlsec and the test suite run inside the image.
57 lines
1.7 KiB
Docker
57 lines
1.7 KiB
Docker
# VulnManager Dockerfile
|
|
FROM python:3.11-slim
|
|
|
|
# Security: Run as non-root user
|
|
RUN useradd -m -u 1000 vulnmanager
|
|
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies.
|
|
# - postgresql-client: pg_isready in the entrypoint
|
|
# - dos2unix: entrypoint line-endings
|
|
# No -dev packages: every requirement ships a wheel (xmlsec and lxml bundle
|
|
# their own libxml2), and the headers only added CVE findings to the image
|
|
# (linux-libc-dev, libunbound, libxml2). upgrade: the base image lags behind
|
|
# Debian security updates.
|
|
RUN apt-get update && apt-get upgrade -y \
|
|
&& apt-get install -y --no-install-recommends \
|
|
postgresql-client \
|
|
dos2unix \
|
|
ca-certificates \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy requirements and install Python dependencies. --only-binary: a
|
|
# requirement without a wheel fails the build instead of needing a compiler.
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
|
|
&& pip install --no-cache-dir --only-binary=:all: -r requirements.txt
|
|
|
|
# Copy application code (and entrypoint)
|
|
COPY . .
|
|
|
|
# Set permissions for entrypoint
|
|
RUN dos2unix /app/entrypoint.sh
|
|
RUN chmod +x /app/entrypoint.sh
|
|
RUN chown -R vulnmanager:vulnmanager /app
|
|
|
|
# Switch to non-root user
|
|
USER vulnmanager
|
|
|
|
# Env vars defaults
|
|
ENV POSTGRES_HOST=postgres
|
|
ENV POSTGRES_USER=vulnmanager
|
|
ENV POSTGRES_DB=vulnmanager
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
|
|
|
|
# Entrypoint
|
|
ENTRYPOINT ["/app/entrypoint.sh"]
|
|
|
|
# Start application
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|