From d97735c956562b16d446cc26f2b9244aabadfd42 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Dec 2025 23:56:19 +0100 Subject: [PATCH] Feat/Run Docker container as non-root user for Kubernetes PSP/PSA compatibility (#1) * Initial plan * Add non-root user support to Dockerfile Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> * Add SECURITY.md documentation Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> * Add Kubernetes example manifest, verification script, and README updates Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> * Remove documentation changes (SECURITY.md, k8s-example.yaml, verify script, README updates) Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: theepicsaxguy <39008574+theepicsaxguy@users.noreply.github.com> --- Dockerfile | 25 ++++++++++++++++++++----- scripts/docker-entrypoint.sh | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 629cf433..a7775f3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,8 +20,15 @@ RUN apt-get update && apt-get install -y \ RUN corepack enable && corepack prepare pnpm@9.15.0 --activate -RUN curl -fsSL https://bun.sh/install | bash && \ - ln -s $HOME/.bun/bin/bun /usr/local/bin/bun +USER node + +RUN mkdir -p /home/node/.local/bin && \ + curl -fsSL https://bun.sh/install | bash && \ + ln -s /home/node/.bun/bin/bun /home/node/.local/bin/bun + +USER root + +ENV PATH="/home/node/.local/bin:/home/node/.bun/bin:${PATH}" WORKDIR /app @@ -47,8 +54,13 @@ RUN pnpm --filter frontend build FROM base AS runner -RUN curl -fsSL https://opencode.ai/install | bash && \ - ln -s $HOME/.opencode/bin/opencode /usr/local/bin/opencode +USER node + +RUN mkdir -p /home/node/.local/bin && \ + curl -fsSL https://opencode.ai/install | bash && \ + ln -s /home/node/.opencode/bin/opencode /home/node/.local/bin/opencode + +USER root ENV NODE_ENV=production ENV HOST=0.0.0.0 @@ -69,7 +81,10 @@ RUN mkdir -p /app/backend/node_modules/@opencode-webui && \ COPY scripts/docker-entrypoint.sh /docker-entrypoint.sh RUN chmod +x /docker-entrypoint.sh -RUN mkdir -p /workspace /app/data +RUN mkdir -p /workspace /app/data && \ + chown -R node:node /workspace /app/data /app + +USER node EXPOSE 5003 diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index 1ca8786d..92a09220 100644 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/bash set -e +export HOME=/home/node export BUN_INSTALL="$HOME/.bun" export PATH="$BUN_INSTALL/bin:$HOME/.opencode/bin:$HOME/.local/bin:$PATH"