DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(codex-auth): make the local container OAuth bridge temporary (#743)
Geonwoo Jeongd824a7f9f176
diff --git a/CONTAINERIZATION.md b/CONTAINERIZATION.mdindex 236882217..6a9cd0d51 100644--- a/CONTAINERIZATION.md+++ b/CONTAINERIZATION.md@@ -90,6 +90,84 @@ Notes:the name. The `deeptutor-data` volume keeps your settings and workspaceacross restarts.+### Temporary local Codex OAuth bridge++OpenAI Codex redirects the browser to fixed loopback ports `1455` or `1457`.+The default container network is separate from the host loopback, so publish+both ports to the Web frontend only while signing in. Both host ports must be+free before starting the temporary bridge.++For `docker run`, stop the normal container and temporarily rerun the same+image and data volume with two extra loopback-only mappings:++```bash+docker run --rm --name deeptutor \+ -p 127.0.0.1:3782:3782 \+ -p 127.0.0.1:1455:3782 \+ -p 127.0.0.1:1457:3782 \+ -v deeptutor-data:/app/data \+ ghcr.io/hkuds/deeptutor:latest+```++For Compose, add the same temporary overlay to the base file you normally use:++```bash+# Source build with sidecars+python scripts/docker_compose.py \+ -f docker-compose.yml -f compose.codex-oauth.yaml \+ up -d --force-recreate deeptutor++# Pre-built GHCR image+python scripts/docker_compose.py \+ -f docker-compose.ghcr.yml -f compose.codex-oauth.yaml \+ up -d --force-recreate deeptutor++# Rootless Podman+podman compose -f compose.yaml -f compose.codex-oauth.yaml \+ up -d --force-recreate deeptutor+```++Complete **Settings → Models → OpenAI Codex → Sign in with Codex**. After the+status changes to **Connected**, stop the temporary `docker run` container and+return to the normal command above. For Compose, rerun the same base command+without `compose.codex-oauth.yaml`; keep `--force-recreate deeptutor` so the+temporary port bindings are removed.++This releases host ports `1455` and `1457`; credentials remain in the persistent+`/app/data/system` tree. Bind every callback mapping to `127.0.0.1` and never+expose it on a LAN or public interface — the overlay publishes the **whole**+frontend on those two ports, not just `/auth/callback`. For a manual+`docker run` whose container-side frontend port is not `3782`, change the+right-hand `3782` targets; `scripts/docker_compose.py` handles configured+custom ports. For single-container installs, set `sandbox_allow_subprocess`+to `false` if model-generated code must not share the container trust+boundary with secrets.++### One-time migration: `docker-compose.ghcr.yml` now mounts all of `./data`++`docker-compose.ghcr.yml` used to bind-mount only three subtrees+(`data/user`, `data/memory`, `data/knowledge_bases`), so everything else —+`data/system` (the JWT signing secret, accounts, grants, audit log, per-owner+Codex tokens), `data/users` (per-user workspaces), `data/partners`,+`data/cli-apps` — lived in the container's writable layer and was discarded+on every recreate. It now mounts the whole tree, matching+`docker-compose.yml` and `compose.yaml`.++**Before your first `up -d` after upgrading**, copy that state out of the+running container, or the empty host directories shadow it and DeepTutor+regenerates the auth secret (logging everyone out) and starts with no+non-admin accounts:++```bash+for tree in system users partners cli-apps; do+ docker cp "deeptutor:/app/data/$tree" "./data/$tree" 2>/dev/null || true+done+```++Deployments using a named volume (`-v deeptutor-data:/app/data`) or the+source-build Compose file were never affected — they already persisted the+whole tree.+### Remote / reverse-proxy deploymentsFor the common **single-container** case (this image), you do **not** needdiff --git a/README.md b/README.mdindex 4ef459074..a8f3dfc04 100644--- a/README.md+++ b/README.md@@ -627,7 +627,9 @@ Settings is the operational control plane, with a live status strip (Backend, LLMost sections use a draft-and-apply flow, so you can test a provider before committing it. Four themes ship in the box — Default, Cream, Dark, and Glass. Project-root `.env` files are intentionally ignored; runtime configuration lives under `data/user/settings/*.json` unless `DEEPTUTOR_HOME` or `deeptutor start --home` points the app elsewhere.-**OpenAI Codex OAuth (experimental).** Picking **OpenAI Codex** under Models → LLM replaces the API-key fields with a browser sign-in that runs against your own ChatGPT plan, so no `OPENAI_API_KEY` is needed. Tokens live only in `data/system/user-secrets/<owner>/private/openai-codex/` — outside every tree the exec sandbox can reach — and DeepTutor never reads or modifies your `~/.codex` CLI login. The model list comes from that account's live catalog; signing in publishes the profile but only becomes the active model when no LLM is configured yet. Because a token authorizes one person's plan, the profile is not shareable through user grants — each account signs in for itself.+**OpenAI Codex OAuth (experimental).** Picking **OpenAI Codex** under Models → LLM replaces the API-key fields with a browser sign-in that runs against your own ChatGPT plan, so no `OPENAI_API_KEY` is needed. Tokens live only in `data/system/user-secrets/<owner>/private/openai-codex/` — in the multi-container Compose deployment, outside every tree the exec sandbox can reach — and DeepTutor never reads or modifies your `~/.codex` CLI login. The model list comes from that account's live catalog; signing in publishes the profile but only becomes the active model when no LLM is configured yet. Because a token authorizes one person's plan, the profile is not shareable through user grants — each account signs in for itself.++Default local Docker and Podman deployments use separate loopback networks and need a temporary bridge during sign-in. Follow the [temporary local Codex OAuth bridge guide](./CONTAINERIZATION.md#temporary-local-codex-oauth-bridge) for the exact Docker, Compose, Podman, and teardown commands.For a remote deployment, the browser's `localhost` and the server's `localhost` are different machines, so an ordinary reverse proxy alone cannot carry the browser's localhost callback to the server. Use an SSH tunnel as the callback bridge. The tunnel reaches the already-published Web port; Next.js rewrites only the exact callback path to the public callback broker, and the broker validates `state` before routing to the original OAuth operation. The callback listener remains on the backend loopback, ports `1455` and `1457` are not published, and this path supports the default Docker bridge network.diff --git a/compose.codex-oauth.yaml b/compose.codex-oauth.yamlnew file mode 100644index 000000000..2e722207c--- /dev/null+++ b/compose.codex-oauth.yaml@@ -0,0 +1,9 @@+# Temporary local OpenAI Codex OAuth callback bridge.+#+# Apply this overlay only while signing in, then recreate the service from its+# base Compose file so ports 1455 and 1457 are returned to other Codex clients.+services:+ deeptutor:+ ports:+ - "127.0.0.1:1455:${DEEPTUTOR_DOCKER_FRONTEND_PORT:-3782}"+ - "127.0.0.1:1457:${DEEPTUTOR_DOCKER_FRONTEND_PORT:-3782}"diff --git a/docker-compose.ghcr.yml b/docker-compose.ghcr.ymlindex 47bf5c410..c73df472b 100644--- a/docker-compose.ghcr.yml+++ b/docker-compose.ghcr.yml@@ -47,10 +47,14 @@ services:- "${DEEPTUTOR_DOCKER_FRONTEND_PORT:-3782}:${DEEPTUTOR_DOCKER_FRONTEND_PORT:-3782}"volumes:- # Persistent data (created automatically on first start)- - ./data/user:/app/data/user- - ./data/memory:/app/data/memory- - ./data/knowledge_bases:/app/data/knowledge_bases+ # Persist every workspace and deployment secret across recreation.+ # This used to mount only data/user, data/memory and data/knowledge_bases,+ # which left data/system (auth secret, accounts, grants, per-owner Codex+ # tokens), data/users, data/partners and data/cli-apps in the container's+ # writable layer — discarded on every recreate. Upgrading from that+ # layout needs a one-time copy out of the running container first; see+ # CONTAINERIZATION.md → "One-time migration".+ - ./data:/app/datahealthcheck:test: ["CMD", "curl", "-f", "http://localhost:${DEEPTUTOR_DOCKER_BACKEND_PORT:-8001}/"]diff --git a/tests/scripts/test_docker_compose.py b/tests/scripts/test_docker_compose.pyindex ff0825fee..43b67c4b6 100644--- a/tests/scripts/test_docker_compose.py+++ b/tests/scripts/test_docker_compose.py@@ -3,8 +3,11 @@ from __future__ import annotationsimport importlib.utilimport jsonfrom pathlib import Path+import reimport sys+import yaml+def _load_module():module_path = Path(__file__).resolve().parents[2] / "scripts" / "docker_compose.py"@@ -73,6 +76,77 @@ def test_compose_files_do_not_consume_legacy_env_names() -> None:assert "DEEPTUTOR_DOCKER_BACKEND_PORT" in content+def _compose_service(root: Path, name: str) -> dict:+ content = yaml.safe_load((root / name).read_text(encoding="utf-8"))+ return content["services"]["deeptutor"]+++def _volume_targets(root: Path, name: str) -> set[str | None]:+ volumes = _compose_service(root, name).get("volumes", [])+ return {+ (volume.get("target") if isinstance(volume, dict) else str(volume).split(":")[1])+ for volume in volumes+ }+++def test_default_compose_files_do_not_reserve_codex_callback_ports() -> None:+ """The fixed Codex callback ports are opt-in because other clients use them."""+ root = Path(__file__).resolve().parents[2]+ for name in ("docker-compose.yml", "docker-compose.ghcr.yml", "compose.yaml"):+ ports = _compose_service(root, name).get("ports", [])+ assert not any(re.search(r"(^|:)145[57]:", str(port)) for port in ports), name+++def test_codex_oauth_overlay_forwards_loopback_callbacks_to_frontend() -> None:+ """The temporary overlay routes browser callbacks through the Web broker."""+ root = Path(__file__).resolve().parents[2]+ ports = _compose_service(root, "compose.codex-oauth.yaml")["ports"]++ assert set(ports) == {+ "127.0.0.1:1455:${DEEPTUTOR_DOCKER_FRONTEND_PORT:-3782}",+ "127.0.0.1:1457:${DEEPTUTOR_DOCKER_FRONTEND_PORT:-3782}",+ }+++def test_official_container_manifests_persist_codex_credentials() -> None:+ """Container recreation must retain data/system, where Codex tokens live."""+ root = Path(__file__).resolve().parents[2]+ for name in ("docker-compose.yml", "docker-compose.ghcr.yml", "compose.yaml"):+ targets = _volume_targets(root, name)+ assert "/app/data" in targets or "/app/data/system" in targets, name+++def test_ghcr_compose_persists_complete_data_tree() -> None:+ """Forced recreation must retain every workspace as well as OAuth tokens."""+ root = Path(__file__).resolve().parents[2]+ volumes = _compose_service(root, "docker-compose.ghcr.yml")["volumes"]++ assert "./data:/app/data" in volumes+++def test_container_docs_use_temporary_codex_oauth_bridge() -> None:+ """README links to the canonical guide, which owns the exact commands."""+ root = Path(__file__).resolve().parents[2]+ readme = (root / "README.md").read_text(encoding="utf-8")+ guide = (root / "CONTAINERIZATION.md").read_text(encoding="utf-8")+ heading = "### Temporary local Codex OAuth bridge"+ assert heading in guide, f"{heading} was renamed; update this test with it"+ section = guide.split(heading, 1)[1].split("\n### ", 1)[0]+ normalized_section = " ".join(section.replace("\\\n", " ").split())++ assert "CONTAINERIZATION.md#temporary-local-codex-oauth-bridge" in readme+ assert "127.0.0.1:1455:3782" in section+ assert "127.0.0.1:1457:3782" in section+ for base_file in ("docker-compose.yml", "docker-compose.ghcr.yml"):+ assert (+ f"-f {base_file} -f compose.codex-oauth.yaml up -d --force-recreate deeptutor"+ ) in normalized_section+ assert (+ "podman compose -f compose.yaml -f compose.codex-oauth.yaml "+ "up -d --force-recreate deeptutor"+ ) in normalized_section++def test_dockerfile_is_json_driven_without_bundle_sed() -> None:"""The image no longer rewrites the built bundle at startup (the runtime``sed -i`` broke under a read-only rootfs). URL/auth knowledge is JSON-driven: