Skip to content

Commit

Permalink
non-root users for Dockerfiles (actualbudget#300)
Browse files Browse the repository at this point in the history
* Optional non-root users for Dockerfiles
  • Loading branch information
hkiang01 authored and MMichotte committed Sep 9, 2024
1 parent 2efa0f5 commit c26f5d5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ RUN yarn workspaces focus --all --production

FROM node:18-bullseye-slim as prod
RUN apt-get update && apt-get install tini && apt-get clean -y && rm -rf /var/lib/apt/lists/*

ARG USERNAME=actual
ARG USER_UID=1001
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
RUN mkdir /data && chown -R ${USERNAME}:${USERNAME} /data

WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
ADD package.json app.js ./
Expand Down
7 changes: 7 additions & 0 deletions docker/edge-alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ RUN unzip /tmp/desktop-client.zip -d /public

FROM alpine:3.17 as prod
RUN apk add --no-cache nodejs tini

ARG USERNAME=actual
ARG USER_UID=1001
ARG USER_GID=$USER_UID
RUN addgroup -S ${USERNAME} -g ${USER_GID} && adduser -S ${USERNAME} -G ${USERNAME} -u ${USER_UID}
RUN mkdir /data && chown -R ${USERNAME}:${USERNAME} /data

WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
COPY --from=base /public /public
Expand Down
8 changes: 8 additions & 0 deletions docker/edge-ubuntu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ RUN unzip /tmp/desktop-client.zip -d /public

FROM node:18-bullseye-slim as prod
RUN apt-get update && apt-get install tini && apt-get clean -y && rm -rf /var/lib/apt/lists/*

ARG USERNAME=actual
ARG USER_UID=1001
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
RUN mkdir /data && chown -R ${USERNAME}:${USERNAME} /data

WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
COPY --from=base /public /public
Expand Down
7 changes: 7 additions & 0 deletions docker/stable-alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ RUN if [ "$(uname -m)" = "armv7l" ]; then npm install bcrypt better-sqlite3 --bu

FROM alpine:3.17 as prod
RUN apk add --no-cache nodejs tini

ARG USERNAME=actual
ARG USER_UID=1001
ARG USER_GID=$USER_UID
RUN addgroup -S ${USERNAME} -g ${USER_GID} && adduser -S ${USERNAME} -G ${USERNAME} -u ${USER_UID}
RUN mkdir /data && chown -R ${USERNAME}:${USERNAME} /data

WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
ADD package.json app.js ./
Expand Down
8 changes: 8 additions & 0 deletions docker/stable-ubuntu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ RUN yarn workspaces focus --all --production

FROM node:18-bullseye-slim as prod
RUN apt-get update && apt-get install tini && apt-get clean -y && rm -rf /var/lib/apt/lists/*

ARG USERNAME=actual
ARG USER_UID=1001
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
RUN mkdir /data && chown -R ${USERNAME}:${USERNAME} /data

WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
ADD package.json app.js ./
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/300.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [hkiang01]
---

Optional non-root user for Docker

0 comments on commit c26f5d5

Please sign in to comment.