前面的系列文章已经带你走过了 Hermes Agent 的绝大部分核心功能:从安装配置到技能系统,从多平台集成到多 Agent 编排,再到 Profiles 和 CredentialPools 的环境隔离。

安全配置与 Curator —— 命令审批、Secret 脱敏、技能自动维护

简介

前面的系列文章已经带你走过了 Hermes Agent 的绝大部分核心功能:从安装配置到技能系统,从多平台集成到多 Agent 编排,再到 Profiles 和 CredentialPools 的环境隔离。

但所有这些功能都指向同一个问题:

当 AI Agent 拥有了执行命令、读写文件、调用 API 的能力时,谁来确保它不做危险的事情?

这不是一个理论问题。让我们看几个真实场景:

text
┌─────────────────────────────────────────────────────────┐
│              安全事件场景                                  │
│                                                         │
│  场景一:误删文件                                          │
│  Agent 接到"清理临时文件"的任务                           │
│  执行了 rm -rf /tmp/*                                    │
│  但工作目录没有正确设置,实际执行了 rm -rf /*              │
│  → 系统被清空                                            │
│                                                         │
│  场景二:密钥泄露                                          │
│  Agent 在调试时输出了完整的配置文件                        │
│  日志中包含了数据库密码和 API 密钥                         │
│  日志被上传到了公开的日志聚合平台                          │
│  → 密钥泄露                                              │
│                                                         │
│  场景三:Skill 过期                                        │
│  一个 Skill 依赖的第三方 API 已更新                        │
│  Skill 脚本中的代码使用了已废弃的端点                      │
│  Agent 执行失败,但没有明确的错误提示                      │
│  → 任务静默失败                                          │
│                                                         │
│  场景四:资源耗尽                                          │
│  Agent 陷入了无限循环                                     │
│  不断调用 API,耗尽了月度配额                              │
│  账单暴涨                                                 │
│  → 经济损失                                              │
│                                                         │
└─────────────────────────────────────────────────────────┘

这些场景不是虚构的,它们是任何拥有系统执行能力的 AI Agent 都可能遇到的问题。

Hermes Agent 通过 安全配置系统Curator 系统 来解决这些问题:

  • 命令审批:危险命令需要人工确认才能执行
  • Secret 脱敏:输出中自动隐藏敏感信息
  • Curator 系统:自动维护 Skills,检测问题,推荐更新
  • 安全审计:完整的操作日志和异常检测

读完本文后,你将能够为 Hermes Agent 配置完善的安全防护,让 AI Agent 在受控的环境中安全、可靠地运行。

目录

安全配置概述

安全分层架构

text
┌─────────────────────────────────────────────────────────┐
│              Hermes Agent 安全分层                         │
│                                                         │
│  ┌─────────────────────────────────────────────────┐    │
│  │  Layer 4: 审计层                                 │    │
│  │  ├── 操作日志记录                                  │    │
│  │  ├── 异常行为检测                                  │    │
│  │  └── 安全事件告警                                  │    │
│  └─────────────────────────────────────────────────┘    │
│  ┌─────────────────────────────────────────────────┐    │
│  │  Layer 3: 资源层                                 │    │
│  │  ├── API 调用配额限制                              │    │
│  │  ├── 磁盘使用限制                                  │    │
│  │  ├── 内存/CPU 使用限制                             │    │
│  │  └── 网络访问控制                                  │    │
│  └─────────────────────────────────────────────────┘    │
│  ┌─────────────────────────────────────────────────┐    │
│  │  Layer 2: 数据层                                 │    │
│  │  ├── Secret 脱敏                                   │    │
│  │  ├── 文件操作保护                                  │    │
│  │  └── 敏感路径保护                                  │    │
│  └─────────────────────────────────────────────────┘    │
│  ┌─────────────────────────────────────────────────┐    │
│  │  Layer 1: 执行层                                 │    │
│  │  ├── 命令审批                                      │    │
│  │  ├── 危险命令拦截                                  │    │
│  │  └── 沙箱执行                                      │    │
│  └─────────────────────────────────────────────────┘    │
│                                                         │
│  从底层到顶层,层层防护                                  │
│                                                         │
└─────────────────────────────────────────────────────────┘

全局安全配置

yaml
# ~/.config/hermes/hermes.yaml
security:
  # ===== 命令审批 =====
  command_approval:
    enabled: true
    # 危险命令模式(需要审批)
    dangerous_patterns:
      - "rm -rf /"
      - "rm -rf /*"
      - "rm -rf ~"
      - "dd if="
      - "mkfs"
      - "format"
      - "chmod 777"
      - "chown root"
      - "sudo"
      - "curl.*\\|"         # curl 输出直接管道
      - "wget.*\\|"         # wget 输出直接管道
      - "eval"
      - "exec"
      - "source.*http"
      - "python.*-c.*import.*os"

    # 白名单(无需审批的命令)
    whitelist:
      - "ls"
      - "cat"
      - "echo"
      - "grep"
      - "find . -name"
      - "git status"
      - "git log"

    # 审批超时(秒)
    timeout: 300
    # 超时后的行为: deny | allow
    timeout_action: deny

  # ===== Secret 脱敏 =====
  secret_masking:
    enabled: true
    # 自动检测的模式
    auto_detect: true
    # 手动指定的模式
    patterns:
      - "sk-[a-zA-Z0-9]{20,}"        # OpenAI key
      - "ghp_[a-zA-Z0-9]{36}"         # GitHub token
      - "AKIA[0-9A-Z]{16}"            # AWS key ID
      - "password['\"]\\s*:\\s*['\"][^'\"]+" # 密码字段
    # 日志中隐藏
    mask_in_logs: true
    # API 响应中隐藏
    mask_in_responses: true

  # ===== 文件操作保护 =====
  file_protection:
    # 保护的目录
    protected_paths:
      - "/"
      - "/etc"
      - "/usr"
      - "/var"
      - "/root"
      - "/home"
    # 保护的模式
    protected_patterns:
      - "*.key"
      - "*.pem"
      - "*.p12"
      - ".env"
      - "*password*"
    # 写入确认
    require_write_confirmation: true
    # 单次最大写入文件大小(MB)
    max_write_size_mb: 10
    # 禁止写入的路径
    deny_write_paths:
      - "/etc/passwd"
      - "/etc/shadow"
      - "/etc/sudoers"

  # ===== 资源限制 =====
  resource_limits:
    # API 调用限制
    api_calls:
      max_per_hour: 100
      max_per_day: 1000
      # 达到限制后的行为
      on_limit: notify_and_stop

    # 磁盘使用限制
    disk:
      max_usage_mb: 1024
      # 临时文件自动清理
      auto_cleanup: true
      cleanup_after_days: 7

    # 执行时间限制
    execution:
      max_command_runtime_seconds: 300
      max_session_duration_hours: 8
      # 空闲超时
      idle_timeout_minutes: 30

命令审批系统

审批工作流程

text
┌─────────────────────────────────────────────────────────┐
│              命令审批流程                                  │
│                                                         │
│  Agent 决定执行命令: 
│  "rm -rf /tmp/build-cache"                              │
│              │                                           │
│              ▼                                           │
│  ┌─────────────────────────────────────────┐            │
│  │ 1. 命令匹配检查                           │            │
│  │    是否匹配 dangerous_patterns?          │            │
│  │    ✓ 匹配 "rm -rf" 模式                  │            │
│  └────────────────┬────────────────────────┘            │
│                   │                                     │
│                   ▼                                     │
│  ┌─────────────────────────────────────────┐            │
│  │ 2. 上下文分析                             │            │
│  │    - 目标路径是否安全? /tmp/build-cache  │            │
│  │    - 是否在 protected_paths 中?否        │            │
│  │    - 是否有通配符风险? 否                │            │
│  └────────────────┬────────────────────────┘            │
│                   │                                     │
│                   ▼                                     │
│  ┌─────────────────────────────────────────┐            │
│  │ 3. 风险评分                               │            │
│  │    基础分: 70 (rm -rf)                   │            │
│  │    路径加分: +0 (/tmp 是安全目录)         │            │
│  │    通配符加分: +0                        │            │
│  │    总分: 70 → 需要审批                    │            │
│  └────────────────┬────────────────────────┘            │
│                   │                                     │
│                   ▼                                     │
│  ┌─────────────────────────────────────────┐            │
│  │ 4. 向用户发起审批请求                     │            │
│  │    ⚠️ 危险命令待审批:                     │            │
│  │    rm -rf /tmp/build-cache               │            │
│  │    风险等级: 中                          │            │
│  │    原因: 使用 rm -rf 递归删除             │            │
│  │    [✅ 允许] [❌ 拒绝] [✏️ 修改]          │            │
│  └────────────────┬────────────────────────┘            │
│                   │                                     │
│                   ▼                                     │
│  用户选择: 
│  ├── 允许 → 执行命令,记录审批日志                         │
│  ├── 拒绝 → 取消执行,通知 Agent                          │
│  └── 修改 → 用户修改命令后重新审批                        │
│                                                         │
└─────────────────────────────────────────────────────────┘

配置审批规则

bash
# 启用命令审批
hermes security set command-approval enabled true

# 添加危险命令模式
hermes security add dangerous-pattern "kubectl delete.*--all"
hermes security add dangerous-pattern "DROP TABLE"
hermes security add dangerous-pattern "DELETE FROM.*WHERE.*1=1"

# 添加白名单
hermes security add whitelist "ls -la"
hermes security add whitelist "git diff"

# 查看当前规则
hermes security show command-approval

# 输出:
# ┌──────────────────────────────────┬──────────┬──────────┐
# │ 规则                             │ 类型     │ 来源     │
# ├──────────────────────────────────┼──────────┼──────────┤
# │ rm -rf /.*                       │ 危险     │ 默认     │
# │ kubectl delete.*--all            │ 危险     │ 自定义   │
# │ DROP TABLE                       │ 危险     │ 自定义   │
# │ ls.*                             │ 白名单   │ 自定义   │
# └──────────────────────────────────┴──────────┴──────────┘

交互式审批

当 Agent 尝试执行需要审批的命令时,你会在 TUI 中收到审批请求:

text
┌─────────────────────────────────────────────────────────┐
│ ⚠️  命令审批请求                                          │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  命令: rm -rf /tmp/build-cache/node_modules             │
│  发起者: Agent (hermes-session-abc123)                   │
│  原因: 清理构建缓存                                      │
│                                                         │
│  风险分析: 
│  ├── 操作类型: 文件删除 (rm -rf)                         │
│  ├── 目标路径: /tmp/build-cache/node_modules             │
│  ├── 路径安全: ✓ (/tmp 下的目录)                         │
│  ├── 通配符风险: 无                                      │
│  └── 风险等级: 🟡 中等                                   │
│                                                         │
│  建议: 
│  该命令在 /tmp 目录下执行,风险较低。                     │
│  但 rm -rf 是危险操作,建议确认后再执行。                 │
│                                                         │
│  [1] ✅ 允许执行                                         │
│  [2] ❌ 拒绝执行                                         │
│  [3] ✏️ 修改命令                                         │
│  [4] 📋 查看更多上下文                                    │
│  [5] ⏸️  暂停 Agent 等待                                  │
│                                                         │
│  选择 (1-5) 或在 300 秒后自动拒绝: 
│                                                         │
└─────────────────────────────────────────────────────────┘

批量审批

bash
# 设置一段时间内的自动审批(临时放宽)
hermes security auto-approve --duration 10m --reason "批量部署窗口"

# 输出:
# ✓ 已开启 10 分钟的自动审批模式
#   结束时间: 2026-05-22 19:00:00
#   原因: 批量部署窗口
#   ⚠️ 自动审批将在结束后自动关闭

# 为特定命令模式设置永久自动审批
hermes security add auto-approve-pattern "git commit.*"
hermes security add auto-approve-pattern "npm test.*"

# 查看自动审批规则
hermes security show auto-approve

Profile 级别的审批策略

yaml
# 开发环境 - 宽松
# profiles/dev.yaml
security:
  command_approval:
    enabled: false  # 开发环境不要求审批

# 测试环境 - 适中
# profiles/test.yaml
security:
  command_approval:
    enabled: true
    timeout: 120
    timeout_action: deny

# 生产环境 - 严格
# profiles/prod.yaml
security:
  command_approval:
    enabled: true
    timeout: 60
    timeout_action: deny
    # 额外限制
    max_approvals_per_hour: 10
    require_second_approval_for:
      - "rm -rf"
      - "DROP.*"
      - "DELETE.*"

Secret 脱敏机制

自动检测与脱敏

text
┌─────────────────────────────────────────────────────────┐
│              Secret 脱敏示例                               │
│                                                         │
│  Agent 输出:                                             │
│  "已配置数据库连接,连接字符串为:                          │
│  postgresql://admin:P@ssw0rd123@db.example.com:5432/app  │
│  API Key: sk-1234567890abcdef12345678                    │
│  请确认配置是否正确。"                                    │
│                                                         │
│  ↓ Secret 脱敏处理后                                     │
│                                                         │
│  用户看到:                                               │
│  "已配置数据库连接,连接字符串为:                          │
│  postgresql://admin:***@db.example.com:5432/app           │
│  API Key: sk-*********************                       │
│  请确认配置是否正确。"                                    │
│                                                         │
└─────────────────────────────────────────────────────────┘

配置脱敏规则

bash
# 查看当前脱敏规则
hermes security show secret-masking

# 添加自定义脱敏模式
hermes security add mask-pattern \
  "Bearer [a-zA-Z0-9._-]+" \
  --replacement "Bearer ***" \
  --label "JWT Token"

hermes security add mask-pattern \
  "x-api-key: [a-zA-Z0-9]+" \
  --replacement "x-api-key: ***" \
  --label "API Key Header"

# 测试脱敏效果
hermes security test-mask "my password is SecretPass123 and token is sk-abc123"

# 输出:
# 原始: my password is SecretPass123 and token is sk-abc123
# 脱敏: my password is *** and token is sk-***

# 从 CredentialPool 自动学习脱敏模式
hermes security sync-mask-patterns --from-credential-pool dev-pool

# 所有已注册的密钥值会被自动添加到脱敏模式

脱敏作用域

bash
# 全局脱敏(所有输出)
hermes security set secret-masking scope all

# 仅日志中脱敏
hermes security set secret-masking scope logs

# 仅 Agent 回复中脱敏
hermes security set secret-masking scope responses

# 仅文件写入中脱敏
hermes security set secret-masking scope file-writes

# 查看当前配置
hermes security show secret-masking

日志脱敏

bash
# 查看脱敏后的日志
hermes logs --tail 50

# 即使 Agent 在输出中包含了密钥,日志中也只会看到脱敏版本
# 2026-05-22 18:30:00 INFO 执行命令: curl -H "Authorization: Bearer ***" https://api.example.com
# 2026-05-22 18:30:01 INFO 响应状态: 200 OK

# 导出日志时自动脱敏
hermes logs --export session.log

# 强制导出原始日志(需要管理员权限)
hermes logs --export session-raw.log --no-mask

文件操作保护

受保护路径

bash
# 查看受保护路径
hermes security show protected-paths

# 输出:
# ┌──────────────────────────────────┬──────────┐
# │ 路径                             │ 保护级别  │
# ├──────────────────────────────────┼──────────┤
# │ /                                │ 完全禁止  │
# │ /etc                             │ 只读      │
# │ /usr                             │ 只读      │
# │ /var                             │ 只读      │
# │ ~/.ssh                           │ 完全禁止  │
# │ ~/.gnupg                         │ 完全禁止  │
# │ ~/.config/hermes/profiles/prod*  │ 完全禁止  │
# └──────────────────────────────────┴──────────┘

# 添加保护路径
hermes security add protected-path /opt/important-data --level deny

# 添加带通配符的保护模式
hermes security add protected-pattern "*.env" --level deny
hermes security add protected-pattern "*password*" --level deny

写入确认

text
┌─────────────────────────────────────────────────────────┐
│              文件写入确认                                  │
│                                                         │
│  Agent 尝试写入文件: 
│  /home/user/project/config.yaml                         │
│                                                         │
│  ┌─────────────────────────────────────────┐            │
│  │ 文件变更预览:                             │            │
│  │                                         │            │
│  │  @@ -15,7 +15,7 @@                      │            │
│  │   database:                             │            │
│  │     host: localhost                     │            │
│  │ -   port: 5432                          │            │
│  │ +   port: 5433                          │            │
│  │     name: myapp                         │            │
│  │                                         │            │
│  │  @@ -30,3 +30,5 @@                      │            │
│  │   cache:                                │            │
│  │     enabled: true                       │            │
│  │ +   ttl: 3600                           │            │
│  │ +   backend: redis                      │            │
│  │                                         │            │
│  └─────────────────────────────────────────┘            │
│                                                         │
│  文件大小: +120 字节                                     │
│  变更行数: 3 行修改, 2 行新增                             │
│                                                         │
│  [1] ✅ 接受变更                                         │
│  [2] ❌ 拒绝变更                                         │
│  [3] ✏️ 编辑后再写入                                     │
│                                                         │
└─────────────────────────────────────────────────────────┘

资源限制与配额

API 调用配额

bash
# 查看当前配额使用
hermes security show quota

# 输出:
# ┌──────────────────┬───────────┬──────────┬──────────┐
# │ 指标             │ 已用      │ 限制     │ 剩余     │
# ├──────────────────┼───────────┼──────────┼──────────┤
# │ 每小时 API 调用  │ 23        │ 100      │ 77       │
# │ 每日 API 调用    │ 156       │ 1000     │ 844      │
# │ 当前会话时长     │ 2h 15m    │ 8h       │ 5h 45m   │
# │ Token 用量       │ 45,230    │ 500,000  │ 454,770  │
# └──────────────────┴──────────┴──────────┴──────────┘

# 设置配额
hermes security set quota api-calls-per-hour 50
hermes security set quota api-calls-per-day 500
hermes security set quota max-session-hours 4

# 设置达到限制时的行为
hermes security set quota on-limit notify_and_stop
# 选项:
#   notify_and_stop   - 通知并停止
#   notify_and_throttle - 通知并降速(降低模型调用频率)
#   block             - 直接阻止,不通知

磁盘与执行限制

bash
# 设置磁盘使用限制
hermes security set resource disk-limit-mb 500

# 设置命令执行时间限制
hermes security set resource max-command-runtime 60

# 设置空闲超时
hermes security set resource idle-timeout 15

# 启用自动清理
hermes security set resource auto-cleanup true
hermes security set resource cleanup-after-days 3

Curator 系统概述

什么是 Curator?

Curator(策展人)是 Hermes Agent 中负责自动维护 Skills 的系统。就像图书馆的策展人负责整理、更新和维护书籍一样,Curator 负责:

text
┌─────────────────────────────────────────────────────────┐
│              Curator 的核心职责                            │
│                                                         │
│  ┌─────────────────────────────────────────────────┐    │
│  │  1. 健康检查                                      │    │
│  │     ├── Skill 依赖是否完整?                      │    │
│  │     ├── Skill 引用的外部 API 是否可用?            │    │
│  │     └── Skill 脚本是否有语法错误?                 │    │
│  └─────────────────────────────────────────────────┘    │
│  ┌─────────────────────────────────────────────────┐    │
│  │  2. 版本管理                                      │    │
│  │     ├── 已安装的 Skill 是否有新版本?              │    │
│  │     ├── Skill 的依赖包是否需要更新?               │    │
│  │     └── 是否存在冲突的版本?                      │    │
│  └─────────────────────────────────────────────────┘    │
│  ┌─────────────────────────────────────────────────┐    │
│  │  3. 自动修复                                      │    │
│  │     ├── 自动修复常见的配置问题                     │    │
│  │     ├── 更新过期的依赖                            │    │
│  │     └── 修复损坏的 Skill 文件                     │    │
│  └─────────────────────────────────────────────────┘    │
│  ┌─────────────────────────────────────────────────┐    │
│  │  4. 推荐与通知                                    │    │
│  │     ├── 推荐新版本的 Skill                        │    │
│  │     ├── 推荐相关的 Skill                         │    │
│  │     └── 通知即将废弃的 Skill                     │    │
│  └─────────────────────────────────────────────────┘    │
│                                                         │
└─────────────────────────────────────────────────────────┘

Curator 工作模式

bash
# 手动触发健康检查
hermes curator check

# 输出:
# 🔍 Skill 健康检查开始...
#
# ✅ code-review (v2.1.0)
#    ├── 依赖: 全部满足
#    ├── API: 正常
#    └── 脚本: 无错误
#
# ⚠️  python-helper (v1.3.2)
#    ├── 依赖: 全部满足
#    ├── API: 正常
#    └── 脚本: ⚠️ 使用了已废弃的 API (ast.get_docstring)
#       建议: 更新到 v1.4.0,使用新的文档解析方式
#
# ❌ aws-deploy (v0.8.1)
#    ├── 依赖: ❌ 缺少 aws-cli (需要 >= 2.0)
#    ├── API: ❌ AWS 端点不可达(网络配置问题)
#    └── 脚本: 正常
#    建议: 安装 aws-cli 并检查网络配置
#
# ℹ️  docker-helper (v3.0.0)
#    ├── 依赖: 全部满足
#    ├── API: N/A (本地工具)
#    └── 脚本: 正常
#    💡 有新版本 v3.1.0 可用(新增 Docker Compose 支持)
#
# 检查结果: 4 个 Skill
#   ✅ 健康: 2 个
#   ⚠️  警告: 1 个
#   ❌ 错误: 1 个

Skill 健康检查

深度健康检查

bash
# 深度检查(包含 API 调用测试)
hermes curator check --deep

# 检查指定 Skill
hermes curator check --skill python-helper

# 检查所有已安装 Skill
hermes curator check --all

# 以 JSON 格式输出(适合 CI/CD)
hermes curator check --output json

健康检查内容

text
┌─────────────────────────────────────────────────────────┐
│              健康检查层级                                  │
│                                                         │
│  Level 1: 结构检查                                       │
│  ├── skill.yaml 存在且格式正确?                         │
│  ├── 必需的字段是否完整?                                │
│  └── 引用的文件是否存在?                                │
│                                                         │
│  Level 2: 依赖检查                                       │
│  ├── 系统依赖是否安装?(如 python, node, jq)            │
│  ├── Python 包是否安装?                                 │
│  └── 版本是否满足要求?                                  │
│                                                         │
│  Level 3: 脚本检查                                       │
│  ├── Shell 脚本语法检查                                  │
│  ├── Python 脚本语法检查                                 │
│  └── YAML/JSON 模板格式检查                              │
│                                                         │
│  Level 4: 功能检查(--deep)                             │
│  ├── 调用 Skill 的 dry-run 模式                          │
│  ├── 测试外部 API 连接                                   │
│  └── 验证凭证池引用是否有效                              │
│                                                         │
└─────────────────────────────────────────────────────────┘

自动修复

bash
# 尝试自动修复发现的问题
hermes curator fix

# 输出:
# 🔧 开始自动修复...
#
# 修复 python-helper:
#   ├── ⚠️ 使用了已废弃的 API
#   ├── 方案: 更新脚本中的 ast.get_docstring 调用
#   ├── 执行修复... ✓ 已修复 3 处废弃 API 调用
#   └── 验证: ✓ 修复后脚本语法正确
#
# 修复 aws-deploy:
#   ├── ❌ 缺少 aws-cli 依赖
#   ├── 方案: 安装 aws-cli >= 2.0
#   ├── 正在安装... ✓ aws-cli 2.15.0 已安装
#   ├── ❌ AWS 端点不可达
#   ├── 诊断: DNS 解析失败
#   ├── 建议: 检查 /etc/resolv.conf 或网络代理配置
#   └── 此问题需要手动解决
#
# 修复完成: 1 个自动修复成功,1 个需要手动处理

定期检查(Cron)

bash
# 设置每天自动检查
hermes curator schedule check --cron "0 9 * * *"

# 设置每周自动更新检查
hermes curator schedule update-check --cron "0 10 * * 1"

# 查看调度任务
hermes curator schedule list

# 输出:
# ┌──────────────────┬─────────────┬──────────┬──────────┐
# │ 任务             │ 调度        │ 下次执行  │ 状态     │
# ├──────────────────┼─────────────┼──────────┼──────────┤
# │ health-check     │ 0 9 * * *   │ 明天 09:00│ 已启用   │
# │ update-check     │ 0 10 * * 1  │ 下周一    │ 已启用   │
# └──────────────────┴─────────────┴──────────┴──────────┘

Skill 自动更新

检查可用更新

bash
# 检查所有 Skill 的更新
hermes curator check-updates

# 输出:
# ┌──────────────────┬──────────┬──────────┬──────────────┐
# │ Skill 名称       │ 当前版本  │ 最新版本  │ 变更类型      │
# ├──────────────────┼──────────┼──────────┼──────────────┤
# │ code-review      │ v2.1.0   │ v2.1.0   │ ✓ 最新       │
# │ python-helper    │ v1.3.2   │ v1.4.0   │ 🔄 小更新    │
# │ aws-deploy       │ v0.8.1   │ v0.9.0   │ 🔄 小更新    │
# │ docker-helper    │ v3.0.0   │ v3.1.0   │ 🔄 小更新    │
# └──────────────────┴──────────┴──────────┴──────────────┘
#
# 3 个 Skill 有可用更新

# 查看某个 Skill 的更新详情
hermes curator show-updates python-helper

# 输出:
# python-helper v1.3.2 → v1.4.0
# ─────────────────────
# 变更日志:
#   - [新增] 支持 Python 3.12 语法
#   - [修复] 修复了多行 docstring 解析错误
#   - [优化] 提高了大型文件的分析速度
#   - [废弃] 移除了对 Python 3.8 的支持
#
# 兼容性: ✓ 兼容当前环境
# 风险评估: 🟢 低风险(小版本更新)

执行更新

bash
# 更新单个 Skill
hermes curator update python-helper

# 输出:
# 正在更新 python-helper v1.3.2 → v1.4.0...
#   1/4 下载新版本... ✓
#   2/4 验证签名... ✓
#   3/4 安装文件... ✓
#   4/4 运行迁移脚本... ✓
# ✓ 更新完成
#
# 迁移说明:
#   - 配置文件已自动更新
#   - 旧配置已备份到 ~/.config/hermes/skills/python-helper.bak

# 批量更新所有可更新的 Skill
hermes curator update --all

# 仅更新小版本(不更新大版本)
hermes curator update --all --minor-only

# 干运行(预览更新但不实际执行)
hermes curator update --all --dry-run

# 更新后验证
hermes curator verify python-helper

更新策略

bash
# 配置自动更新策略
hermes curator set-update-strategy auto --minor-only --notify

# 策略说明:
#   auto            - 自动更新
#   minor-only      - 只自动更新小版本(1.3 → 1.4),大版本需手动确认
#   notify          - 更新后发送通知

# 配置手动更新策略(推荐用于生产环境)
hermes curator set-update-strategy manual --notify-available

# 查看当前策略
hermes curator show-update-strategy

安全审计与日志

审计日志

bash
# 查看审计日志
hermes audit log

# 输出:
# ┌─────────────────────┬──────────┬──────────────────────────┬──────────┐
# │ 时间                │ 类型     │ 详情                     │ 结果     │
# ├─────────────────────┼──────────┼──────────────────────────┼──────────┤
# │ 18:30:00            │ 命令审批  │ rm -rf /tmp/cache        │ ✅ 允许  │
# │ 18:29:45            │ 命令审批  │ DROP TABLE users         │ ❌ 拒绝  │
# │ 18:28:30            │ 文件写入  │ config.yaml 修改         │ ✅ 允许  │
# │ 18:27:15            │ 密钥访问  │ dev-pool/OPENAI_API_KEY  │ ✅ 允许  │
# │ 18:26:00            │ Skill执行 │ code-review              │ ✅ 成功  │
# │ 18:25:30            │ Profile   │ 切换到 test              │ ✅ 成功  │
# │ 18:24:00            │ 命令执行  │ ls -la                   │ ✅ 成功  │
# └─────────────────────┴──────────┴──────────────────────────┴──────────┘

# 按类型过滤
hermes audit log --type command-approval
hermes audit log --type file-access
hermes audit log --type credential-access
hermes audit log --type skill-execution

# 按时间过滤
hermes audit log --since "1 hour ago"
hermes audit log --since "2026-05-22"

异常检测

bash
# 启用异常检测
hermes security set anomaly-detection enabled true

# 异常检测规则
hermes security show anomaly-rules

# 输出:
# ┌──────────────────────────────────┬──────────┐
# │ 规则                             │ 状态     │
# ├──────────────────────────────────┼──────────┤
# │ 短时间内大量 API 调用             │ ✓ 已启用  │
# │ 异常的文件访问模式                │ ✓ 已启用  │
# │ 密钥异常访问                      │ ✓ 已启用  │
# │ 命令执行频率异常                  │ ✓ 已启用  │
# │ 输出中包含敏感信息                │ ✓ 已启用  │
# │ Agent 行为偏离正常模式            │ ✓ 已启用  │
# └──────────────────────────────────┴──────────┘

# 查看最近的异常事件
hermes audit anomalies

# 输出:
# ┌─────────────────────┬──────────┬──────────────────────────┬──────────┐
# │ 时间                │ 严重性   │ 详情                     │ 处理     │
# ├─────────────────────┼──────────┼──────────────────────────┼──────────┤
# │ 18:15:00            │ 🔴 高    │ 1 分钟内 20 次 API 调用  │ 已限流   │
# │ 17:45:30            │ 🟡 中    │ 尝试访问 /etc/shadow     │ 已拦截   │
# │ 17:30:00            │ 🟡 中    │ 输出中包含疑似 API Key   │ 已脱敏   │
# └─────────────────────┴──────────┴──────────────────────────┴──────────┘

导出审计报告

bash
# 导出审计报告
hermes audit export --output audit-report-2026-05.md --format markdown
hermes audit export --output audit-report-2026-05.pdf --format pdf

# 导出 JSON 格式(适合程序处理)
hermes audit export --output audit.json --format json

# 定期自动生成报告
hermes audit schedule-report --cron "0 18 * * 5" --output ~/reports/

实战案例

案例一:生产环境安全加固

bash
# 1. 启用所有安全功能
hermes security set command-approval enabled true
hermes security set secret-masking enabled true
hermes security set file-protection enabled true
hermes security set anomaly-detection enabled true

# 2. 配置严格的生产 Profile
hermes profile create prod-secure --from prod
hermes profile update prod-secure \
  --security require_command_approval=true \
  --security allow_dangerous_commands=false \
  --security max_api_calls_per_hour 50 \
  --security max_session_hours 4

# 3. 设置生产环境配额
hermes security set quota api-calls-per-hour 50
hermes security set quota api-calls-per-day 500
hermes security set quota max-session-hours 4
hermes security set quota on-limit notify_and_stop

# 4. 配置密钥轮转
hermes credential-pool set-policy prod-pool OPENAI_API_KEY \
  --rotation-interval 90d \
  --auto-rotate true

# 5. 启用审计
hermes audit schedule-report --cron "0 18 * * 5" --output ~/security-reports/

# 6. 设置 Curator 自动检查
hermes curator schedule check --cron "0 9 * * *"
hermes curator schedule update-check --cron "0 10 * * 1"
hermes curator set-update-strategy manual --notify-available

# 7. 验证配置
hermes security audit
# 输出安全配置评分和建议

案例二:CI/CD 安全集成

yaml
# .github/workflows/security-audit.yml
name: Hermes Security Audit
on:
  schedule:
    - cron: "0 2 * * *"  # 每天凌晨 2 点
  workflow_dispatch:

jobs:
  audit:
    runs-on: ubuntu-latest
    steps:
      - name: Run Hermes Security Audit
        run: |
          hermes security audit --output audit-result.json
          hermes curator check --all --output json > skill-health.json
          hermes audit log --since "24 hours ago" --format json > audit-log.json

      - name: Upload Reports
        uses: actions/upload-artifact@v4
        with:
          name: security-audit
          path: |
            audit-result.json
            skill-health.json
            audit-log.json

      - name: Check for Critical Issues
        run: |
          CRITICAL=$(jq '.issues | map(select(.severity == "critical")) | length' audit-result.json)
          if [ "$CRITICAL" -gt 0 ]; then
            echo "::error::发现 $CRITICAL 个严重安全问题"
            exit 1
          fi

案例三:团队安全规范

bash
# 创建团队安全基线配置
hermes security export-baseline team-security-baseline.yaml

# 团队成员应用基线
hermes security import-baseline team-security-baseline.yaml

# 定期同步安全更新
hermes security sync-baseline --source "https://internal.company.com/security-baseline.yaml"

总结与下篇预告

总结

本文全面介绍了 Hermes Agent 的安全配置系统和 Curator 系统:

安全配置核心要点:

  1. 命令审批系统 —— 通过危险命令模式匹配、风险评分、交互式审批,确保危险操作必须经过人工确认。支持白名单、批量审批、超时策略。

  2. Secret 脱敏机制 —— 自动检测和隐藏输出中的敏感信息,包括 API Key、数据库密码、Token 等。支持自定义脱敏模式,自动从 CredentialPool 学习。

  3. 文件操作保护 —— 保护系统目录和敏感文件,写入前显示差异预览,确认后才执行。防止误删和越权写入。

  4. 资源限制与配额 —— 控制 API 调用频率、会话时长、磁盘使用,防止资源耗尽和费用失控。

Curator 系统核心要点:

  1. 健康检查 —— 定期检查 Skill 的依赖、脚本、API 连接是否正常,发现问题及时通知。

  2. 自动修复 —— 尝试自动修复常见的配置问题和依赖问题,减少手动维护成本。

  3. 版本管理与更新 —— 自动检测 Skill 新版本,支持安全更新策略(小版本自动更新,大版本手动确认)。

  4. 安全审计 —— 完整的操作日志、异常检测、审计报告,满足合规要求。

最佳实践建议:

  • 生产环境必须开启命令审批和 Secret 脱敏
  • 为不同 Profile 设置不同的安全级别(开发宽松,生产严格)
  • 启用异常检测,及时发现异常行为
  • 定期运行 Curator 健康检查,保持 Skill 处于良好状态
  • 导出审计报告,满足安全合规要求
  • 在 CI/CD 中集成安全审计,自动发现问题