π OpenHands: AI-Driven Development
Persist jwt_secret in config file (#5353)
tofarrd782bdf691c2
diff --git a/README.md b/README.mdindex f4fcffcdb4..141420021b 100644--- a/README.md+++ b/README.md@@ -45,10 +45,11 @@ system requirements and more information.```bashdocker pull docker.all-hands.dev/all-hands-ai/runtime:0.15-nikolaik-docker run -it --pull=always \+docker run -it --rm --pull=always \-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.15-nikolaik \-e LOG_ALL_EVENTS=true \-v /var/run/docker.sock:/var/run/docker.sock \+ -v ~/.openhands:/home/openhands/.openhands \-p 3000:3000 \--add-host host.docker.internal:host-gateway \--name openhands-app \diff --git a/containers/app/Dockerfile b/containers/app/Dockerfileindex 266a9d6b3e..67753cbe2c 100644--- a/containers/app/Dockerfile+++ b/containers/app/Dockerfile@@ -42,6 +42,8 @@ ENV USE_HOST_NETWORK=falseENV WORKSPACE_BASE=/opt/workspace_baseENV OPENHANDS_BUILD_VERSION=$OPENHANDS_BUILD_VERSIONENV SANDBOX_USER_ID=0+ENV FILE_STORE=local+ENV FILE_STORE_PATH=~/.openhandsRUN mkdir -p $WORKSPACE_BASERUN apt-get update -y \diff --git a/openhands/core/config/app_config.py b/openhands/core/config/app_config.pyindex 9e883860cb..497cb9061e 100644--- a/openhands/core/config/app_config.py+++ b/openhands/core/config/app_config.py@@ -1,4 +1,3 @@-import uuidfrom dataclasses import dataclass, field, fields, is_dataclassfrom typing import ClassVar@@ -66,7 +65,7 @@ class AppConfig:modal_api_token_id: str = ''modal_api_token_secret: str = ''disable_color: bool = False- jwt_secret: str = uuid.uuid4().hex+ jwt_secret: str = ''attach_session_middleware_class: str = ('openhands.server.middleware.AttachSessionMiddleware')diff --git a/openhands/core/config/utils.py b/openhands/core/config/utils.pyindex 6f29066019..3aedaf9523 100644--- a/openhands/core/config/utils.py+++ b/openhands/core/config/utils.py@@ -5,6 +5,7 @@ import platformfrom dataclasses import is_dataclassfrom types import UnionTypefrom typing import Any, MutableMapping, get_args, get_origin+from uuid import uuid4import tomlfrom dotenv import load_dotenv@@ -19,7 +20,10 @@ from openhands.core.config.config_utils import (from openhands.core.config.llm_config import LLMConfigfrom openhands.core.config.sandbox_config import SandboxConfigfrom openhands.core.config.security_config import SecurityConfig+from openhands.storage import get_file_store+from openhands.storage.files import FileStore+JWT_SECRET = '.jwt_secret'load_dotenv()@@ -195,6 +199,16 @@ def load_from_toml(cfg: AppConfig, toml_file: str = 'config.toml'):)+def get_or_create_jwt_secret(file_store: FileStore) -> str:+ try:+ jwt_secret = file_store.read(JWT_SECRET)+ return jwt_secret+ except FileNotFoundError:+ new_secret = uuid4().hex+ file_store.write(JWT_SECRET, new_secret)+ return new_secret++def finalize_config(cfg: AppConfig):"""More tweaks to the config after it's been loaded."""if cfg.workspace_base is not None:@@ -223,6 +237,11 @@ def finalize_config(cfg: AppConfig):if cfg.cache_dir:pathlib.Path(cfg.cache_dir).mkdir(parents=True, exist_ok=True)+ if not cfg.jwt_secret:+ cfg.jwt_secret = get_or_create_jwt_secret(+ get_file_store(cfg.file_store, cfg.file_store_path)+ )+# Utility function for command line --group argumentdef get_llm_config_arg(