OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix(security): Containerized Backend application is running as root
Mike Pawlowski8cf3d8c73534
diff --git a/Dockerfile.backend b/Dockerfile.backendindex c42b4053e..a8ee4ded7 100644--- a/Dockerfile.backend+++ b/Dockerfile.backend@@ -51,17 +51,44 @@ RUN apt-get update && apt-get install -y --no-install-recommends \curl \ca-certificates \openssl \+ gosu \&& rm -rf /var/lib/apt/lists/*+# Create a non-root user/group.+# UID/GID 1000 is the conventional first non-root account and+# matches what Podman's :U volume flag maps to.+RUN groupadd --gid 1000 appuser \+ && useradd --uid 1000 --gid 1000 --no-create-home appuser+WORKDIR /appCOPY --from=builder /app /appCOPY securityconfig/ ./securityconfig/COPY cloud_securityconfig/ ./cloud_securityconfig/+COPY entrypoint.sh /entrypoint.shENV VIRTUAL_ENV=/app/.venvENV PATH="/app/.venv/bin:$PATH"+# Pre-create every directory the app writes to at runtime so they are owned+# by appuser in the image layer. When Docker/Podman mounts a host volume over+# one of these paths the mount takes precedence, but the ownership baked here+# acts as a safe default when no volume is attached (e.g. CI, unit tests).+#+# Writable paths:+# keys/ - RSA JWT keys (private_key.pem / public_key.pem)+# data/ - connections.json+# config/ - config.yaml (ConfigManager runtime settings)+# flows/backup/ - Langflow flow backups (flows/ itself is COPY'd from builder)+# openrag-documents/ - uploaded documents staging area+RUN mkdir -p keys data config flows/backup openrag-documents \+ && chown -R appuser:appuser /app \+ && chmod +x /entrypoint.sh++# entrypoint.sh runs as root, re-chowns volume-mounted directories to appuser+# (belt-and-suspenders for Docker where :U is not supported), then execs the+# application as appuser via gosu.EXPOSE 8000+ENTRYPOINT ["/entrypoint.sh"]CMD ["python", "src/main.py"]diff --git a/Makefile b/Makefileindex 1eb86d08d..04fd04bdd 100644--- a/Makefile+++ b/Makefile@@ -80,7 +80,7 @@ endefbackend frontend docling docling-stop install-be install-fe build-be build-fe build-os build-lf logs-be logs-fe logs-lf logs-os \shell-be shell-lf shell-os restart status health db-reset clear-os-data flow-upload setup factory-reset \dev-branch build-langflow-dev stop-dev clean-dev logs-dev logs-lf-dev shell-lf-dev restart-dev status-dev \- ensure-langflow-data+ ensure-langflow-data ensure-backend-volumesall: help@@ -324,7 +324,11 @@ ensure-langflow-data: ## Create the langflow-data directory if it does not exist@mkdir -p langflow-data@chmod 777 langflow-data-dev: ensure-langflow-data ## Start full stack with GPU support+ensure-backend-volumes: ## Create and permission backend volume directories for Docker (UID 1000 / appuser)+ @mkdir -p flows keys config data+ @chmod 775 flows keys config data++dev: ensure-langflow-data ensure-backend-volumes ## Start full stack with GPU support@echo "$(YELLOW)Starting OpenRAG with GPU support...$(NC)"$(COMPOSE_CMD) -f docker-compose.yml -f docker-compose.gpu.yml up -d@echo "$(PURPLE)Services started!$(NC)"@@ -334,7 +338,7 @@ dev: ensure-langflow-data ## Start full stack with GPU support@echo " $(CYAN)OpenSearch:$(NC) http://localhost:9200"@echo " $(CYAN)Dashboards:$(NC) http://localhost:5601"-dev-cpu: ensure-langflow-data ## Start full stack with CPU only+dev-cpu: ensure-langflow-data ensure-backend-volumes ## Start full stack with CPU only@echo "$(YELLOW)Starting OpenRAG with CPU only...$(NC)"$(COMPOSE_CMD) up -d@echo "$(PURPLE)Services started!$(NC)"@@ -344,7 +348,7 @@ dev-cpu: ensure-langflow-data ## Start full stack with CPU only@echo " $(CYAN)OpenSearch:$(NC) http://localhost:9200"@echo " $(CYAN)Dashboards:$(NC) http://localhost:5601"-dev-local: ensure-langflow-data ## Start infrastructure for local development+dev-local: ensure-langflow-data ensure-backend-volumes ## Start infrastructure for local development@echo "$(YELLOW)Starting infrastructure only (for local development)...$(NC)"$(COMPOSE_CMD) -f docker-compose.yml -f docker-compose.gpu.yml up -d opensearch openrag-backend dashboards langflow@echo "$(PURPLE)Infrastructure started!$(NC)"@@ -355,7 +359,7 @@ dev-local: ensure-langflow-data ## Start infrastructure for local development@echo ""@echo "$(YELLOW)Now run 'make backend' and 'make frontend' in separate terminals$(NC)"-dev-local-cpu: ensure-langflow-data ## Start infrastructure for local development, with CPU only+dev-local-cpu: ensure-langflow-data ensure-backend-volumes ## Start infrastructure for local development, with CPU only@echo "$(YELLOW)Starting infrastructure only (for local development)...$(NC)"$(COMPOSE_CMD) up -d opensearch openrag-backend dashboards langflow@echo "$(PURPLE)Infrastructure started!$(NC)"@@ -366,7 +370,7 @@ dev-local-cpu: ensure-langflow-data ## Start infrastructure for local developmen@echo ""@echo "$(YELLOW)Now run 'make backend' and 'make frontend' in separate terminals$(NC)"-dev-local-build-lf: ensure-langflow-data ## Start infrastructure for local development, building only Langflow image+dev-local-build-lf: ensure-langflow-data ensure-backend-volumes ## Start infrastructure for local development, building only Langflow image@echo "$(YELLOW)Building Langflow image...$(NC)"$(COMPOSE_CMD) -f docker-compose.yml -f docker-compose.gpu.yml build langflow@echo "$(YELLOW)Starting infrastructure only (for local development)...$(NC)"@@ -379,7 +383,7 @@ dev-local-build-lf: ensure-langflow-data ## Start infrastructure for local devel@echo ""@echo "$(YELLOW)Now run 'make backend' and 'make frontend' in separate terminals$(NC)"-dev-local-build-lf-cpu: ensure-langflow-data ## Start infrastructure for local development, building only Langflow image with CPU only+dev-local-build-lf-cpu: ensure-langflow-data ensure-backend-volumes ## Start infrastructure for local development, building only Langflow image with CPU only@echo "$(YELLOW)Building Langflow image (CPU)...$(NC)"$(COMPOSE_CMD) build langflow@echo "$(YELLOW)Starting infrastructure only (for local development)...$(NC)"@@ -398,7 +402,7 @@ dev-local-build-lf-cpu: ensure-langflow-data ## Start infrastructure for local d# Usage: make dev-branch BRANCH=test-openai-responses# make dev-branch BRANCH=feature-x REPO=https://github.com/myorg/langflow.git-dev-branch: ensure-langflow-data ## Build & run full stack with custom Langflow branch+dev-branch: ensure-langflow-data ensure-backend-volumes ## Build & run full stack with custom Langflow branch@echo "$(YELLOW)Building Langflow from branch: $(BRANCH)$(NC)"@echo " $(CYAN)Repository:$(NC) $(REPO)"@echo ""@@ -414,7 +418,7 @@ dev-branch: ensure-langflow-data ## Build & run full stack with custom Langflow@echo " $(CYAN)OpenSearch:$(NC) http://localhost:9200"@echo " $(CYAN)Dashboards:$(NC) http://localhost:5601"-dev-branch-cpu: ensure-langflow-data ## Build & run full stack with custom Langflow branch and CPU only mode+dev-branch-cpu: ensure-langflow-data ensure-backend-volumes ## Build & run full stack with custom Langflow branch and CPU only mode@echo "$(YELLOW)Building Langflow from branch: $(BRANCH)$(NC)"@echo " $(CYAN)Repository:$(NC) $(REPO)"@echo ""@@ -441,7 +445,7 @@ stop-dev: ## Stop dev environment containers$(COMPOSE_CMD) -f docker-compose.dev.yml down@echo "$(PURPLE)Dev environment stopped.$(NC)"-restart-dev: ensure-langflow-data ## Restart dev environment+restart-dev: ensure-langflow-data ensure-backend-volumes ## Restart dev environment@echo "$(YELLOW)Restarting dev environment with branch: $(BRANCH)$(NC)"$(COMPOSE_CMD) -f docker-compose.dev.yml downGIT_BRANCH=$(BRANCH) GIT_REPO=$(REPO) $(COMPOSE_CMD) -f docker-compose.dev.yml up -d@@ -682,7 +686,7 @@ test-integration: ## Run integration tests (requires infrastructure)@echo "$(YELLOW)Make sure to run 'make dev-local' first!$(NC)"uv run pytest tests/integration/core/ -v-test-ci: ensure-langflow-data ## Start infra, run integration + SDK tests, tear down (uses DockerHub images)+test-ci: ensure-langflow-data ensure-backend-volumes ## Start infra, run integration + SDK tests, tear down (uses DockerHub images)@chmod 777 langflow-data@set -e; \echo "$(YELLOW)Installing test dependencies...$(NC)"; \@@ -812,7 +816,7 @@ test-ci: ensure-langflow-data ## Start infra, run integration + SDK tests, tear$(COMPOSE_CMD) down -v 2>/dev/null || true; \exit $$TEST_RESULT-test-ci-local: ensure-langflow-data ## Same as test-ci but builds all images locally+test-ci-local: ensure-langflow-data ensure-backend-volumes ## Same as test-ci but builds all images locally@chmod 777 langflow-data@set -e; \echo "$(YELLOW)Installing test dependencies...$(NC)"; \diff --git a/entrypoint.sh b/entrypoint.shnew file mode 100755index 000000000..16a141f4f--- /dev/null+++ b/entrypoint.sh@@ -0,0 +1,23 @@+#!/bin/sh+# entrypoint.sh — run as root, fix volume-mount ownership, then drop to appuser.+#+# When Docker (not Podman) mounts a host directory the ownership reflects the+# host filesystem, which may not be UID/GID 1000. Podman handles this with the+# :U compose flag; this script is the belt-and-suspenders fallback for Docker+# and any other runtime that does not remap UIDs automatically.+#+# Each path listed below corresponds to a volume mount in docker-compose.yml.+# The chown is a no-op when the directory is already owned by appuser (e.g.+# fresh Podman start), so there is no cost to running this unconditionally.++set -e++chown -R appuser:appuser \+ /app/keys \+ /app/flows \+ /app/config \+ /app/data \+ /app/openrag-documents \+ 2>/dev/null || true++exec gosu appuser "$@"diff --git a/src/tui/main.py b/src/tui/main.pyindex 884ce864f..3e88a06d6 100644--- a/src/tui/main.py+++ b/src/tui/main.py@@ -772,6 +772,22 @@ def setup_host_directories():directory.mkdir(parents=True, exist_ok=True)logger.debug(f"Ensured directory exists: {directory}")+ # Backend volume-mounted directories must be writable by the container user+ # (appuser, UID 1000). Podman handles this via :U in docker-compose.yml, but+ # Docker ignores :U. Applying 0o775 means any process in the directory's group+ # can write; the entrypoint.sh in the image also re-chowns these at startup as+ # a belt-and-suspenders fallback.+ backend_writable = [+ base_dir / "documents",+ base_dir / "flows",+ base_dir / "keys",+ base_dir / "config",+ base_dir / "data",+ ]+ for directory in backend_writable:+ os.chmod(directory, 0o775)+ logger.debug(f"Set permissions 775 on: {directory}")+# Resolve the configured LANGFLOW_DATA_PATH so we pre-create the exact# directory that Docker/Podman will mount, regardless of user customisation.langflow_data_dir = _resolve_langflow_data_path(base_dir)