refactor(api-keys): use role field and route-level API key guards
Replace scopes JSON with a viewer/contributor/admin role column, move unsafe-method authorization from path-prefix middleware to declarative APIKey* guards on routes, and close remaining KB-scope gaps in handlers.
This commit is contained in:
@@ -2439,14 +2439,7 @@ func requireTenantAPIKeyKnowledgeBase(ctx context.Context, kbID string) error {
|
||||
}
|
||||
|
||||
func requireTenantAPIKeyKnowledgeBases(ctx context.Context, kbIDs ...string) error {
|
||||
scope, ok := types.TenantAPIKeyScopeFromContext(ctx)
|
||||
if !ok || !scope.IsKnowledgeBaseRestricted() {
|
||||
return nil
|
||||
}
|
||||
if !scope.AllowsKnowledgeBases(kbIDs) {
|
||||
return errors.NewForbiddenError("API key scope does not allow one or more knowledge bases")
|
||||
}
|
||||
return nil
|
||||
return types.AuthorizeTenantAPIKeyKnowledgeBases(ctx, kbIDs...)
|
||||
}
|
||||
|
||||
func tenantAPIKeyAllowedKBSet(ctx context.Context) map[string]bool {
|
||||
|
||||
Reference in New Issue
Block a user