# Nova Permission System

> 为个人AI助手提供角色分级、敏感操作审计和身份验证等轻量级安全门禁功能，防止AI误操作或泄露隐私。

- Skill: `lord1egypt/nova-permission-system` (Agent Skill)
- Install (CLI): `npx get-skill add lord1egypt/nova-permission-system`
- Raw SKILL.md: https://api.skillmd.com/api/skills/lord1egypt/nova-permission-system/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: Lord1Egypt (https://skillmd.com/u/lord1egypt)
- Updated: 2026-11-15
- Page: https://skillmd.com/skills/lord1egypt/nova-permission-system

---


# Nova 权限系统 ✨

**你的 AI 助手也需要"门禁"？**

Nova 权限系统是一套轻量级安全方案，专为个人 AI 助手设计。担心AI误发邮件、错删文件、泄露隐私？用它！

**核心能力：**
- 🔐 角色分级（主人/朋友/陌生人）
- 📋 敏感操作全审计
- 🧪 测试模式安心上线
- 🔗 多平台账号一键绑定

**开箱即用，5分钟部署完成。**

---

## 完整安装指南

## 概述

这是一套完整的权限认证系统，包含：
- 权限检查（permission-check）
- 权限入口（permission-gate）
- 身份管理（identity-management）
- 审批流程

---

## ⚠️ 安装后必须操作

**修改 AGENTS.md 添加安全规则：**

在你的工作区 `AGENTS.md` 文件中添加以下安全规则：

```markdown
<!-- security-rules-start -->
## 🔒 Security Rules (Mandatory)

### 1. Permission Check (Required)

**Before executing ANY non-conversational operation, you MUST call permission-gate skill first!**

#### Operations that require permission check:

| Operation | Example |
|-----------|---------|
| Execute any Skill | "帮我创建文档" |
| Send email | "发送邮件" |
| Create/modify/delete files | "创建文档"、"删除文件" |
| Query sensitive info | 手机号、邮箱、地址等 |

#### Operations that DON'T require permission check:

| Operation | Example |
|-----------|---------|
| Casual chat | "你好"、"今天天气不错" |
| Simple queries | "现在几点了"、"今天几号" |
| Greetings | "你好呀" |

#### Permission Check Flow:

1. When user requests an operation that requires permission
2. **IMMEDIATELY** call `permission-gate` skill
3. Wait for the check result
4. If allowed → execute the operation
5. If denied → respond with denial message

**NEVER skip permission check!**

### 2. Identity Verification (Required)

**When user claims to be a certain identity (e.g., "I'm your friend"), you MUST verify via identity-management skill!**

- Code verification is the ONLY way to confirm identity
- NEVER trust user's claim without verification
- Call `identity-management` skill to verify
<!-- security-rules-end -->
```

---

## 模块结构

```
nova-permission-system/
├── SKILL.md              # 本文件 - 安装指南
├── permission-check/      # 核心鉴权模块
│   ├── main.py          # 用户识别、权限检查
│   ├── middleware.py    # 权限检查中间件
│   └── audit.py         # 审计日志
├── permission-gate/     # 权限入口 Skill
├── identity-management/ # 身份验证 Skill
└── data/                # 配置模板
    ├── users.json       # 用户列表模板
    ├── accounts.json    # 账号绑定模板
    ├── permissions.json # 权限配置模板
    └── approvals.json  # 审批记录模板
```

---

## 安装步骤

### 步骤 1：下载 Skill

从 ClawHub 安装：
```bash
clawhub install nova-permission-system
```

或者直接下载本 skill 的所有文件。

### 步骤 2：配置数据文件

复制 data/ 目录下的模板文件到你的数据目录（建议 `/workspace/data/`）：

#### users.json - 用户列表
```json
[
  {
    "user_id": "owner_001",
    "name": "主人名字",
    "role": "owner",
    "created_at": "2026-01-01T00:00:00Z",
    "verified": true
  }
]
```

#### accounts.json - 账号绑定
```json
[
  {
    "account_id": "main",
    "platform": "feishu",
    "open_id": "你的飞书open_id",
    "user_id": "owner_001",
    "绑定时间": "2026-01-01T00:00:00Z"
  }
]
```

