fix(api-keys): harden scoped key auth after code review
Revoke existing keys on reset, unify scope enforcement, default empty scopes to read-only, map API key scopes to tenant roles, and remove dead key-generation helpers left over from the tenant api_key column removal.
This commit is contained in:
@@ -104,9 +104,6 @@ func (f *flowTenantSvc) DeleteTenant(context.Context, uint64) error { return nil
|
||||
func (f *flowTenantSvc) ListTenants(context.Context) ([]*types.Tenant, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (f *flowTenantSvc) UpdateAPIKey(context.Context, uint64) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
func (f *flowTenantSvc) ExtractTenantIDFromAPIKey(string) (uint64, error) { return 0, nil }
|
||||
func (f *flowTenantSvc) ListAllTenants(context.Context) ([]*types.Tenant, error) {
|
||||
return nil, nil
|
||||
|
||||
@@ -537,7 +537,7 @@ func (h *TenantHandler) UpdateTenant(c *gin.Context) {
|
||||
|
||||
// ResetAPIKey godoc
|
||||
// @Summary 重置租户 API Key
|
||||
// @Description 为指定租户生成一个新的 API Key,旧 Key 立即失效
|
||||
// @Description 吊销该租户全部现有 API Key 后创建一把新的全权限 Key
|
||||
// @Tags 租户管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -562,6 +562,11 @@ func (h *TenantHandler) ResetAPIKey(c *gin.Context) {
|
||||
c.Error(errors.NewInternalServerError("API key service is not configured"))
|
||||
return
|
||||
}
|
||||
if err := h.apiKeyService.RevokeAllAPIKeys(ctx, id); err != nil {
|
||||
logger.ErrorWithFields(ctx, err, map[string]interface{}{"tenant_id": id})
|
||||
c.Error(errors.NewInternalServerError("Failed to reset API key").WithDetails(err.Error()))
|
||||
return
|
||||
}
|
||||
result, err := h.apiKeyService.CreateAPIKey(ctx, interfaces.TenantAPIKeyCreateRequest{
|
||||
TenantID: id,
|
||||
Name: "Tenant API key",
|
||||
|
||||
@@ -43,7 +43,6 @@ func (s *stubTenantService) ListAllTenants(context.Context) ([]*types.Tenant, er
|
||||
func (s *stubTenantService) SearchTenants(context.Context, string, uint64, int, int) ([]*types.Tenant, int64, error) {
|
||||
return nil, 0, nil
|
||||
}
|
||||
func (s *stubTenantService) UpdateAPIKey(context.Context, uint64) (string, error) { return "", nil }
|
||||
func (s *stubTenantService) ExtractTenantIDFromAPIKey(string) (uint64, error) { return 0, nil }
|
||||
func (s *stubTenantService) BulkSetStorageQuota(context.Context, int64) (int64, error) {
|
||||
return 0, nil
|
||||
|
||||
Reference in New Issue
Block a user