policy

package
v0.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package policy 实现 Golem 的运行时安全策略评估引擎。 它根据配置的模式(严格、宽松、关闭)对工具执行请求进行准入控制。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action 表示策略评估后针对工具执行请求的决策动作。

const (
	ActionAllow           Action = "allow"            // 允许执行
	ActionDeny            Action = "deny"             // 拒绝执行
	ActionRequireApproval Action = "require_approval" // 需要人工审批后执行
)

type Config

type Config struct {
	Mode            Mode     // 运行模式
	RequireApproval []string // 需要审批的工具列表
}

Config 包含评估器初始化所需的策略设置。

type Decision

type Decision struct {
	Action Action // 决策动作
	Reason string // 决策原因(特别是在拒绝时)
}

Decision 封装了策略评估的最终确定性结果。

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

Evaluator 负责执行纯粹的策略决策逻辑,不包含副作用。

func NewEvaluator

func NewEvaluator(cfg Config) Evaluator

NewEvaluator 根据提供的配置构建一个确定性的评估器实例。

func (Evaluator) Evaluate

func (e Evaluator) Evaluate(input Input) Decision

Evaluate 根据当前策略模式和输入上下文(如工具名称)返回一个确定性的准入决策。

type Input

type Input struct {
	ToolName string // 待执行的工具名称
}

Input 包含单次策略评估所需的上下文信息。

type Mode

type Mode string

Mode 控制策略评估器的运行模式。

const (
	ModeStrict  Mode = "strict"  // 严格模式:不在允许列表中的敏感操作需审批
	ModeRelaxed Mode = "relaxed" // 宽松模式:目前允许所有操作,未来可能增加风险预警
	ModeOff     Mode = "off"     // 关闭模式:不进行任何策略拦截
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL