Files
2026-04-02 23:40:04 +08:00

45 lines
1.1 KiB
Markdown
Raw Permalink 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.
# 安全规则
## 数据安全
- SSH 密码必须加密存储(使用 Fernet 加密)
- 敏感信息通过环境变量配置
- 数据库连接使用 SSL
- 定期备份数据(90天历史记录)
**密码加密示例**
```python
from cryptography.fernet import Fernet
def encrypt_password(password: str, key: bytes) -> str:
f = Fernet(key)
return f.encrypt(password.encode()).decode()
def decrypt_password(encrypted: str, key: bytes) -> str:
f = Fernet(key)
return f.decrypt(encrypted.encode()).decode()
```
## 应用安全
- 所有 API 端点需要认证(除登录接口)
- 实现 CSRF 保护
- 输入验证使用 Pydantic
- SQL 注入防护(使用 ORM
- XSS 防护(前端转义)
- 实现速率限制
## 访问控制
- 基于 RBAC 的权限控制
- 数据级权限过滤(按区域/学校)
- 操作审计日志记录
- 设备信息变更需要审核
**权限级别**
- 超级管理员:所有权限
- 管理员:管理所有设备和用户
- 区域管理员:管理指定区域的设备
- 学校管理员:管理指定学校的设备
- 普通用户:只读权限