fix(api-keys): allow scoped file serve and ingest batch routes

Let tenant-wide retrieve keys serve tenant-bounded /files paths while
denying KB-restricted keys, declare knowledge batch write routes for
ingest-capable keys, and short-circuit ownership checks for API-key
principals already authorized by the gate and KB allow-list.
This commit is contained in:
wizardchen
2026-07-20 19:47:42 +08:00
committed by lyingbug
parent 23e606f570
commit d1cab68e3d
7 changed files with 271 additions and 36 deletions
+11
View File
@@ -314,6 +314,17 @@ func EvaluateOwnershipOrRole(
creatorID string,
lookupErr error,
) error {
// API-key principals are authorized solely by the APIKeyGate (route
// policy) plus the KB allow-list handlers enforce separately
// (requireTenantAPIKeyKnowledgeBase(s)). Ownership ("creator OR Admin+")
// is a human concept that never applies to a machine principal, so
// short-circuit here — exactly as RequireOwnershipOrRole does for the
// middleware form. Without this, a scoped key (synthesized as Viewer for
// legacy-guard compatibility) would be 403'd by the body-carried-KB
// ownership checks even though the gate + allow-list already admitted it.
if _, ok := types.TenantAPIKeyScopeFromContext(ctx); ok {
return nil
}
role := types.TenantRoleFromContext(ctx)
if role.HasPermission(min) {
return nil