OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix(security): Clear-text storage of sensitive information
Mike Pawlowski173769b3c1fb
diff --git a/src/tui/managers/env_manager.py b/src/tui/managers/env_manager.pyindex bbe5968f2..fe5081c93 100644--- a/src/tui/managers/env_manager.py+++ b/src/tui/managers/env_manager.py@@ -68,7 +68,7 @@ class EnvConfig:langflow_auto_login: str = "False"langflow_new_user_is_active: str = "False"langflow_enable_superuser_cli: str = "False"-+# Ingestion settingsdisable_ingest_with_langflow: str = "False"nudges_flow_id: str = "ebc01d31-1976-46ce-a385-b0240327226c"@@ -85,7 +85,7 @@ class EnvConfig:openrag_data_path: str = "$HOME/.openrag/data" # Backend data (conversations, tokens, etc.)opensearch_data_path: str = "$HOME/.openrag/data/opensearch-data"openrag_tui_config_path_legacy: str = "$HOME/.openrag/tui/config"-+# Container version (linked to TUI version)openrag_version: str = ""@@ -103,7 +103,7 @@ class EnvManager:# Use centralized location for TUI .env filefrom utils.paths import get_tui_env_file, get_legacy_pathsself.env_file = get_tui_env_file()-+# Check for legacy .env in current directory and migrate if neededlegacy_env = get_legacy_paths()["tui_env"]if not self.env_file.exists() and legacy_env.exists():@@ -116,7 +116,7 @@ class EnvManager:except Exception as e:logger.warning(f"Failed to migrate .env file: {e}")-+self.config = EnvConfig()def generate_secure_password(self) -> str:@@ -156,7 +156,7 @@ class EnvManager:def load_existing_env(self) -> bool:"""Load existing .env file if it exists, or fall back to environment variables.-+Uses python-dotenv's load_dotenv() for standard .env file parsing, which handles:- Quoted values (single and double quotes)- Variable expansion (${VAR})@@ -210,9 +210,9 @@ class EnvManager:"LANGFUSE_PUBLIC_KEY": "langfuse_public_key", # pragma: allowlist secret"LANGFUSE_HOST": "langfuse_host",}-+loaded_from_file = False-+# Load .env file using python-dotenv for standard parsing# override=True ensures .env file values take precedence over existing environment variablesif self.env_file.exists():@@ -223,14 +223,14 @@ class EnvManager:logger.debug(f"Loaded .env file from {self.env_file}")except Exception as e:logger.error("Error loading .env file", error=str(e))-+# Map environment variables to config attributes# This works whether values came from .env file or existing environment variablesfor env_key, attr_name in attr_map.items():value = os.environ.get(env_key, "")if value:setattr(self.config, attr_name, value)-+return loaded_from_filedef setup_secure_defaults(self) -> None:@@ -240,7 +240,7 @@ class EnvManager:if not self.config.langflow_secret_key:self.config.langflow_secret_key = self.generate_langflow_secret_key()-+# Set OPENRAG_VERSION to TUI version if not already setif not self.config.openrag_version:try:@@ -376,7 +376,9 @@ class EnvManager:backup_file = self.env_file.with_suffix(f".env.backup.{timestamp}")self.env_file.rename(backup_file)- with open(self.env_file, "w") as f:+ # Create .env file with secure permissions (owner read/write only) to protect secrets+ fd = os.open(self.env_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)+ with os.fdopen(fd, "w") as f:f.write("# OpenRAG Environment Configuration\n")f.write("# Generated by OpenRAG TUI\n\n")@@ -460,7 +462,7 @@ class EnvManager:provider_vars.append(("WATSONX_ENDPOINT", self.config.watsonx_endpoint))if self.config.watsonx_project_id:provider_vars.append(("WATSONX_PROJECT_ID", self.config.watsonx_project_id))-+if provider_vars:f.write("# AI Provider API Keys and Endpoints\n")for var_name, var_value in provider_vars:@@ -548,6 +550,9 @@ class EnvManager:if langfuse_written:f.write("\n")+ f.flush()+ os.fsync(f.fileno())+return Trueexcept Exception as e:@@ -649,11 +654,10 @@ class EnvManager:"""Ensure OPENRAG_VERSION is set in .env file to match TUI version."""try:from ..utils.version_check import get_current_version- import oscurrent_version = get_current_version()if current_version == "unknown":return-+# Check if OPENRAG_VERSION is already set in .envif self.env_file.exists():# Load .env file using load_dotenv@@ -662,17 +666,17 @@ class EnvManager:if existing_value and existing_value == current_version:# Already correct, no update neededreturn-+# Set or update OPENRAG_VERSIONself.config.openrag_version = current_version-+# Update .env fileif self.env_file.exists():# Read existing contentlines = self.env_file.read_text().splitlines()updated = Falsenew_lines = []-+for line in lines:if line.strip().startswith("OPENRAG_VERSION"):# Replace existing line@@ -680,7 +684,7 @@ class EnvManager:updated = Trueelse:new_lines.append(line)-+# If not found, add it after OPENSEARCH_DATA_PATH or at the endif not updated:insert_pos = len(new_lines)@@ -689,14 +693,18 @@ class EnvManager:insert_pos = i + 1breaknew_lines.insert(insert_pos, f"OPENRAG_VERSION={self._quote_env_value(current_version)}")-- with open(self.env_file, 'w') as f:++ fd = os.open(self.env_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)+ # Ensure pre-existing files get restricted permissions+ os.chmod(self.env_file, 0o600)+ with os.fdopen(fd, 'w') as f:f.write("\n".join(new_lines) + "\n")f.flush()os.fsync(f.fileno())else:# Create new .env file with just OPENRAG_VERSION- with open(self.env_file, 'w') as f:+ fd = os.open(self.env_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)+ with os.fdopen(fd, 'w') as f:content = (f"# OpenRAG Environment Configuration\n"f"# Generated by OpenRAG TUI\n\n"@@ -706,7 +714,7 @@ class EnvManager:f.flush()os.fsync(f.fileno())except Exception as e:- logger.debug(f"Error ensuring OPENRAG_VERSION: {e}")+ logger.error(f"Error ensuring OPENRAG_VERSION: {e}")def generate_compose_volume_mounts(self) -> List[str]:"""Generate Docker Compose volume mount strings from documents paths."""