Skip to content

Commit 3c868fa

Browse files
Dockerfile Security Changes (#64)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description <!-- Describe your changes in detail. --> This modifies the dockerfile to use a non-root user and actually copy all files needed over into the docker image. ## Context <!-- Why is this change required? What problem does it solve? --> This makes the dockerfile more secure by not running as a root user and will remove security issues in SonarCloud (once enabled for this project). ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [x] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md) - [x] I have followed the code style of the project - [ ] I have added tests to cover my changes (where appropriate) - [ ] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.
1 parent 23a465f commit 3c868fa

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

buildBase.dockerfile

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1+
# This dockerfile allows for the code from the project to be built into a Docker image,
2+
# for use in a CI/CD-style environment such as GitHub Actions or Jenkins.
3+
# Further reading on this: https://docs.docker.com/get-started/docker-concepts/the-basics/what-is-an-image/
4+
15
FROM python:3.13-slim
26

7+
# Create non-root OS user/group and configure environment
8+
RUN addgroup --system nonroot \
9+
&& adduser --system --home /home/nonroot nonroot --ingroup nonroot
10+
311
WORKDIR /test
412

13+
ENV HOME=/home/nonroot
14+
ENV PATH="$HOME/.local/bin:$PATH"
15+
516
# Install dependencies
617
COPY ./requirements.txt ./requirements.txt
7-
RUN pip install --no-cache-dir -r requirements.txt
8-
RUN playwright install --with-deps
9-
RUN playwright install chrome
18+
RUN pip install --no-cache-dir -r requirements.txt && \
19+
playwright install --with-deps && \
20+
mkdir -p /tests/ && \
21+
mkdir -p /utils/ && \
22+
mkdir -p /pages/
1023

11-
RUN mkdir -p /tests/
24+
# Copy project files
1225
COPY ./tests/ ./tests/
13-
RUN mkdir -p /utils/
1426
COPY ./utils/ ./utils/
27+
COPY ./pages/ ./pages/
28+
COPY ./conftest.py ./conftest.py
1529
COPY ./pytest.ini ./pytest.ini
1630
COPY ./run_tests.sh ./run_tests.sh
31+
COPY ./users.json ./users.json
32+
33+
# Set permissions, make the script executable and switch OS user
34+
RUN chmod +x ./run_tests.sh \
35+
&& chown -R nonroot:nonroot /test
1736

18-
RUN chmod +x ./run_tests.sh
37+
USER nonroot

0 commit comments

Comments
 (0)