M0-04 Audit & Security 基础版 #4

Closed
opened 2026-05-22 21:00:15 +08:00 by wangdl · 2 comments
Owner

交付检查

  • Prisma migration — AdminAuditLog(riskLevel+reason) + SecurityEvent
  • MySQL
  • BullMQ 异步写入 — audit-logs 队列 + AuditLogProcessor
  • AdminAuditService — log() 异步,自动风险分级
  • Admin AAPI — GET /admin-api/audit-logs 分页筛选
  • Admin Web — /audit 审计日志页
  • 操作前后快照 — beforeJson/afterJson
  • SecurityEvent 安全事件视图 系统运维→安全事件
  • 审计日志归档策略 (暂不实施)
  • 安全事件自动检测 (暂不实施)

架构实施计划

写入链路

业务操作 -> AdminAuditService.log(input)
-> QueueService.add('audit-logs', data)
-> BullMQ Redis
-> AuditLogProcessor.process() -> Prisma -> MySQL

风险自动分级

操作类型 风险等级
delete/remove/purge/revoke critical
update/edit/disable/block high
create/add/import/upload medium
read/view/list low

已接入

  • Admin 登录/登出/失败 — admin-auth.service.ts
  • Admin CRUD — admin-users
  • 知识库删除 — admin-knowledge
  • 配置变更 — ConfigChangeLog 表
## 交付检查 - [x] Prisma migration — AdminAuditLog(riskLevel+reason) + SecurityEvent - [x] MySQL - [x] BullMQ 异步写入 — audit-logs 队列 + AuditLogProcessor - [x] AdminAuditService — log() 异步,自动风险分级 - [x] Admin AAPI — GET /admin-api/audit-logs 分页筛选 - [x] Admin Web — /audit 审计日志页 - [x] 操作前后快照 — beforeJson/afterJson - [x] SecurityEvent 安全事件视图 ✅ 系统运维→安全事件 - [x] 审计日志归档策略 (暂不实施) - [x] 安全事件自动检测 (暂不实施) --- ## 架构实施计划 ### 写入链路 业务操作 -> AdminAuditService.log(input) -> QueueService.add('audit-logs', data) -> BullMQ Redis -> AuditLogProcessor.process() -> Prisma -> MySQL ### 风险自动分级 | 操作类型 | 风险等级 | |------|------| | delete/remove/purge/revoke | critical | | update/edit/disable/block | high | | create/add/import/upload | medium | | read/view/list | low | ### 已接入 - Admin 登录/登出/失败 — admin-auth.service.ts - Admin CRUD — admin-users - 知识库删除 — admin-knowledge - 配置变更 — ConfigChangeLog 表
wangdl added this to the M0:后端基础能力与架构规范闭环(P0) milestone 2026-05-22 21:00:15 +08:00
wangdl self-assigned this 2026-05-22 21:00:15 +08:00
Author
Owner

E2E 测试通过

M0 E2E 测试已全部通过 — 28/28 tests passed,耗时 ~1.4s。

本 Issue 测试内容

GET /admin-api/audit-logs → 200 paginated items, 401 without token

运行方式

npm run test:e2e

测试架构

  • Mock 层: @prisma/client / ioredis / jose / @nestjs/bullmq
  • 无需本地 MySQL/Redis,纯 mock 轻量集成测试
  • 测试文件: test/m0.e2e-spec.ts
## ✅ E2E 测试通过 M0 E2E 测试已全部通过 — **28/28 tests passed**,耗时 ~1.4s。 ### 本 Issue 测试内容 GET /admin-api/audit-logs → 200 paginated items, 401 without token ### 运行方式 ```bash npm run test:e2e ``` ### 测试架构 - Mock 层: `@prisma/client` / `ioredis` / `jose` / `@nestjs/bullmq` - 无需本地 MySQL/Redis,纯 mock 轻量集成测试 - 测试文件: `test/m0.e2e-spec.ts`
Author
Owner

关闭

M0 基础设施已实现并被后续 M1-M7 具体 issue 覆盖。相关代码已在生产运行。

## 关闭 M0 基础设施已实现并被后续 M1-M7 具体 issue 覆盖。相关代码已在生产运行。
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/api-server#4
No description provided.