Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(auth): stop issuing personal keys in trusted mode (#5946)

Qin Haojie34187bc0ca02
diff --git a/docs/en/api/08-admin.md b/docs/en/api/08-admin.md
index b8c1355de..628ccc24f 100644
--- a/docs/en/api/08-admin.md
+++ b/docs/en/api/08-admin.md
@@ -23,7 +23,7 @@ For `/api/v1/admin/*`, `trusted` mode permits requests with no explicit identity
| Register/remove users | Y | Y (own account) | N |
| Manage groups and membership | Y | Y (own account) | N |
| List agents (deprecated, returns empty list) | Y | Y (own account) | N |
-| Regenerate user key | Y | Y (own account) | N |
+| Regenerate user key (API Key mode only) | Y | Y (own account) | N |
| Promote user to ADMIN | Y | Y (own account) | N |
## CLI `--sudo` Option
@@ -956,7 +956,7 @@ Create a new workspace with its first admin user.
| settings | object | No | `null` | Initial Account runtime configuration. ROOT-only; supports `feishu`, `github`, `acl`, `agent_evolution`, `vlm`, `query_planner`, `embedding`, and `vectordb`. `vectordb` and Embedding create-only fields can only be set here |
**Notes:**
-- In `trusted` mode, `user_key` is omitted from the response
+- In `trusted` mode, only identity and role are created: no personal key, hash, or key index is generated. The response omits `user_key`, and `seed` is unused.
- Omit `seed` for the default random API key. Set `OV_KEY_SEED` to a securely generated secret before running a deterministic example; the Go example also requires `import "os"`. Short or predictable seeds make the key guessable.
- `settings` receives structural and effective Embedding/VectorDB pair validation before the Account and its directories are created. A failed validation leaves no Account, user, or configuration file.
- Account `vlm`, `query_planner`, `embedding`, and `vectordb` are ROOT-only. See [Account Configuration Reference](#account-configuration-reference) above for their schema, lifecycle, and validation. The current Python SDK, CLI, and other SDK Account-creation wrappers do not expose a `settings` argument; use the HTTP API for this capability.
@@ -1355,7 +1355,7 @@ Register a new user in a workspace.
| user_config | object | No | `null` | Initial config for the new user. Supports `add_targets.resource_uri`, `add_targets.skill_uri`, and `memory_policy` |
**Notes:**
-- In `trusted` mode, `user_key` is omitted from the response
+- In `trusted` mode, only identity and role are created: no personal key, hash, or key index is generated. The response omits `user_key`, and `seed` is unused.
- Omit `seed` for the default random API key. Set `OV_KEY_SEED` to a securely generated secret before running a deterministic example; the Go example also requires `import "os"`. Short or predictable seeds make the key guessable.
- ADMIN can only register users in their own account
- The `"root"` role cannot be minted through user registration
@@ -1807,6 +1807,7 @@ Generate and store a user API key. With the default random generation, the old k
| seed | str | No | `null` | Optional deterministic API key seed in the JSON request body. When set, the key secret is `sha256(user_id + "\0" + seed)` |
**Notes:**
+- `trusted` mode rejects this operation with HTTP 412 (`FAILED_PRECONDITION`) without generating or modifying credentials.
- ADMIN can only regenerate keys for users in their own account
- With random generation or a new seed, the old key stops working immediately; update clients that use it
- Omit `seed` for the default random regenerated key. Deterministic examples use `OV_KEY_SEED` or `OV_NEW_KEY_SEED`; set these to a securely generated secret before use. In Go, import `os`. Do not use the example variable names as seed values.
diff --git a/docs/en/guides/04-authentication.md b/docs/en/guides/04-authentication.md
index c0c518785..9622ccd2b 100644
--- a/docs/en/guides/04-authentication.md
+++ b/docs/en/guides/04-authentication.md
@@ -506,7 +506,9 @@ curl https://openviking.example.com/api/v1/fs/ls?uri=viking:// \
## Trusted Mode
-Trusted mode requires a root API key to authenticate the upstream and uses explicit identity headers instead of user-key lookup:
+Trusted mode manages user identities and roles without personal credentials. Creating accounts (including the first administrator) or users generates no personal key, hash, or key index. Resetting a personal key returns HTTP 412 (`FAILED_PRECONDITION`). Studio can select users without personal keys; Bot authenticates with the deployment root key and sends user identity separately. Existing personal keys are not automatically deleted and are not used for trusted authentication.
+
+Trusted mode skips user-key lookup and instead trusts explicit identity headers on each request:
```json
{
diff --git a/docs/zh/api/08-admin.md b/docs/zh/api/08-admin.md
index 680ecd75c..5ca2c911e 100644
--- a/docs/zh/api/08-admin.md
+++ b/docs/zh/api/08-admin.md
@@ -23,7 +23,7 @@ Admin API 用于多租户环境下的账户、用户和用户组管理。包括
| 注册/移除用户 | Y | Y(本 account) | N |
| 管理用户组和成员 | Y | Y(本 account) | N |
| 列出 agents(已废弃,返回空列表) | Y | Y(本 account) | N |
-| 重新生成 User Key | Y | Y(本 account) | N |
+| 重新生成 User Key(仅 API Key 模式) | Y | Y(本 account) | N |
| 将用户提升为 ADMIN | Y | Y(本 account) | N |
## CLI `--sudo` 选项
@@ -827,7 +827,7 @@ User override 并重新继承上述默认值,请 PATCH `{"memory_policy": null
| settings | object | 否 | `null` | Account 运行时初始配置。仅 ROOT 可提交;支持 `feishu`、`github`、`acl`、`agent_evolution`、`vlm`、`query_planner`、`embedding` 和 `vectordb`。其中 `vectordb` 及 Embedding 创建期字段只能在这里设置 |
**说明:**
-- 在 `trusted` 模式下,响应中不会包含 `user_key` 字段
+- 在 `trusted` 模式下,只创建身份和角色,不生成个人密钥、密钥哈希或密钥索引;响应不包含 `user_key`,`seed` 不参与处理。
- 省略 `seed` 时随机生成 API Key。运行确定性示例前,将 `OV_KEY_SEED` 设为安全生成的秘密值;Go 示例还需导入 `os`。不要使用短字符串或可预测内容作为 seed。
- `settings` 在账号和目录创建前完成结构与有效 Embedding/VectorDB 联合校验。校验失败不会留下 Account、用户或配置文件。
- Account `vlm`、`query_planner`、`embedding` 和 `vectordb` 是 ROOT-only 配置;字段 schema、生命周期和校验见上文 [Account Configuration 接口参考](#account-configuration-接口参考)。当前 Python SDK、CLI 及其他 SDK 的创建账号封装尚未暴露 `settings` 参数,使用此能力请直接调用 HTTP API。
@@ -1224,7 +1224,7 @@ ov --sudo task status <task_id>
| user_config | object | 否 | `null` | 新用户的初始配置。支持 `add_targets.resource_uri`、`add_targets.skill_uri` 和 `memory_policy` |
**说明:**
-- 在 `trusted` 模式下,响应中不会包含 `user_key` 字段
+- 在 `trusted` 模式下,只创建身份和角色,不生成个人密钥、密钥哈希或密钥索引;响应不包含 `user_key`,`seed` 不参与处理。
- 省略 `seed` 时随机生成 API Key。运行确定性示例前,将 `OV_KEY_SEED` 设为安全生成的秘密值;Go 示例还需导入 `os`。不要使用短字符串或可预测内容作为 seed。
- ADMIN 只能在自己所属的 account 中注册用户
- 无法通过用户注册接口直接创建 `"root"` 角色
@@ -1675,6 +1675,7 @@ ov --sudo admin set-role acme bob admin
| seed | str | 否 | `null` | JSON request body 中可选的确定性 API Key seed。传入后,key secret 为 `sha256(user_id + "\0" + seed)` |
**说明:**
+- `trusted` 模式拒绝此操作,返回 HTTP 412(`FAILED_PRECONDITION`),不生成或修改密钥。
- ADMIN 只能为自己所属的 account 中的用户重新生成密钥
- 随机生成或使用新 seed 时,旧密钥立即失效,需要更新使用该密钥的客户端
- 省略 `seed` 时随机生成新密钥。确定性示例使用 `OV_KEY_SEED` 或 `OV_NEW_KEY_SEED`,运行前需将其设为安全生成的秘密值;Go 示例需导入 `os`。不要把示例变量名直接当作 seed。
diff --git a/docs/zh/guides/04-authentication.md b/docs/zh/guides/04-authentication.md
index 1a940281b..2e03456c7 100644
--- a/docs/zh/guides/04-authentication.md
+++ b/docs/zh/guides/04-authentication.md
@@ -445,6 +445,8 @@ rank 用于降权检查,不会继承 ADMIN 的接口权限。`require_role()`
### Trusted 模式
+Trusted 模式只管理用户身份和角色。创建账号(包括首个管理员)和创建用户都不生成个人密钥、哈希或密钥索引;重置个人密钥返回 HTTP 412(`FAILED_PRECONDITION`)。Studio 可选择没有个人密钥的用户;Bot 使用部署配置的 root key 认证,并单独传递用户身份。已有个人密钥不会被自动删除,也不用于 trusted 认证。
+
trusted 模式的普通数据面请求无需预先注册 user 或创建 user API Key。服务端会异步批量注册
该 account/user,使其最终出现在既有 account/user 管理接口中(默认五分钟刷盘)。注册不会
创建 user API Key,也不会修改 group 或已有 user 的角色。设置
diff --git a/openviking/server/api_keys/new.py b/openviking/server/api_keys/new.py
index cebd2e7d0..2e05161df 100644
--- a/openviking/server/api_keys/new.py
+++ b/openviking/server/api_keys/new.py
@@ -94,6 +94,8 @@ class NewAPIKeyManager:
root_key: str,
viking_fs: VikingFS,
api_key_hashing_enabled: bool = False,
+ *,
+ issue_user_keys: bool = True,
):
"""Initialize NewAPIKeyManager.
@@ -102,7 +104,9 @@ class NewAPIKeyManager:
viking_fs: VikingFS client for persistent storage of user keys.
api_key_hashing_enabled: Whether API key Argon2id hashing is enabled.
Default: false - rely on file-level AES encryption for protection.
+ issue_user_keys: Whether this auth plugin issues personal credentials.
"""
+ self._issue_user_keys = issue_user_keys
# Delegate to legacy manager for all core functionality
self._legacy = LegacyAPIKeyManager(
root_key, viking_fs, api_key_hashing_enabled=api_key_hashing_enabled
@@ -195,12 +199,36 @@ class NewAPIKeyManager:
# Fall back to legacy resolver for legacy keys
return self._legacy.resolve(api_key)
+ def _issue_user_key(
+ self, account_id: str, user_id: str, user_info: dict, seed: Optional[str]
+ ) -> str:
+ """Generate, store and index one personal credential."""
+ key = generate_api_key(account_id, user_id, seed)
+ is_hashed = self._legacy._api_key_hashing_enabled
+ stored_key = self._legacy._hash_api_key(key) if is_hashed else key
+ prefix = self._legacy._get_key_prefix(key)
+ user_info["key"] = stored_key
+ if is_hashed:
+ user_info["key_prefix"] = prefix
+ else:
+ user_info.pop("key_prefix", None)
+ self._legacy._prefix_index.setdefault(prefix, []).append(
+ UserKeyEntry(
+ account_id=account_id,
+ user_id=user_id,
+ role=Role(user_info["role"]),
+ key_or_hash=stored_key,
+ is_hashed=is_hashed,
+ )
+ )
+ return key
+
async def create_account(
self,
account_id: str,
admin_user_id: str,
seed: Optional[str] = None,
- ) -> str:
+ ) -> str | None:
async with self._legacy.mutation_lock:
return await self._create_account_unlocked(account_id, admin_user_id, seed)
@@ -209,10 +237,10 @@ class NewAPIKeyManager:
account_id: str,
admin_user_id: str,
seed: Optional[str] = None,
- ) -> str:
+ ) -> str | None:
"""Create a new account (workspace) with its first admin user.
- Returns the admin user's API key in new format.
+ Returns the admin user's API key when personal credentials are enabled.
"""
# Validate account_id and user_id format
verr = validate_account_id(account_id)
@@ -222,13 +250,6 @@ class NewAPIKeyManager:
if verr:
raise InvalidArgumentError(verr)
- # Generate new format key
- key = generate_api_key(account_id, admin_user_id, seed)
-
- # Use legacy to create account but with our new key
- # We temporarily replace the generate method, call, then restore
- # Instead, we implement the create_account with new key format
-
# Check existence first
if account_id in self._legacy._accounts:
from openviking_cli.exceptions import AlreadyExistsError
@@ -240,21 +261,12 @@ class NewAPIKeyManager:
now = datetime.now(timezone.utc).isoformat()
- if self._legacy._api_key_hashing_enabled:
- stored_key = self._legacy._hash_api_key(key)
- is_hashed = True
- key_prefix = self._legacy._get_key_prefix(key)
- else:
- stored_key = key
- is_hashed = False
- key_prefix = self._legacy._get_key_prefix(key)
-
- user_info = {
- "role": "admin",
- "key": stored_key,
- }
- if self._legacy._api_key_hashing_enabled:
- user_info["key_prefix"] = key_prefix
+ user_info = {"role": "admin"}
+ key = (
+ self._issue_user_key(account_id, admin_user_id, user_info, seed)
+ if self._issue_user_keys
+ else None
+ )
# Add to legacy's data structures
self._legacy._accounts[account_id] = AccountInfo(
@@ -263,19 +275,6 @@ class NewAPIKeyManager:
groups={},
)
- entry = UserKeyEntry(
- account_id=account_id,
- user_id=admin_user_id,
- role=Role.ADMIN,
- key_or_hash=stored_key,
- is_hashed=is_hashed,
- )
-
- if key_prefix:
- if key_prefix not in self._legacy._prefix_index:
- self._legacy._prefix_index[key_prefix] = []
- self._legacy._prefix_index[key_prefix].append(entry)
-
account_was_created = False
try:
created_account_ids = await self._legacy._save_accounts_json(
@@ -311,7 +310,7 @@ class NewAPIKeyManager:
user_id: str,
role: str = "user",
seed: Optional[str] = None,
- ) -> str:
+ ) -> str | None:
async with self._legacy.mutation_lock:
return await self._register_user_unlocked(account_id, user_id, role, seed)
@@ -321,8 +320,8 @@ class NewAPIKeyManager:
user_id: str,
role: str = "user",
seed: Optional[str] = None,
- ) -> str:
- """Register a new user in an account. Returns the user's API key in new format."""
+ ) -> str | None:
+ """Register a user, issuing a personal credential only when enabled."""
resolved_role = validate_account_user_role(role)
# Validate user_id format
verr = validate_user_id(user_id)
@@ -341,39 +340,13 @@ class NewAPIKeyManager:
raise AlreadyExistsError(user_id, "user")
- # Generate new format key
- key = generate_api_key(account_id, user_id, seed)
-
- if self._legacy._api_key_hashing_enabled:
- stored_key = self._legacy._hash_api_key(key)
- is_hashed = True
- key_prefix = self._legacy._get_key_prefix(key)
- else:
- stored_key = key
- is_hashed = False
- key_prefix = self._legacy._get_key_prefix(key)
-
- user_info = {
- "role": resolved_role,
- "key": stored_key,
- }
- if self._legacy._api_key_hashing_enabled:
- user_info["key_prefix"] = key_prefix
-
- account.users[user_id] = user_info
-
- entry = UserKeyEntry(
- account_id=account_id,
- user_id=user_id,
- role=resolved_role,
- key_or_hash=stored_key,
- is_hashed=is_hashed,
+ user_info = {"role": resolved_role}
+ key = (
+ self._issue_user_key(account_id, user_id, user_info, seed)
+ if self._issue_user_keys
+ else None
)
-
- if key_prefix:
- if key_prefix not in self._legacy._prefix_index:
- self._legacy._prefix_index[key_prefix] = []
- self._legacy._prefix_index[key_prefix].append(entry)
+ account.users[user_id] = user_info
try:
await self._legacy._save_users_json(
@@ -458,6 +431,9 @@ class NewAPIKeyManager:
Generates new format key regardless of original format.
"""
+ if not self._issue_user_keys:
+ raise FailedPreconditionError("Personal API keys are disabled in trusted mode")
+
# Check account and user exist
self._legacy.ensure_account_active(account_id)
account = self._legacy._accounts.get(account_id)
@@ -473,55 +449,8 @@ class NewAPIKeyManager:
raise FailedPreconditionError("User deletion is in progress")
old_user_info = account.users[user_id]
- old_key_or_hash = old_user_info.get("key", "")
-
- # Get old key_prefix
- old_key_prefix = old_user_info.get("key_prefix", "")
- if not old_key_prefix and old_key_or_hash:
- old_key_prefix = self._legacy._get_key_prefix(old_key_or_hash)
-
- # Remove old key from prefix index
- if old_key_prefix in self._legacy._prefix_index:
- self._legacy._prefix_index[old_key_prefix] = [
- entry
- for entry in self._legacy._prefix_index[old_key_prefix]
- if not (entry.account_id == account_id and entry.user_id == user_id)
- ]
- if not self._legacy._prefix_index[old_key_prefix]:
- del self._legacy._prefix_index[old_key_prefix]
-
- # Generate new key in new format
- new_key = generate_api_key(account_id, user_id, seed)
-
- if self._legacy._api_key_hashing_enabled:
- new_stored_key = self._legacy._hash_api_key(new_key)
- new_is_hashed = True
- new_key_prefix = self._legacy._get_key_prefix(new_key)
- else:
- new_stored_key = new_key
- new_is_hashed = False
- new_key_prefix = self._legacy._get_key_prefix(new_key)
-
- # Update user info
- account.users[user_id]["key"] = new_stored_key
- if self._legacy._api_key_hashing_enabled:
- account.users[user_id]["key_prefix"] = new_key_prefix
- else:
- if "key_prefix" in account.users[user_id]:
- del account.users[user_id]["key_prefix"]
-
- entry = UserKeyEntry(
- account_id=account_id,
- user_id=user_id,
- role=Role(account.users[user_id]["role"]),
- key_or_hash=new_stored_key,
- is_hashed=new_is_hashed,
- )
-
- if new_key_prefix:
- if new_key_prefix not in self._legacy._prefix_index:
- self._legacy._prefix_index[new_key_prefix] = []
- self._legacy._prefix_index[new_key_prefix].append(entry)
+ self._legacy._remove_key_index_entry(account_id, user_id, old_user_info)
+ new_key = self._issue_user_key(account_id, user_id, old_user_info, seed)
await self._legacy._save_users_json(account_id, {user_id: account.users[user_id]})
return new_key
@@ -561,7 +490,7 @@ class NewAPIKeyManager:
limit=limit,
name_filter=name_filter,
role_filter=role_filter,
- expose_key=expose_key,
+ expose_key=expose_key and self._issue_user_keys,
page=page,
)
@@ -580,7 +509,7 @@ class NewAPIKeyManager:
limit=limit,
name_filter=name_filter,
role_filter=role_filter,
- expose_key=expose_key,
+ expose_key=expose_key and self._issue_user_keys,
page=page,
query_filter=query_filter,
)
diff --git a/openviking/server/auth/plugins/trusted.py b/openviking/server/auth/plugins/trusted.py
index 7ce9607a7..f31c352a3 100644
--- a/openviking/server/auth/plugins/trusted.py
+++ b/openviking/server/auth/plugins/trusted.py
@@ -188,6 +188,7 @@ class TrustedAuthPlugin(AuthPlugin):
root_key=config.root_api_key,
viking_fs=service.viking_fs,
api_key_hashing_enabled=config.api_key_hashing_enabled,
+ issue_user_keys=False,
)
await api_key_manager.load()
self._api_key_manager = api_key_manager
diff --git a/tests/server/test_admin_api.py b/tests/server/test_admin_api.py
index 7dad658af..648afdc59 100644
--- a/tests/server/test_admin_api.py
+++ b/tests/server/test_admin_api.py
@@ -53,6 +53,10 @@ from openviking.session.memory.session_extract_context_provider import SessionEx
from openviking_cli.exceptions import OpenVikingError
from openviking_cli.session.user_id import UserIdentifier
from openviking_cli.utils.config import get_openviking_config
+from openviking_cli.utils.config.open_viking_config import (
+ OpenVikingConfig,
+ OpenVikingConfigSingleton,
+)
def _uid() -> str:
@@ -190,6 +194,7 @@ def _build_lightweight_admin_test_app() -> FastAPI:
@pytest_asyncio.fixture(scope="function")
async def lightweight_admin_app(monkeypatch):
+ monkeypatch.setattr(OpenVikingConfigSingleton, "_instance", OpenVikingConfig())
app = _build_lightweight_admin_test_app()
await app.state.fake_service.runtime_config_manager.initialize()
await app.state.api_key_manager.load()
@@ -3131,26 +3136,17 @@ async def test_session_storage_uses_canonical_uri(
@pytest_asyncio.fixture(scope="function")
-async def trusted_admin_app(admin_service):
+async def trusted_admin_app(lightweight_admin_app):
from openviking.server.auth.plugins import TrustedAuthPlugin
- from openviking.server.auth.registry import get_registry
-
- config = ServerConfig(auth_mode="trusted", root_api_key=ROOT_KEY)
- app = create_app(config=config, service=admin_service)
- set_service(admin_service)
- manager = APIKeyManager(root_key=ROOT_KEY, viking_fs=admin_service.viking_fs)
- await manager.load()
- # Create test users for trusted mode tests if they don't exist
- if "platform" not in manager._accounts:
- await manager.create_account("platform", "gateway-admin")
- app.state.api_key_manager = manager
-
- # Set auth plugin (lifespan not triggered in ASGI tests)
- registry = get_registry()
- if registry.get("trusted") is None:
- registry.register(TrustedAuthPlugin)
- app.state.auth_plugin = registry.get("trusted")()
+ app = lightweight_admin_app
+ config = ServerConfig(
+ auth_mode="trusted", root_api_key=ROOT_KEY, trusted_identity_flush_interval_seconds=0
+ )
+ app.state.config = config
+ app.state.auth_plugin = TrustedAuthPlugin()
+ await app.state.auth_plugin.initialize(app, app.state.fake_service, config)
+ await app.state.api_key_manager.create_account("platform", "gateway-admin")
return app
@@ -3186,11 +3182,20 @@ async def test_trusted_mode_root_can_create_account(
assert "user_key" not in body["result"]
[email protected]("hashing_enabled", [False, True])
async def test_trusted_mode_admin_can_register_user_in_own_account(
trusted_admin_client: httpx.AsyncClient,
trusted_admin_app,
+ monkeypatch,
+ hashing_enabled,
):
"""Trusted ADMIN requests should be able to manage users in their own account."""
+ manager = trusted_admin_app.state.api_key_manager
+ manager._legacy._api_key_hashing_enabled = hashing_enabled
+ monkeypatch.setattr(
+ "openviking.server.api_keys.new.generate_api_key",
+ Mock(side_effect=AssertionError("trusted must not generate personal credentials")),
+ )
acct = _uid()
create_resp = await trusted_admin_client.post(
"/api/v1/admin/accounts",
@@ -3217,6 +3222,18 @@ async def test_trusted_mode_admin_can_register_user_in_own_account(
assert resp.json()["result"]["user_id"] == "bob"
assert "user_key" not in resp.json()["result"]
+ before = deepcopy(manager._accounts[acct].users)
+ assert before == {"alice": {"role": "admin"}, "bob": {"role": "user"}}
+ response = await trusted_admin_client.post(
+ f"/api/v1/admin/accounts/{acct}/users/bob/key", headers=root_headers()
+ )
+ assert response.status_code == 412
+ assert response.json()["error"]["code"] == "FAILED_PRECONDITION"
+ assert response.json()["error"]["message"] == "Personal API keys are disabled in trusted mode"
+ await manager.reload()
+ assert manager._accounts[acct].users == before
+ assert manager._legacy._prefix_index == {}
+
async def test_trusted_mode_admin_can_list_users_with_account_only_in_url(
trusted_admin_client: httpx.AsyncClient,
diff --git a/web-studio/src/routes/users/route.tsx b/web-studio/src/routes/users/route.tsx
index c3ead79f8..97d47b458 100644
--- a/web-studio/src/routes/users/route.tsx
+++ b/web-studio/src/routes/users/route.tsx
@@ -774,32 +774,34 @@ export function UserManagementPanel() {
</TooltipContent>
</Tooltip>
) : null}
- <div className="ml-1 flex items-center border-l border-border/70 pl-1.5">
- <Tooltip>
- <TooltipTrigger
- render={
- <Button
- type="button"
- variant="ghost"
- size="icon-xs"
- aria-label={t('actions.regenerate')}
- onClick={() =>
- setPendingRegenerateUser(user)
- }
- disabled={
- regenerateKey.isPending ||
- Boolean(switchingIdentityKey)
- }
- />
- }
- >
- <RotateCwIcon />
- </TooltipTrigger>
- <TooltipContent>
- {t('actions.regenerate')}
- </TooltipContent>
- </Tooltip>
- </div>
+ {serverMode !== 'trusted' && (
+ <div className="ml-1 flex items-center border-l border-border/70 pl-1.5">
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon-xs"
+ aria-label={t('actions.regenerate')}
+ onClick={() =>
+ setPendingRegenerateUser(user)
+ }
+ disabled={
+ regenerateKey.isPending ||
+ Boolean(switchingIdentityKey)
+ }
+ />
+ }
+ >
+ <RotateCwIcon />
+ </TooltipTrigger>
+ <TooltipContent>
+ {t('actions.regenerate')}
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ )}
</div>
</TableCell>
<TableCell>
diff --git a/web-studio/src/routes/vikingbot/-api.test.ts b/web-studio/src/routes/vikingbot/-api.test.ts
index 5c026f8ad..e0f475cf2 100644
--- a/web-studio/src/routes/vikingbot/-api.test.ts
+++ b/web-studio/src/routes/vikingbot/-api.test.ts
@@ -61,14 +61,23 @@ it('keeps provider credential fields inside a generic envelope', () => {
body: { revision: 3, credentials, user_id: 'bot' },
})
})
-it('reuses the safe admin-user projection', async () => {
- transport.get.mockResolvedValue([{ user_id: 'bot', api_key_available: true }])
- expect(await getBotUsers()).toEqual([{ user_id: 'bot', available: true }])
- expect(transport.get).toHaveBeenCalledWith({
- url: '/api/v1/admin/accounts/team/users',
- query: { role: 'user', include_credentials: false },
- })
-})
+it.each(['api_key', 'trusted'] as const)(
+ 'selects users using the %s auth contract',
+ async (mode) => {
+ transport.get.mockResolvedValue([
+ { user_id: 'bot', api_key_available: true },
+ { user_id: 'keyless', api_key_available: false },
+ ])
+ expect(await getBotUsers(mode)).toEqual([
+ { user_id: 'bot', available: true },
+ { user_id: 'keyless', available: mode === 'trusted' },
+ ])
+ expect(transport.get).toHaveBeenCalledWith({
+ url: '/api/v1/admin/accounts/team/users',
+ query: { role: 'user', include_credentials: false },
+ })
+ },
+)
it('uses current account and encodes identifiers without moving conversation keys into paths', () => {
transport.accountId = 'team two'
getMessages('app/id', 'group/thread:topic', 7)
diff --git a/web-studio/src/routes/vikingbot/-api.ts b/web-studio/src/routes/vikingbot/-api.ts
index c7ae02b6f..8196574b1 100644
--- a/web-studio/src/routes/vikingbot/-api.ts
+++ b/web-studio/src/routes/vikingbot/-api.ts
@@ -1,4 +1,5 @@
import { getOvResult, ovClient } from '#/lib/ov-client'
+import type { ServerMode } from '#/hooks/use-server-mode'
export type Connection = {
id: string
@@ -128,7 +129,7 @@ export function rotateCredentials(
)
}
-export async function getBotUsers() {
+export async function getBotUsers(serverMode: ServerMode) {
const { accountId } = ovClient.getConnection()
if (!accountId) throw new Error('Select an account before managing bots')
const users = await getOvResult<
@@ -141,7 +142,7 @@ export async function getBotUsers() {
)
return users.map((user) => ({
user_id: user.user_id,
- available: user.api_key_available,
+ available: serverMode === 'trusted' || user.api_key_available,
}))
}
diff --git a/web-studio/src/routes/vikingbot/-components/runtime-user-select.tsx b/web-studio/src/routes/vikingbot/-components/runtime-user-select.tsx
index c8c6d0541..40b1e87c4 100644
--- a/web-studio/src/routes/vikingbot/-components/runtime-user-select.tsx
+++ b/web-studio/src/routes/vikingbot/-components/runtime-user-select.tsx
@@ -6,11 +6,11 @@ import { useAppConnection } from '#/hooks/use-app-connection'
import { getBotUsers } from '../-api'
export function useRuntimeUserSelection(enabled: boolean) {
- const { identityScopeKey } = useAppConnection()
+ const { identityScopeKey, serverMode } = useAppConnection()
const [userId, setUserId] = useState('')
const users = useQuery({
- queryKey: ['vikingbot', identityScopeKey, 'users'],
- queryFn: getBotUsers,
+ queryKey: ['vikingbot', identityScopeKey, serverMode, 'users'],
+ queryFn: () => getBotUsers(serverMode),
enabled,
retry: false,
})