feat(api-keys): add platform-scoped API keys for control-plane automation

Introduce platform API keys with capability-based access to tenant management,
system settings, runtime queues, and audit logs, plus admin UI for key lifecycle
and system audit log viewing.
This commit is contained in:
wizardchen
2026-07-21 15:05:57 +08:00
committed by lyingbug
parent c695125dce
commit 23db592c4a
42 changed files with 2967 additions and 1083 deletions
+29
View File
@@ -171,6 +171,35 @@ func TestGateKBScopeDoesNotBlockDataPlane(t *testing.T) {
}
}
func TestGatePlatformOnlyPolicyRejectsTenantKeyBeforeFullAccess(t *testing.T) {
a := NewAPIKeyRouteAuthorizer()
a.Register(http.MethodGet, "/api/v1/system/admin/settings",
APIKeyRoutePolicy{PlatformOnly: true}.
WithCapability(types.APIKeyCapabilitySystemSettingsRead))
tenantFull := &types.TenantAPIKeyScope{FullAccess: true}
platform := &types.TenantAPIKeyScope{
ScopeType: types.APIKeyScopePlatform,
Capabilities: types.StringArray{string(types.APIKeyCapabilitySystemSettingsRead)},
}
if runGate(t, a, tenantFull, http.MethodGet, "/api/v1/system/admin/settings") {
t.Fatal("tenant full-access key must not enter a platform-only route")
}
if !runGate(t, a, platform, http.MethodGet, "/api/v1/system/admin/settings") {
t.Fatal("platform key with the required capability should pass")
}
withoutCapability := NewAPIKeyRouteAuthorizer()
withoutCapability.Register(http.MethodGet, "/api/v1/system/admin/unsafe",
APIKeyRoutePolicy{PlatformOnly: true})
corruptPlatformFull := &types.TenantAPIKeyScope{
ScopeType: types.APIKeyScopePlatform,
FullAccess: true,
}
if runGate(t, withoutCapability, corruptPlatformFull, http.MethodGet, "/api/v1/system/admin/unsafe") {
t.Fatal("platform-only policy without an explicit capability must fail closed")
}
}
// runDenyAPIKey mounts DenyAPIKeyPrincipal ahead of a handler and reports
// whether the request reached the handler.
func runDenyAPIKey(t *testing.T, scope *types.TenantAPIKeyScope) (reached bool, status int) {