Skip to content

Commit 8c1571b

Browse files
committed
fix: remove pip from Lambda GPU runtime images to eliminate bundled CVEs
Install awslambdaric via uv instead of inheriting it from the Lambda base image. Copy only Python binary/stdlib/lib from lambda-python stage, drop site-packages entirely, and install all deps (including awslambdaric==3.1.1 and pip==25.3) via uv so we own the full dependency tree. Remove pip after OSS compliance step runs. This eliminates the three pip-bundled CVEs that could not be patched via requirements pinning: - CVE-2024-6345 (setuptools RCE via pip/_vendor/pkg_resources) - CVE-2025-47273 (setuptools path traversal via pip/_vendor/pkg_resources) - CVE-2026-21441 (urllib3 decompression bomb via pip/_vendor/urllib3==1.26.20) Allowlist reduced from 14 to 11 entries. Signed-off-by: Junpu Fan <junpu@amazon.com>
1 parent 0c1933f commit 8c1571b

File tree

5 files changed

+37
-28
lines changed

5 files changed

+37
-28
lines changed

docker/lambda/Dockerfile

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# ============================================================
22
# Lambda Python sources
3-
# These images include the Lambda Runtime Interface Client (RIC)
4-
# pre-installed in /var/lang, so no explicit awslambdaric install
5-
# is needed in downstream runtime stages.
3+
# We take only the Python binary, stdlib, and lib-dynload.
4+
# Site-packages are intentionally excluded — all dependencies
5+
# (including awslambdaric) are installed via uv so we own the
6+
# full dependency tree with no Lambda-bundled extras.
67
# ============================================================
78
FROM public.ecr.aws/lambda/python:3.13 as lambda-python
89

@@ -58,19 +59,25 @@ RUN dnf install -y --setopt=install_weak_deps=False \
5859
&& cd /tmp && rm -rf ffmpeg-6.1
5960

6061
# ============================================================
61-
# Base builder (Python 3.13 — requests, pip-licenses for OSS compliance)
62+
# Base builder (Python 3.13 — awslambdaric, requests, pip-licenses)
6263
# ============================================================
6364
FROM builder-base as builder-base-py3
64-
COPY --from=lambda-python /var/lang /var/lang
65+
COPY --from=lambda-python /var/lang/bin /var/lang/bin
66+
COPY --from=lambda-python /var/lang/include /var/lang/include
67+
COPY --from=lambda-python /var/lang/lib /var/lang/lib
68+
RUN rm -rf /var/lang/lib/python3.13/site-packages
6569
ENV PATH="/var/lang/bin:$PATH"
6670
COPY ./docker/lambda/requirements-base.txt /tmp/requirements.txt
6771
RUN --mount=type=cache,target=/root/.cache/uv uv pip install --python /var/lang/bin/python3.13 -r /tmp/requirements.txt
6872

6973
# ============================================================
70-
# CuPy builder (Python 3.13 — CuPy, NumPy, SciPy, etc.)
74+
# CuPy builder (Python 3.13 — awslambdaric, CuPy, NumPy, SciPy, etc.)
7175
# ============================================================
7276
FROM builder-base as builder-cupy-py3
73-
COPY --from=lambda-python /var/lang /var/lang
77+
COPY --from=lambda-python /var/lang/bin /var/lang/bin
78+
COPY --from=lambda-python /var/lang/include /var/lang/include
79+
COPY --from=lambda-python /var/lang/lib /var/lang/lib
80+
RUN rm -rf /var/lang/lib/python3.13/site-packages
7481
ENV PATH="/var/lang/bin:$PATH"
7582
COPY ./docker/lambda/requirements-cupy.txt /tmp/requirements.txt
7683
RUN --mount=type=cache,target=/root/.cache/uv \
@@ -81,10 +88,13 @@ RUN --mount=type=cache,target=/root/.cache/uv \
8188
&& find /var/lang -type f -name "*.pyo" -delete
8289

8390
# ============================================================
84-
# PyTorch builder (Python 3.13 — PyTorch, SAM2, transformers)
91+
# PyTorch builder (Python 3.13 — awslambdaric, PyTorch, SAM2, transformers)
8592
# ============================================================
8693
FROM builder-base-devel as builder-pytorch-py3
87-
COPY --from=lambda-python /var/lang /var/lang
94+
COPY --from=lambda-python /var/lang/bin /var/lang/bin
95+
COPY --from=lambda-python /var/lang/include /var/lang/include
96+
COPY --from=lambda-python /var/lang/lib /var/lang/lib
97+
RUN rm -rf /var/lang/lib/python3.13/site-packages
8898
ENV PATH="/var/lang/bin:$PATH"
8999
COPY ./docker/lambda/requirements-pytorch.txt /tmp/requirements.txt
90100
RUN --mount=type=cache,target=/root/.cache/uv \
@@ -133,14 +143,15 @@ RUN chmod +x /usr/local/bin/deep_learning_container.py \
133143
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/etc/bashrc \
134144
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/root/.bashrc \
135145
&& bash /tmp/setup_oss_compliance.sh python3 \
136-
&& rm /tmp/setup_oss_compliance.sh
146+
&& rm /tmp/setup_oss_compliance.sh \
147+
&& rm -rf /var/lang/lib/python3.13/site-packages/pip \
148+
/var/lang/lib/python3.13/site-packages/pip-25.3.dist-info
137149
WORKDIR /var/task
138150
ENTRYPOINT ["/lambda_entrypoint.sh", "python", "-m", "awslambdaric"]
139151
CMD ["handler.handler"]
140152

