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
@@ -5779,15 +5779,23 @@ export default {
apiKeyNameRequired: "API Key 이름을 입력하세요",
toggleApiKeyVisible: "API Key 표시 또는 숨기기",
apiKeyAccessRole: "접근 역할",
apiKeyAccessRoleHint: "워크스페이스 멤버 역할과 동일하며, 요청 시 선택한 역할로 인증됩니다.",
accessRoleViewer: "뷰어",
accessRoleContributor: "편집",
accessRoleAdmin: "관리자",
apiKeyAccessType: "접근 유형",
apiKeyAccessTypeHint: "\"지식베이스\"는 아래 권한 수준에 따라 지식베이스 범위 내에서 작동합니다. \"테넌트 전체 접근\"은 모델, 데이터 소스 등 모든 테넌트 수준 API를 추가로 사용할 수 있습니다.",
accessTypeKnowledgeBase: "지식베이스",
accessTypeTenantFull: "테넌트 전체 접근",
apiKeyPermissionLevel: "권한 수준",
apiKeyAccessRoleHint: "앞의 세 역할은 지식베이스 범위 내 작업으로 제한되며, \"테넌트 전체 접근\"은 모델, 데이터 소스 등 테넌트 수준 API도 추가로 사용할 수 있습니다.",
accessRoleViewer: "지식베이스 읽기",
accessRoleContributor: "지식베이스 읽기·쓰기",
accessRoleAdmin: "지식베이스 관리자",
accessRoleOwner: "테넌트 전체 접근",
accessRoleViewerDesc: "조회, 검색 및 대화만 가능하며 지식베이스 내용은 수정하지 않습니다.",
accessRoleContributorDesc: "선택한 범위 내에서 지식베이스 콘텐츠를 생성, 수정 또는 삭제합니다.",
accessRoleAdminDesc: "테넌트 수준 설정 및 통합을 관리합니다. API Key 생성, 교체 또는 삭제는 불가합니다.",
accessRoleAdminDesc: "선택한 범위 내에서 지식베이스를 관리하며, 지식베이스 비우기 등 파괴적 작업을 포함합니다. 테넌트 수준 설정은 다루지 않습니다.",
accessRoleOwnerDesc: "전체 접근, 테넌트 소유자와 동일: 모델, 벡터 스토어, 데이터 소스, 채널 등 모든 테넌트 수준 API를 호출할 수 있으며 지식베이스 범위의 제한을 받지 않습니다.",
apiKeyKnowledgeScope: "지식베이스 범위",
apiKeyKnowledgeScopePlaceholder: "비워 두면 모든 지식베이스 접근 허용",
apiKeyKnowledgeScopeOwnerHint: "소유자는 전체 접근 키이므로 지식베이스 범위가 적용되지 않습니다.",
allKnowledgeBases: "모든 지식베이스",
createdAt: "생성일",
actions: "작업",