Skip to content

Commit 4632664

Browse files
authored
Run container as codeql user instead of root. (#42)
* Changed the codeql repository permission to be accessible to other user's other than root. Container starts as the codeql user instead of root. * Changed the ownership of the codeql repos within the home directory to codeql Co-authored-by: Cameron McDougall <cameron.mcdougall@microsoft.com>
1 parent 4e95116 commit 4632664

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ LABEL maintainer="Github codeql team"
44
# tzdata install needs to be non-interactive
55
ENV DEBIAN_FRONTEND=noninteractive
66

7-
# install/update basics and python
8-
RUN apt-get update && \
7+
ARG USERNAME=codeql
8+
ENV CODEQL_HOME /usr/local/codeql-home
9+
10+
# create user, install/update basics and python
11+
RUN adduser --home ${CODEQL_HOME} ${USERNAME} && \
12+
apt-get update && \
913
apt-get upgrade -y && \
1014
apt-get install -y --no-install-recommends \
1115
software-properties-common \
@@ -54,10 +58,10 @@ RUN pip3 install --upgrade pip \
5458
&& pip3 install -r /usr/local/startup_scripts/requirements.txt
5559

5660
# Install latest codeQL
57-
ENV CODEQL_HOME /usr/local/codeql-home
61+
5862
# record the latest version of the codeql-cli
5963
RUN python3 /usr/local/startup_scripts/get-latest-codeql-version.py > /tmp/codeql_version
60-
RUN mkdir -p ${CODEQL_HOME} \
64+
RUN mkdir -p \
6165
${CODEQL_HOME}/codeql-repo \
6266
${CODEQL_HOME}/codeql-go-repo \
6367
/opt/codeql
@@ -80,4 +84,10 @@ RUN codeql query compile --threads=0 ${CODEQL_HOME}/codeql-repo/*/ql/src/codeql-
8084
RUN codeql query compile --threads=0 ${CODEQL_HOME}/codeql-go-repo/ql/src/codeql-suites/*.qls --additional-packs=.
8185

8286
ENV PYTHONIOENCODING=utf-8
87+
88+
# Change ownership of all files and directories within CODEQL_HOME to the codeql user
89+
RUN chown -R ${USERNAME}:${USERNAME} ${CODEQL_HOME}
90+
91+
USER ${USERNAME}
92+
8393
ENTRYPOINT ["python3", "/usr/local/startup_scripts/startup.py"]

0 commit comments

Comments
 (0)