Skip to content

Commit ddaad47

Browse files
authored
chore: ensure docker file runs as non root user (#32976)
### Reason for this change Fix Code Scanner issue ``` By not specifying a USER, a program in the container may run as 'root'. This is a security hazard. If an attacker can control a process running as root, they may have control over the container. Ensure that the last USER in a Dockerfile is a USER other than 'root'. ``` ### Description of changes Create a new group and attach the user to the group. The dockerfile already gives necessary permissions with statements like `chmod 777` ### Description of how you validated changes N/A ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b049fa8 commit ddaad47

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

packages/@aws-cdk/aws-lambda-go-alpha/lib/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ ENV GOPROXY=direct
1212
RUN mkdir $GOPATH && \
1313
chmod -R 777 $GOPATH
1414

15+
# Switch to a non-root user
16+
USER nobody
17+
1518
CMD [ "go" ]

packages/@aws-cdk/aws-lambda-python-alpha/lib/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ RUN \
3636
# Ensure no temporary files remain in the caches
3737
rm -rf /tmp/pip-cache/* /tmp/poetry-cache/*
3838

39+
# Switch to a non-root user
40+
USER nobody
41+
3942
CMD [ "python" ]

packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ RUN mkdir /tmp/bun-cache && \
4747
chmod -R 777 /tmp/bun-cache && \
4848
echo -e "[install.cache]\ndir = \"/tmp/bun-cache\"\ndisable = true" >> /home/user/.bunfig.toml
4949

50+
USER nobody
51+
5052
CMD [ "esbuild" ]

0 commit comments

Comments
 (0)