refactor(api-keys): simplify authorization to a single-role gate

Redesign tenant API key authorization around one dimension (role) plus a
central default-deny gate, replacing the previous role + KB-scoped flag model.

- Add APIKeyGate as the single authority for API-key authorization: routes
  declare one policy (MinRole) via apiKeyGroup/apiKeyRoute helpers; undeclared
  routes are denied by default. JWT principals short-circuit the gate and the
  JWT-centric RBAC guards short-circuit for API-key principals.
- Roles: viewer/contributor/admin are knowledge-base data-plane only (KB scope
  is a pure downstream data filter); owner is a full-access tenant tier that
  unlocks tenant-level infrastructure routes and is required for every method.
- Drop the KBScoped policy flag and the KB-restricted-vs-tenant branching.
- Security hardening: never disclose HMAC secret (return presence only), abort
  writes on API-key encryption failure, deny KB-restricted keys on /files, and
  backfill legacy key hashes at startup instead of O(N) plaintext scans.
- Frontend: two-level create dialog (access type -> permission level), rename
  role labels to reflect actual scope, sync en/zh/ko/ru locales.
- Fix startup self-check false-positive on trailing-slash routes and normalize
  gin paths before comparison; add regression tests.
This commit is contained in:
wizardchen
2026-07-06 17:34:52 +08:00
committed by lyingbug
parent fedb6c3f7e
commit d2ffc1b973
26 changed files with 1045 additions and 500 deletions
+13 -5
View File
@@ -5768,15 +5768,23 @@ export default {
apiKeyNameRequired: 'Enter an API key name',
toggleApiKeyVisible: 'Show or hide API key',
apiKeyAccessRole: "Access role",
apiKeyAccessRoleHint: "Matches tenant member roles; requests are authorized by the selected role.",
accessRoleViewer: "Viewer",
accessRoleContributor: "Contributor",
accessRoleAdmin: "Admin",
apiKeyAccessType: "Access type",
apiKeyAccessTypeHint: "\"Knowledge base\" operates within the KB scope at the permission level below; \"Tenant full\" additionally unlocks every tenant-level API such as models and data sources.",
accessTypeKnowledgeBase: "Knowledge base",
accessTypeTenantFull: "Tenant full",
apiKeyPermissionLevel: "Permission level",
apiKeyAccessRoleHint: "The first three roles are limited to knowledge-base operations; \"Tenant Full\" also unlocks tenant-level APIs such as models and data sources.",
accessRoleViewer: "KB Read",
accessRoleContributor: "KB Write",
accessRoleAdmin: "KB Admin",
accessRoleOwner: "Tenant Full",
accessRoleViewerDesc: "Query, search, and chat without modifying knowledge-base content.",
accessRoleContributorDesc: "Create, update, or delete knowledge-base content within the selected scope.",
accessRoleAdminDesc: "Manage tenant-level settings and integrations; cannot create, rotate, or delete API keys.",
accessRoleAdminDesc: "Manage knowledge bases, including destructive operations like clearing a KB, within the selected scope; no tenant-level configuration.",
accessRoleOwnerDesc: "Full access, equivalent to a tenant owner: may call every tenant-level API (models, vector stores, data sources, channels, ...). Not limited by knowledge-base scope.",
apiKeyKnowledgeScope: 'Knowledge bases',
apiKeyKnowledgeScopePlaceholder: 'Leave empty to allow all knowledge bases',
apiKeyKnowledgeScopeOwnerHint: 'Owner is a full-access key; the knowledge-base scope does not apply to it.',
allKnowledgeBases: 'All knowledge bases',
createdAt: 'Created',
actions: 'Actions',