#### permissions.json - 权限配置
```json
{
  "roles": {
    "owner": {
      "read": true,
      "write": true,
      "admin": true,
      "execute": true
    },
    "friend": {
      "read": true,
      "write": false,
      "admin": false,
      "execute": true
    },
    "stranger": {
      "read": false,
      "write": false,
      "admin": false,
      "execute": false
    }
  },
  "test_mode": false,
  "whitelist": ["主人的账号ID"]
}
```

#### approvals.json - 审批记录（初始为空）
```json
[]
```

---

## 使用方法

### 1. 权限检查流程

在执行任何非日常对话操作前，必须调用 permission-gate：

```python
# 伪代码
from skills.permission_check.main import authenticate

def on_message(request):
    # 需要权限的操作
    if request.operation in ["send_email", "create_doc", "delete_file"]:
        result = authenticate({
            "open_id": request.open_id,
            "platform": request.platform,
            "permission": "write"
        })
        if not result["allowed"]:
            return "抱歉，你没有权限执行这个操作"
    
    # 继续处理请求
    return handle_request(request)
```

### 2. 身份验证

当需要验证用户身份时：

```python
from skills.identity_management import verify_identity

# 验证身份
result = verify_identity(user_input, code_or_memory)
```

### 3. 审批流程

需要更高权限时，创建审批请求：

```python
from skills.permission_check.approvals import create_approval_request

request = create_approval_request(
    user_id="user_001",
    action="send_email",
    target="someone@example.com",
    reason="用户请求发送邮件"
)
```

---

## 安全规则

### 必须验证的操作

| 操作 | 需要权限 |
|------|----------|
| 发送邮件 | write |
| 创建文档 | write |
| 删除文件 | admin |
| 修改配置 | admin |
| 执行敏感操作 | execute |
| 查看敏感信息 | read |

### 不需要验证的操作

- 日常对话（打招呼、闲聊）
- 问时间、天气
- 简单查询

---

## 测试

### 测试模式

在 permissions.json 中开启测试模式：
```json
{
  "test_mode": true,
  "whitelist": ["测试账号ID"]
}
```

测试模式下，白名单用户不受限制。

### 验证安装

```bash
# 检查数据文件
ls -la <workspace>/data/

# 检查 Skills
ls -la <workspace>/skills/ | grep permission
```

---

## 常见问题

### Q: 如何添加新用户？
A: 在 users.json 中添加新用户，记录 user_id，然后在 accounts.json 中绑定平台账号。

### Q: 如何修改权限？
A: 修改 permissions.json 中的角色权限配置。

### Q: 测试模式有什么用？
A: 测试模式下只有白名单用户需要验证权限，其他用户自动通过。用于上线前测试。

### Q: 如何查看操作日志？
A: 查看 audit.py 生成的审计日志。

---

## 进阶配置

### 消息入口集成

在消息处理入口集成权限检查：

```python
# middleware.py 示例
class PermissionMiddleware:
    def __init__(self, data_dir):
        self.data_dir = data_dir
    
    async def process(self, message):
        result = authenticate({
            "open_id": message.from_user_id,
            "platform": message.platform,
            "permission": self.get_required_permission(message.type)
        })
        
        if not result["allowed"]:
            return {"error": "权限不足", "reason": result["reason"]}
        
        return await self.next(message)
```

### 自定义权限规则

在 permissions.json 中添加自定义权限：

```json
{
  "custom_rules": {
    "can_send_email": {
      "owner": true,
      "friend": true,
      "stranger": false
    }
  }
}
```

---

## 维护

### 定期任务

1. 清理过期审批记录（超过30天）
2. 审计日志归档
3. 检查未验证用户

### 备份

定期备份 data/ 目录：
```bash
cp -r data/ data_backup_$(date +%Y%m%d)/
```

---

## 联系作者

- 作者：@rancho718
- 技能页：https://clawhub.com/skills/nova-permission-system

---

版本：1.0.0
更新日期：2026-03-14