141153
# ============================================================
142154
# Runtime: CuPy Python 3.13 (base + CuPy, NumPy, SciPy)
143-
# /var/lang from builder includes both Lambda RIC and our deps.
144155
# ============================================================
145156
FROM nvidia/cuda:12.8.1-runtime-amzn2023 as cupy-py3
146157
LABEL maintainer="Amazon AI"
@@ -177,7 +188,9 @@ RUN chmod +x /usr/local/bin/deep_learning_container.py \
177188
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/etc/bashrc \
178189
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/root/.bashrc \
179190
&& bash /tmp/setup_oss_compliance.sh python3 \
180-
&& rm /tmp/setup_oss_compliance.sh
191+
&& rm /tmp/setup_oss_compliance.sh \
192+
&& rm -rf /var/lang/lib/python3.13/site-packages/pip \
193+
/var/lang/lib/python3.13/site-packages/pip-25.3.dist-info
181194
WORKDIR /var/task
182195
ENTRYPOINT ["/lambda_entrypoint.sh", "python", "-m", "awslambdaric"]
183196
CMD ["handler.handler"]
@@ -225,7 +238,9 @@ RUN chmod +x /usr/local/bin/deep_learning_container.py \
225238
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/etc/bashrc \
226239
&& echo 'source /usr/local/bin/bash_telemetry.sh' >>/root/.bashrc \
227240
&& bash /tmp/setup_oss_compliance.sh python3 \
228-
&& rm /tmp/setup_oss_compliance.sh
241+
&& rm /tmp/setup_oss_compliance.sh \
242+
&& rm -rf /var/lang/lib/python3.13/site-packages/pip \
243+
/var/lang/lib/python3.13/site-packages/pip-25.3.dist-info
229244
WORKDIR /var/task
230245
ENTRYPOINT ["/lambda_entrypoint.sh", "python", "-m", "awslambdaric"]
231246
CMD ["handler.handler"]

docker/lambda/requirements-base.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
awslambdaric==3.1.1
2+
pip==25.3
13
pip-licenses==5.5.1
24
requests==2.32.5
35
setuptools==78.1.1

docker/lambda/requirements-cupy.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
awslambdaric==3.1.1
12
boto3==1.40.4
23
cupy-cuda12x==14.0.1
34
cvxpy==1.8.1
45
numba==0.64.0
56
numpy==2.4.2
67
pandas==3.0.1
8+
pip==25.3
79
pip-licenses==5.5.1
810
requests==2.32.5
911
scipy==1.17.1

docker/lambda/requirements-pytorch.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
--extra-index-url https://download.pytorch.org/whl/cu128
22
accelerate==1.12.0
33
av==16.1.0
4+
awslambdaric==3.1.1
45
boto3==1.40.4
56
diffusers==0.36.0
67
librosa==0.11.0
78
numpy==2.4.2
89
opencv-python-headless==4.13.0.92
910
pillow==12.1.1
11+
pip==25.3
1012
pip-licenses==5.5.1
1113
requests==2.32.5
1214
safetensors==0.7.0

test/security/data/ecr_scan_allowlist/lambda/framework_allowlist.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
[
2-
{
3-
"vulnerability_id": "CVE-2024-6345",
4-
"reason": "setuptools package_index RCE; pinned to setuptools==78.1.1 in requirements but ECR scan detects older copy bundled in uv or the Lambda base image's pip, which cannot be patched via requirements.",
5-
"review_by": "2026-03-24"
6-
},
2+
73
{
84
"vulnerability_id": "CVE-2025-4138",
95
"reason": "Python tarfile symlink extraction filter bypass (stdlib); cannot be patched via pip. Lambda images do not extract untrusted tar archives at runtime.",
@@ -24,11 +20,7 @@
2420
"reason": "Python tarfile arbitrary write with filter=data (stdlib); cannot be patched via pip. Lambda images do not extract untrusted tar archives at runtime.",
2521
"review_by": "2026-03-24"
2622
},
27-
{
28-
"vulnerability_id": "CVE-2025-47273",
29-
"reason": "setuptools path traversal; pinned to setuptools==78.1.1 in requirements but ECR scan detects older copy bundled in uv or the Lambda base image's pip, which cannot be patched via requirements.",
30-
"review_by": "2026-03-24"
31-
},
23+
3224
{
3325
"vulnerability_id": "CVE-2025-47912",
3426
"reason": "Go net/url insufficient validation of bracketed IPv6 hostnames; present in NVIDIA CUDA base image Go tooling, not exposed by Lambda runtime.",
@@ -44,11 +36,7 @@
4436
"reason": "Python tarfile extraction API defect (stdlib); cannot be patched via pip. Lambda images do not extract untrusted tar archives at runtime.",
4537
"review_by": "2026-03-24"
4638
},
47-
{
48-
"vulnerability_id": "CVE-2026-21441",
49-
"reason": "urllib3 decompression bomb on redirect responses; pinned to urllib3==2.6.3 in requirements files but ECR scan may still report against bundled copies in transitive deps.",
50-
"review_by": "2026-03-24"
51-
},
39+
5240
{
5341
"vulnerability_id": "CVE-2026-23949",
5442
"reason": "CVE details not yet published; present in NVIDIA CUDA base image, no fix available in AL2023 repo.",

0 commit comments

Comments
 (0)