Skip to content

fix(security): Containerized Backend application is running as root#1329

Open
mpawlow wants to merge 2 commits intomainfrom
mp/fix/GH-1322-backend-app-running-as-root
Open

fix(security): Containerized Backend application is running as root#1329
mpawlow wants to merge 2 commits intomainfrom
mp/fix/GH-1322-backend-app-running-as-root

Conversation

@mpawlow
Copy link
Copy Markdown
Collaborator

@mpawlow mpawlow commented Apr 2, 2026

Issue

Summary

  • Configured the backend container to run as a non-root user (appuser, UID/GID 1000) by introducing a dedicated entrypoint script, updating the Dockerfile, and ensuring host volume directories are pre-created with correct permissions.

Dockerfile Changes

  • Installed gosu to enable privilege dropping from root to appuser at container startup.
  • Created the appuser group (GID 1000) and user (UID 1000) in the image.
  • Added COPY entrypoint.sh /entrypoint.sh and set it as the ENTRYPOINT.
  • Pre-created all runtime-writable directories (keys/, data/, config/, flows/backup/, openrag-documents/) and chown-ed them to appuser in the image layer so defaults are correct when no volume is attached.

New: entrypoint.sh

  • Added entrypoint.sh that runs as root on container start.
  • Re-chowns all volume-mounted directories (keys, flows, config, data, openrag-documents) to appuser:appuser to handle Docker hosts where :U remapping is not supported.
  • Execs the application process as appuser via gosu, dropping root privileges before src/main.py starts.

Makefile Changes

  • Added ensure-backend-volumes target that creates and sets 775 permissions on flows/, keys/, config/, and data/ on the host before Docker mounts them.
  • Added ensure-backend-volumes as a prerequisite to all dev, dev-cpu, dev-local, dev-local-cpu, dev-local-build-lf, dev-local-build-lf-cpu, dev-branch, dev-branch-cpu, restart-dev, test-ci, and test-ci-local targets.

TUI (src/tui/main.py)

  • Extended setup_host_directories() to apply chmod 0o775 on all backend volume-mounted directories (documents/, flows/, keys/, config/, data/) so the container's appuser (UID 1000) can write to them even on Docker hosts that do not remap UIDs.

Issue

- #1322

Summary

- Configured the backend container to run as a non-root user (appuser, UID/GID 1000) by introducing a dedicated entrypoint script, updating the Dockerfile, and ensuring host volume directories are pre-created with correct permissions.

Dockerfile Changes

- Installed `gosu` to enable privilege dropping from root to appuser at container startup.
- Created the `appuser` group (GID 1000) and user (UID 1000) in the image.
- Added `COPY entrypoint.sh /entrypoint.sh` and set it as the `ENTRYPOINT`.
- Pre-created all runtime-writable directories (`keys/`, `data/`, `config/`, `flows/backup/`, `openrag-documents/`) and `chown`-ed them to `appuser` in the image layer so defaults are correct when no volume is attached.

New: entrypoint.sh

- Added `entrypoint.sh` that runs as root on container start.
- Re-`chown`s all volume-mounted directories (`keys`, `flows`, `config`, `data`, `openrag-documents`) to `appuser:appuser` to handle Docker hosts where `:U` remapping is not supported.
- Execs the application process as `appuser` via `gosu`, dropping root privileges before `src/main.py` starts.

Makefile Changes

- Added `ensure-backend-volumes` target that creates and sets `775` permissions on `flows/`, `keys/`, `config/`, and `data/` on the host before Docker mounts them.
- Added `ensure-backend-volumes` as a prerequisite to all `dev`, `dev-cpu`, `dev-local`, `dev-local-cpu`, `dev-local-build-lf`, `dev-local-build-lf-cpu`, `dev-branch`, `dev-branch-cpu`, `restart-dev`, `test-ci`, and `test-ci-local` targets.

TUI (src/tui/main.py)

- Extended `setup_host_directories()` to apply `chmod 0o775` on all backend volume-mounted directories (`documents/`, `flows/`, `keys/`, `config/`, `data/`) so the container's `appuser` (UID 1000) can write to them even on Docker hosts that do not remap UIDs.
@mpawlow mpawlow self-assigned this Apr 2, 2026
@github-actions github-actions bot added backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) docker bug 🔴 Something isn't working. labels Apr 2, 2026
@github-actions github-actions bot added ci ⬛ CI/CD, build, and infrastructure issues bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. ci ⬛ CI/CD, build, and infrastructure issues docker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant