feat: 重构控制面安全机制与分页规范

本次提交包含多项安全加固和体验优化:
1. 分离管理密钥与传输凭证,避免持 API Token 者伪造管理员票据
2. 钉钉回调地址增加白名单校验,防止开放重定向钓鱼
3. 初始管理员密码改为随机生成并日志记录,移除硬编码 123456
4. 新增登录防爆破计数表,支持 MySQL 多 worker 共享
5. 统一分页规范,新增 usePagedList composable 和 PagerBar 组件
6. 控制面 CORS 收敛为白名单,避免公网环境下任意站点跨域
7. 插件管理、凭证管理等列表接口支持分页和搜索
8. 强制初始密码修改,未改密前禁止使用管理功能
9. 定时任务触发被拒日志节流,避免授权失效时刷屏
10. 健康检查接口移除环境信息泄露,返回固定响应
This commit is contained in:
2026-09-23 15:19:54 +08:00
parent dd546fc07b
commit be1a2899ba
80 changed files with 9029 additions and 493 deletions
+14 -1
View File
@@ -18,6 +18,7 @@ X-API-Token 请求头。
"""
from __future__ import annotations
import logging
import os
import sys
from contextlib import asynccontextmanager
@@ -38,9 +39,16 @@ from controlplane.apis import meta as api_meta
from controlplane.apis import plugins as api_plugins
from controlplane.apis import schedules as api_schedules
_LOGGER = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
if not config.CONTROLPLANE_TOKEN:
# 内部凭证为空时客户端接口无鉴权(P0 安全债)。不阻断本地开发,但生产必须配置:
# 公网部署时请务必在 controlplane/.env 设置 CONTROLPLANE_TOKEN。
_LOGGER.error(
"CONTROLPLANE_TOKEN 未配置:全部客户端接口将无鉴权放行,生产环境禁止!")
_init_db()
_seed()
# 内网文件服务器离线监控:心跳超时判离线并钉钉告警管理员(daemon 线程)
@@ -49,7 +57,12 @@ async def lifespan(app: FastAPI):
app = FastAPI(title="37du 插件管理平台", lifespan=lifespan)
app.add_middleware(CORSMiddleware, allow_origins=["*"],
# CORS 收敛为白名单(原 allow_origins=["*"],控制面走公网时任何站点可跨域调接口)。
# 默认放行本地控制面前端(8090 静态站);公网/反代部署用 CORS_ALLOW_ORIGINS 配置实际来源。
_CORS_ORIGINS = [o.strip() for o in os.getenv(
"CORS_ALLOW_ORIGINS",
"http://127.0.0.1:8090,http://localhost:8090").split(",") if o.strip()]
app.add_middleware(CORSMiddleware, allow_origins=_CORS_ORIGINS,
allow_methods=["*"], allow_headers=["*"])
app.include_router(api_meta.router)