app_audit/README.md
yumoqing 6bcc1469eb feat: app_audit 审计日志全局模块(独立仓库)
- audit_service.py: audit_log 写入 + is_audit_role + list/backup/delete
- init.py: load_app_audit 建 sd_audit_logs 表 + owner.audit 角色
- audit.dspy: list/backup/delete 仅 owner.audit(审计独立性)
- models + load_path.py + README
2026-08-14 12:19:38 +08:00

51 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# app_audit - 审计日志全局模块
独立设计的全局审计模块。审计日志 append-only查看/备份/删除权限仅赋予
`owner.audit` 角色(审计独立性:`owner.superuser` 也无权访问,防管理员删自己的记录)。
## 结构
```
app_audit/
├── app_audit/
│ ├── __init__.py # 导出 audit_log / is_audit_role 等
│ ├── audit_service.py # 核心逻辑
│ └── init.py # load_app_audit建表 + owner.audit 角色)
├── models/
│ └── sd_audit_logs.json
├── wwwroot/
│ └── api/audit.dspy # list/backup/delete仅 owner.audit
└── scripts/load_path.py # RBAC 权限注册
```
## 审计事件清单action 取值)
- 认证:`login` / `login_fail` / `logout`
- 权限:`role_change` / `perm_change` / `user_role_change`
- 工作环境:`work_env_set` / `org_key_gen` / `remote_bwrap`
- 部署账号:`account_create` / `account_remove` / `sandbox_run`
- 用户机构:`user_create` / `user_disable` / `user_delete` / `org_change`
- 审计自身:`audit_delete` / `audit_backup`
## 接入
宿主应用在 `init()` 里调用:
```python
from app_audit.init import load_app_audit
load_app_audit()
```
其他模块在关键操作时写入审计:
```python
from app_audit import audit_log
await audit_log(sor, user_id, username, "work_env_set", target=..., detail=..., result="ok")
```
## 权限隔离
- `owner.audit` 角色:查看/备份/删除审计日志的唯一角色
- `owner.superuser` 也无权访问(审计独立性)
- `audit_delete` 留痕记录永不删除(防自删)