From d0f56fb022c79fe4c6c3856711888d3d16c01591 Mon Sep 17 00:00:00 2001 From: Aditya Arora <230317630+Aditya030207@users.noreply.github.com> Date: Fri, 27 Nov 2026 19:06:31 +0530 Subject: [PATCH 1/2] fix(docker): Run the CLI container as a non-root user --- Dockerfile | 12 +++++++++--- README.md | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d781f96..207fdeb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,15 @@ -FROM --platform=$BUILDPLATFORM alpine:3 AS certs -RUN apk add --no-cache ca-certificates +ARG ALPINE_IMAGE=alpine:3.24.4@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf +FROM --platform=$BUILDPLATFORM $ALPINE_IMAGE AS certs +# Prepare the directories on the build platform so the target stage needs no emulation. +RUN apk add --no-cache ca-certificates && mkdir /runtime-work /runtime-home -FROM alpine:3 +FROM $ALPINE_IMAGE ARG TARGETPLATFORM COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=certs --chown=65534:65534 /runtime-work/ /work/ +COPY --from=certs --chown=65534:65534 /runtime-home/ /home/nobody/ COPY $TARGETPLATFORM/flagsmith /usr/local/bin/flagsmith +ENV HOME=/home/nobody WORKDIR /work +USER 65534:65534 ENTRYPOINT ["flagsmith"] diff --git a/README.md b/README.md index 6df6dc9..ca7fc2b 100644 --- a/README.md +++ b/README.md @@ -52,11 +52,13 @@ go build -o flagsmith . ## Docker ```sh -docker run --rm -v "$PWD:/work" -e FLAGSMITH_API_KEY ghcr.io/flagsmith/flagsmith-cli flag list +docker run --rm -v "$PWD:/work:ro" -e FLAGSMITH_API_KEY ghcr.io/flagsmith/flagsmith-cli flag list ``` A container has no keyring, so `flagsmith login` cannot store credentials there — pass `FLAGSMITH_API_KEY` or `FLAGSMITH_ENVIRONMENT_KEY`. +The image runs as an unprivileged user. For a command that writes to `/work`, such as `flagsmith init`, mount the directory read-write and add `--user "$(id -u):$(id -g)" -e HOME=/tmp` to use your host account's permissions. + ## Quickstart ```sh From 1bddfbad7f595bebcb0308b5209e58bf7f3495e2 Mon Sep 17 00:00:00 2001 From: Aditya Arora <230317630+Aditya030207@users.noreply.github.com> Date: Fri, 27 Nov 2026 19:10:33 +0530 Subject: [PATCH 2/2] docs(docker): Cover rootless bind mount permissions --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ca7fc2b..1ffbd0d 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,10 @@ docker run --rm -v "$PWD:/work:ro" -e FLAGSMITH_API_KEY ghcr.io/flagsmith/flagsm A container has no keyring, so `flagsmith login` cannot store credentials there — pass `FLAGSMITH_API_KEY` or `FLAGSMITH_ENVIRONMENT_KEY`. -The image runs as an unprivileged user. For a command that writes to `/work`, such as `flagsmith init`, mount the directory read-write and add `--user "$(id -u):$(id -g)" -e HOME=/tmp` to use your host account's permissions. +The image runs as an unprivileged user. For a command that writes to `/work`, such as `flagsmith init`, mount the directory read-write and select the user that owns it: + +- With rootful Docker and default UID mapping, add `--user "$(id -u):$(id -g)" -e HOME=/tmp` to use your host account. +- With rootless Docker and a directory owned by the daemon user, add `--user 0:0 -e HOME=/tmp`. Container UID and GID 0 map to the host account running the daemon. See [Docker's UID/GID mapping guide](https://docs.docker.com/engine/security/rootless/uid-gid-mapping/). ## Quickstart