Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(auth): allow root key on trusted admin targets (#3249)
huangruitengabc325826b35
diff --git a/openviking/server/auth/plugins/trusted.py b/openviking/server/auth/plugins/trusted.pyindex 6d14addde..7b789b1f3 100644--- a/openviking/server/auth/plugins/trusted.py+++ b/openviking/server/auth/plugins/trusted.py@@ -127,21 +127,23 @@ class TrustedAuthPlugin(AuthPlugin):effective_account_id = explicit_account_id or x_openviking_accounteffective_user_id = explicit_user_id or x_openviking_user- # Admin paths may omit identity completely, but partial identity is rejected.+ # A verified Root key is the caller identity for admin routes. Path+ # parameters such as ``account_id`` identify the managed resource, so+ # they must not be mistaken for a partial caller identity.is_admin_path = request.url.path.startswith(_TRUSTED_RELAXED_IDENTITY_PREFIXES)if is_admin_path:- if bool(effective_account_id) != bool(effective_user_id):- raise InvalidArgumentError(- "Trusted mode requests must include "- "X-OpenViking-Account or explicit account_id in the URL and "- "X-OpenViking-User or explicit user_id in the URL."- )if configured_root_api_key:return ResolvedIdentity(role=Role.ROOT,account_id=effective_account_id or "trusted",user_id=effective_user_id or "trusted",)+ if bool(effective_account_id) != bool(effective_user_id):+ raise InvalidArgumentError(+ "Trusted mode requests must include "+ "X-OpenViking-Account or explicit account_id in the URL and "+ "X-OpenViking-User or explicit user_id in the URL."+ )if not effective_account_id and not effective_user_id:return ResolvedIdentity(role=Role.ROOT,diff --git a/tests/server/test_admin_api.py b/tests/server/test_admin_api.pyindex ac4699d15..cff1d4a5f 100644--- a/tests/server/test_admin_api.py+++ b/tests/server/test_admin_api.py@@ -1318,11 +1318,7 @@ async def test_trusted_mode_admin_can_list_users_without_account_or_user_headersresp = await trusted_admin_client.get(f"/api/v1/admin/accounts/{acct}/users",- headers={- "X-API-Key": ROOT_KEY,- "X-OpenViking-Account": acct,- "X-OpenViking-User": "alice",- },+ headers={"X-API-Key": ROOT_KEY},)assert resp.status_code == 200assert any(user["user_id"] == "alice" for user in resp.json()["result"])diff --git a/tests/server/test_auth.py b/tests/server/test_auth.pyindex 6a76cd31d..9640dff28 100644--- a/tests/server/test_auth.py+++ b/tests/server/test_auth.py@@ -1386,6 +1386,23 @@ async def test_trusted_mode_admin_api_with_partial_identity_still_requires_full_)+async def test_trusted_mode_root_key_can_target_account_without_caller_identity():+ """A verified Root key should not treat a target account as partial caller identity."""+ request = _make_request(+ "/api/v1/admin/accounts/acme/users",+ headers={"X-API-Key": ROOT_KEY},+ auth_mode="trusted",+ root_api_key=ROOT_KEY,+ )+ request.scope["path_params"] = {"account_id": "acme"}++ identity = await resolve_identity(request, x_api_key=ROOT_KEY)++ assert identity.role == Role.ROOT+ assert identity.account_id == "acme"+ assert identity.user_id == "trusted"++async def test_trusted_mode_get_request_context_exempts_admin_paths():"""get_request_context should exempt admin paths from identity checks in trusted mode."""# Admin path with ROOT identity from default