返回顶部
g

governance-inheritance治理继承

Hierarchical policy inheritance system for OpenClaw agents. Enables policies to be defined at organization, team, project, and session levels with automatic inheritance, override rules, and conflict resolution. Use when setting up governance policies that need to cascade across multiple sessions, when defining policy hierarchies, or when resolving policy conflicts between parent and child contexts. Required tools - exec, read, write. Environment variables - GOVERNANCE_ROOT (default ~/.openclaw/g

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
113
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

governance-inheritance

治理继承

该技能提供了一种分层策略继承系统,允许在多个层级定义策略,并由子上下文自动继承。

策略层级

策略从宽泛到具体逐级传递:

组织(最宽泛)

团队

项目

会话(最具体)

继承规则

  1. 1. 子级覆盖父级:更具体的策略覆盖更宽泛的策略
  2. 默认累加:除非显式覆盖,否则策略合并
  3. 显式拒绝优先:任何层级的拒绝都会阻止该操作
  4. 需要显式允许:在严格模式下,没有显式允许的操作将被阻止

策略结构

每个层级包含一个policies.yaml文件:

yaml

policies.yaml


version: 1.0
level: organization # organization | team | project | session
parent: null # 父策略路径(根节点为null)

策略块

policies: http: - pattern: *.internal.company.com action: allow scope: [GET, POST] - pattern: * action: deny reason: 外部HTTP需要审批

shell:
- command: git *
action: allow
- command: rm -rf /*
action: deny
reason: 破坏性命令已被阻止
- command: *
action: require_approval

file:
read:
- path: ~/workspace/*
action: allow
- path: /etc/*
action: deny
write:
- path: ~/workspace/*
action: allow
- path: *
action: require_approval

继承配置

inheritance: mode: merge # merge | override | isolate exceptions: # 不继承的策略 - shell.sudo extensions: # 子级可以扩展这些策略 - http.allowlist

快速开始

1. 初始化组织策略

bash
python scripts/init_governance.py --level organization --path ~/.openclaw/governance

2. 创建团队级覆盖

bash
python scripts/init_governance.py --level team --name engineering --parent ~/.openclaw/governance/organization

3. 评估操作策略

typescript
const result = await context.tools.governanceInheritance.evaluate({
action: http,
details: { method: GET, url: https://api.example.com/data },
context: {
sessionId: sess_123,
project: my-project,
team: engineering
}
});

// result: { allowed: true } | { allowed: false, reason: ..., level: organization }

策略解析

评估操作时,系统会:

  1. 1. 收集从根节点到叶子节点的所有适用策略
  2. 合并根据继承规则
  3. 评估与最具体的匹配规则
  4. 返回带有来源(哪个层级做出的决定)的决策

冲突解决

父级子级结果
allowallowallow
allow
deny | deny(子级优先) | | allow | requireapproval | requireapproval | | deny | allow | deny(拒绝始终优先) | | deny | deny | deny |

会话上下文集成

策略根据会话上下文自动加载:

yaml

会话继承自项目 → 团队 → 组织


session_context:
organization: acme-corp
team: engineering
project: api-gateway
session: sess_abc123

策略解析路径:

~/.openclaw/governance/organizations/acme-corp/policies.yaml

~/.openclaw/governance/teams/engineering/policies.yaml

~/.openclaw/governance/projects/api-gateway/policies.yaml

~/.openclaw/governance/sessions/sess_abc123/policies.yaml

可用工具

evaluate

根据继承的策略链评估操作。

参数:

  • - action (string):操作类型(http, shell, file, browser)
  • details (object):操作相关详细信息
  • context (object):用于策略解析的会话上下文

返回:
typescript
{
allowed: boolean,
reason?: string,
level: string, // 做出决定的策略层级
policy?: string, // 匹配的具体策略
requiresApproval?: boolean
}

initPolicyLevel

初始化新的策略层级。

参数:

  • - level (string):organization, team, project 或 session
  • name (string):该层级的标识符
  • parent (string, 可选):父策略路径
  • path (string):创建策略的位置

validatePolicyChain

验证策略链是否存在冲突或错误。

参数:

  • - context (object):要验证的会话上下文

返回:
typescript
{
valid: boolean,
errors: string[],
warnings: string[]
}

配置

在环境中设置治理根目录:

bash
export GOVERNANCE_ROOT=~/.openclaw/governance

或者在openclaw.json中:

json
{
skills: {
governance-inheritance: {
env: {
GOVERNANCE_ROOT: ~/.openclaw/governance
}
}
}
}

策略示例

组织层级(限制性基础)

yaml
level: organization
policies:
http:
- pattern: *.company.internal
action: allow
- pattern: *
action: require_approval
shell:
- command: *
action: require_approval

团队层级(工程部 - 更宽松)

yaml
level: team
parent: ../organization
inheritance:
mode: merge
policies:
http:
- pattern: *.github.com
action: allow
- pattern: *.npmjs.com
action: allow
shell:
- command: git *
action: allow
- command: npm *
action: allow
- command: docker *
action: allow

项目层级(特定覆盖)

yaml
level: project
parent: ../engineering
inheritance:
mode: merge
policies:
http:
- pattern: api.stripe.com
action: allow # 该项目使用Stripe
file:
write:
- path: ./dist/*
action: allow

与GovernClaw集成

该技能与governclaw-middleware协同工作:

typescript
// governclaw-middleware调用governance-inheritance进行策略解析
const policyResult = await context.tools.governanceInheritance.evaluate({
action: http,
details: { method, url, headers },
context: sessionContext
});

if (!policyResult.allowed) {
return { blocked: true, reason: policyResult.reason };
}

最佳实践

  1. 1. 在组织层级从限制性开始 - 所有操作都需要审批
  2. 在较低层级授予特定权限 - 团队/项目选择他们需要的权限
  3. 记录例外情况 - 使用reason字段解释策略存在的原因
  4. 定期审计 - 运行validatePolicyChain以发现冲突
  5. 对策略进行版本控制 - 使用version字段跟踪更改

错误处理

始终检查策略评估错误:

typescript
const result = await context.tools.governanceInheritance.evaluate({...});

if (result.error) {
// 策略链配置错误
console.error(策略错误:, result.error);
return { error: 治理配置错误 };
}

if (!result.allowed) {
// 策略阻止了操作
console.log(被, result.level, 策略阻止:, result.reason);
}

参见

  • - references/policy-schema.md - 完整的策略YAML模式
  • references/inheritance-algorithm.md - 详细的继承逻辑
  • scripts/initgovernance.py - 初始化策略层级
  • scripts/validatechain.py - 验证策略链

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 governance-inheritance-1776117673 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 governance-inheritance-1776117673 技能

通过命令行安装

skillhub install governance-inheritance-1776117673

下载

⬇ 下载 governance-inheritance v1.0.0(免费)

文件大小: 13.09 KB | 发布时间: 2026-4-14 13:31

v1.0.0 最新 2026-4-14 13:31
Initial release of governance-inheritance skill

- Implements a hierarchical policy inheritance system for OpenClaw agents with organization, team, project, and session levels.
- Supports policy cascade with automatic inheritance, overrides, and conflict resolution.
- Provides tools for policy evaluation, policy level initialization, and validation of policy chains.
- Offers additive merging, explicit deny/allow handling, and provenance tracking for policy decisions.
- Integrates with session context and external governance middleware for real-time enforcement.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部