AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
refactor(backend): remove the ENABLE_AUTH setting (#15964)
Nicholas Tindle93e908ac5e0a
diff --git a/autogpt_platform/backend/backend/api/ws_api.py b/autogpt_platform/backend/backend/api/ws_api.pyindex 77646218ee..b84f34f4ac 100644--- a/autogpt_platform/backend/backend/api/ws_api.py+++ b/autogpt_platform/backend/backend/api/ws_api.py@@ -17,7 +17,7 @@ from backend.api.model import ()from backend.api.utils.cors import build_cors_paramsfrom backend.data import db, redis_client-from backend.data.user import DEFAULT_USER_ID, is_user_banned+from backend.data.user import is_user_bannedfrom backend.monitoring.instrumentation import (instrument_fastapi,start_metrics_server,@@ -71,9 +71,6 @@ def get_connection_manager():async def authenticate_websocket(websocket: WebSocket) -> str:- if not settings.config.enable_auth:- return DEFAULT_USER_ID-token = websocket.query_params.get("token")if not token:await websocket.close(code=4001, reason="Missing authentication token")diff --git a/autogpt_platform/backend/backend/api/ws_api_test.py b/autogpt_platform/backend/backend/api/ws_api_test.pyindex 9e68fdfe07..47dc1e794d 100644--- a/autogpt_platform/backend/backend/api/ws_api_test.py+++ b/autogpt_platform/backend/backend/api/ws_api_test.py@@ -386,10 +386,9 @@ async def test_handle_subscribe_rejects_unrelated_method(@pytest.mark.asyncio-async def test_authenticate_websocket_missing_token_closes_4001(mocker) -> None:+async def test_authenticate_websocket_missing_token_closes_4001() -> None:from backend.api.ws_api import authenticate_websocket- mocker.patch.object(settings.config, "enable_auth", True)ws = AsyncMock(spec=WebSocket)ws.query_params = {}@@ -404,7 +403,6 @@ async def test_authenticate_websocket_missing_token_closes_4001(mocker) -> None:async def test_authenticate_websocket_invalid_token_closes_4003(mocker) -> None:from backend.api.ws_api import authenticate_websocket- mocker.patch.object(settings.config, "enable_auth", True)mocker.patch("backend.api.ws_api.parse_jwt_token_async",new=AsyncMock(side_effect=ValueError("bad token")),@@ -423,7 +421,6 @@ async def test_authenticate_websocket_invalid_token_closes_4003(mocker) -> None:async def test_authenticate_websocket_missing_sub_closes_4002(mocker) -> None:from backend.api.ws_api import authenticate_websocket- mocker.patch.object(settings.config, "enable_auth", True)mocker.patch("backend.api.ws_api.parse_jwt_token_async",new=AsyncMock(return_value={"not_sub": "x"}),@@ -442,7 +439,6 @@ async def test_authenticate_websocket_missing_sub_closes_4002(mocker) -> None:async def test_authenticate_websocket_happy_path_returns_sub(mocker) -> None:from backend.api.ws_api import authenticate_websocket- mocker.patch.object(settings.config, "enable_auth", True)mocker.patch("backend.api.ws_api.parse_jwt_token_async",new=AsyncMock(return_value={"sub": "user-X"}),@@ -459,7 +455,6 @@ async def test_authenticate_websocket_happy_path_returns_sub(mocker) -> None:async def test_authenticate_websocket_refuses_a_banned_account(mocker) -> None:from backend.api.ws_api import authenticate_websocket- mocker.patch.object(settings.config, "enable_auth", True)mocker.patch("backend.api.ws_api.parse_jwt_token_async",new=AsyncMock(return_value={"sub": "user-X"}),@@ -483,7 +478,6 @@ async def test_authenticate_websocket_refuses_when_the_ban_is_unreadable(told it is banned."""from backend.api.ws_api import authenticate_websocket- mocker.patch.object(settings.config, "enable_auth", True)mocker.patch("backend.api.ws_api.parse_jwt_token_async",new=AsyncMock(return_value={"sub": "user-X"}),@@ -560,19 +554,6 @@ async def test_an_unreadable_ban_keeps_an_open_socket(mock_manager.subscribe_graph_exec.assert_called_once()-async def test_authenticate_websocket_auth_disabled_returns_default(mocker) -> None:- from backend.api.ws_api import authenticate_websocket-- mocker.patch.object(settings.config, "enable_auth", False)- ws = AsyncMock(spec=WebSocket)- ws.query_params = {}-- user_id = await authenticate_websocket(ws)-- assert user_id == DEFAULT_USER_ID--# ---------- get_connection_manager singleton ----------diff --git a/autogpt_platform/backend/backend/util/request_url_logging_test.py b/autogpt_platform/backend/backend/util/request_url_logging_test.pyindex 62c4be82f2..1d8a21e996 100644--- a/autogpt_platform/backend/backend/util/request_url_logging_test.py+++ b/autogpt_platform/backend/backend/util/request_url_logging_test.py@@ -13,7 +13,7 @@ import reimport sysfrom collections.abc import AsyncIterator, Iteratorfrom contextlib import asynccontextmanager-from unittest.mock import AsyncMock+from unittest.mock import AsyncMock, patchimport httpximport pytest@@ -31,7 +31,6 @@ from websockets.exceptions import InvalidStatusfrom backend.api import rest_api, ws_apifrom backend.api.conn_manager import ConnectionManagerfrom backend.api.features.integrations import router as integrations_router-from backend.api.test_helpers import override_configfrom backend.util import logging as service_loggingfrom backend.util import metricsfrom backend.util.process import AppProcess@@ -287,9 +286,11 @@ async def _open_websockets(host: str) -> None:with pytest.raises(InvalidStatus):async with connect(url):pass- # ...and with auth off it is accepted, as a live session's is. A raw quote- # or # earlier in the query must not end the masking before the token.- with override_config(ws_api.settings, "enable_auth", False):+ # ...and once it authenticates it is accepted, as a live session's is. A raw+ # quote or # earlier in the query must not end the masking before the token.+ with patch.object(+ ws_api, "authenticate_websocket", AsyncMock(return_value="user-1")+ ):async with connect(url):passtarget = f"/ws?q=it's#&token={SESSION_TOKEN}"diff --git a/autogpt_platform/backend/backend/util/settings.py b/autogpt_platform/backend/backend/util/settings.pyindex 62ae4d52df..785b068fda 100644--- a/autogpt_platform/backend/backend/util/settings.py+++ b/autogpt_platform/backend/backend/util/settings.py@@ -235,10 +235,6 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):"this is the only per-call wall-clock bound."),)- enable_auth: bool = Field(- default=True,- description="If authentication is enabled or not",- )enable_subscription_credit_grant: bool = Field(default=False,description=(diff --git a/autogpt_platform/single-container/entrypoint.sh b/autogpt_platform/single-container/entrypoint.shindex 8ae78a7ab6..eb8317fd7c 100755--- a/autogpt_platform/single-container/entrypoint.sh+++ b/autogpt_platform/single-container/entrypoint.sh@@ -179,7 +179,7 @@ configure_environment() {# transport) regardless of subscription tier. That is correct for a# single-tenant self-hosted install. Any multi-tenant or hosted deployment# MUST set BEHAVE_AS=cloud, or every user gets every gated capability.- export APP_ENV=dev BEHAVE_AS="${BEHAVE_AS:-local}" ENABLE_AUTH=true+ export APP_ENV=dev BEHAVE_AS="${BEHAVE_AS:-local}"# AutoPilot's daily/weekly USD spend caps are tuned for AutoGPT Cloud# tiers. Without LaunchDarkly every account resolves to NO_TIER, which