Skip to content

Commit 2213ef7

Browse files
authored
security: comprehensively remove pip to address CVE-2025-8869 and CVE-2026-1703 (#15)
- Upgrade pip to >=26.0 in builder stage before installing dependencies - Use find commands to thoroughly remove pip and pip-*.dist-info from builder stage - Remove pip from runtime image using microdnf and find commands - Eliminates pip-24.2.dist-info/METADATA that was causing CVE detection - Addresses MEDIUM severity CVE-2025-8869 (symbolic link extraction) - Addresses LOW severity CVE-2026-1703 (path traversal information disclosure)
1 parent 9f14d51 commit 2213ef7

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

Dockerfile

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,25 @@ RUN dnf install -y --nodocs gcc libffi-devel && \
2525
dnf clean all && \
2626
rm -rf /var/cache/dnf
2727

28+
# Upgrade pip to address CVE-2025-8869 and CVE-2026-1703
2829
# hadolint ignore=DL3013
29-
RUN pip3 install --no-cache-dir "poetry>=2.0" poetry-plugin-export
30+
RUN pip3 install --no-cache-dir --upgrade pip>=26.0 && \
31+
pip3 install --no-cache-dir "poetry>=2.0" poetry-plugin-export
3032

3133
COPY poetry.lock pyproject.toml ./
3234

3335
# Export requirements and install with pip (poetry 2.x has issues with virtualenvs.create=false in UBI)
3436
RUN poetry export -f requirements.txt --only main -o requirements.txt && \
3537
pip3 install --no-cache-dir -r requirements.txt && \
36-
# Remove build tools not needed at runtime (reduces CVEs)
38+
# Remove build tools not needed at runtime (reduces CVEs including CVE-2025-8869, CVE-2026-1703)
3739
pip3 uninstall -y pip setuptools wheel poetry poetry-core poetry-plugin-export 2>/dev/null || true && \
38-
rm -rf /opt/app-root/lib*/python3.12/site-packages/pip* \
39-
/opt/app-root/lib*/python3.12/site-packages/setuptools* \
40+
find /opt/app-root/lib -type d -name "pip*" -exec rm -rf {} + 2>/dev/null || true && \
41+
find /opt/app-root/lib64 -type d -name "pip*" -exec rm -rf {} + 2>/dev/null || true && \
42+
rm -rf /opt/app-root/lib*/python3.12/site-packages/setuptools* \
4043
/opt/app-root/lib*/python3.12/site-packages/wheel* \
4144
/opt/app-root/lib*/python3.12/site-packages/poetry* \
42-
/opt/app-root/lib*/python3.12/site-packages/_distutils_hack
45+
/opt/app-root/lib*/python3.12/site-packages/_distutils_hack \
46+
/opt/app-root/bin/pip*
4347

4448
# Runtime stage - UBI10 minimal image (fewer CVEs)
4549
# hadolint ignore=DL3007
@@ -53,6 +57,15 @@ COPY --from=builder /opt/app-root/lib/python3.12/site-packages /opt/app-root/lib
5357

5458
# Copy application code
5559
USER 0
60+
61+
# Remove pip from runtime image to address CVE-2025-8869 and CVE-2026-1703
62+
# Application doesn't need pip at runtime since dependencies are pre-installed
63+
RUN microdnf remove -y python3.12-pip python3.12-pip-wheel 2>/dev/null || true && \
64+
microdnf clean all && \
65+
find /opt/app-root/lib -type d -name "pip*" -exec rm -rf {} + 2>/dev/null || true && \
66+
find /opt/app-root/lib64 -type d -name "pip*" -exec rm -rf {} + 2>/dev/null || true && \
67+
rm -rf /opt/app-root/bin/pip* 2>/dev/null || true
68+
5669
COPY kube_ops_view ./kube_ops_view
5770

5871
# Copy JavaScript build output (webpack outputs to ../kube_ops_view/static/build relative to app/)

0 commit comments

Comments
 (0)