feat: 新增管理后台前端项目及安全加固
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
refactor(saas): 重构认证中间件与限流策略
- 登录限流调整为5次/分钟/IP
- 注册限流调整为3次/小时/IP
- GET请求不计入限流
fix(saas): 修复调度器时间戳处理
- 使用NOW()替代文本时间戳
- 兼容TEXT和TIMESTAMPTZ列类型
feat(saas): 实现环境变量插值
- 支持${ENV_VAR}语法解析
- 数据库密码支持环境变量注入
chore: 新增前端管理界面
- 基于React+Ant Design Pro
- 包含路由守卫/错误边界
- 对接58个API端点
docs: 更新安全加固文档
- 新增密钥管理规范
- 记录P0安全项审计结果
- 补充TLS终止说明
test: 完善配置解析单元测试
- 新增环境变量插值测试用例
This commit is contained in:
@@ -5,6 +5,7 @@ use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::time::Instant;
|
||||
use tokio::sync::RwLock;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use crate::config::SaaSConfig;
|
||||
use crate::workers::WorkerDispatcher;
|
||||
|
||||
@@ -27,10 +28,12 @@ pub struct AppState {
|
||||
rate_limit_rpm: Arc<AtomicU32>,
|
||||
/// Worker 调度器 (异步后台任务)
|
||||
pub worker_dispatcher: WorkerDispatcher,
|
||||
/// 优雅停机令牌 — 触发后所有 SSE 流和长连接应立即终止
|
||||
pub shutdown_token: CancellationToken,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(db: PgPool, config: SaaSConfig, worker_dispatcher: WorkerDispatcher) -> anyhow::Result<Self> {
|
||||
pub fn new(db: PgPool, config: SaaSConfig, worker_dispatcher: WorkerDispatcher, shutdown_token: CancellationToken) -> anyhow::Result<Self> {
|
||||
let jwt_secret = config.jwt_secret()?;
|
||||
let rpm = config.rate_limit.requests_per_minute;
|
||||
Ok(Self {
|
||||
@@ -42,6 +45,7 @@ impl AppState {
|
||||
totp_fail_counts: Arc::new(dashmap::DashMap::new()),
|
||||
rate_limit_rpm: Arc::new(AtomicU32::new(rpm)),
|
||||
worker_dispatcher,
|
||||
shutdown_token,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -55,9 +59,10 @@ impl AppState {
|
||||
self.rate_limit_rpm.store(rpm, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// 清理过期的限流条目 (60 秒窗口外的记录)
|
||||
/// 清理过期的限流条目
|
||||
/// 使用 3600s 窗口以覆盖 register rate limit (3次/小时) 的完整周期
|
||||
pub fn cleanup_rate_limit_entries(&self) {
|
||||
let window_start = Instant::now() - std::time::Duration::from_secs(60);
|
||||
let window_start = Instant::now() - std::time::Duration::from_secs(3600);
|
||||
self.rate_limit_entries.retain(|_, entries| {
|
||||
entries.retain(|&ts| ts > window_start);
|
||||
!entries.is_empty()
|
||||
|
||||
Reference in New Issue
Block a user