feat(api-key): 增加 API Key 创建数量与频率限制

- 新增 api_key_create.max_active_per_user(默认 200)与
  api_key_create.max_per_user_per_hour(默认 20),0 表示不限制
- 创建频率按固定一小时窗口统计,自定义与自动生成的 Key 统一计入
- 创建计数独立于 Key 生命周期,删除或修改 Key 不再重置计数
- 移除不再使用的 DeleteCreateAttemptCount 缓存方法
This commit is contained in:
shaw
2026-09-30 13:44:02 +08:00
parent a0f41f95a0
commit 9ecb340822
12 changed files with 302 additions and 48 deletions
+13
View File
@@ -717,6 +717,19 @@ api_key_auth_cache:
# 每进程最多跟踪的客户端身份数量,确保内存有界。
capacity: 16384
# =============================================================================
# API Key Creation Limits
# 用户创建 API Key 的防滥用限制(0 表示不限制)
# =============================================================================
api_key_create:
# Maximum non-deleted API keys per user
# 单个用户同时存在(未删除)的 API Key 上限
max_active_per_user: 200
# Maximum API key creations per user per hour (custom and generated keys).
# Deleting a key does not refund the count, which blocks delete/recreate loops.
# 单个用户每小时可创建的 API Key 次数(自定义与自动生成均计入);删除 Key 不返还次数,阻断删建循环
max_per_user_per_hour: 20
# =============================================================================
# Dashboard Cache Configuration
# 仪表盘缓存配置