policy

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package policy 实现命令黑名单、写路径白名单与限额(Spec §8)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPolicyPath

func DefaultPolicyPath() string

DefaultPolicyPath 返回用户级默认 policy 路径。

Types

type Policy

type Policy struct {
	CommandTimeoutMs int64    `toml:"command_timeout_ms"`
	MaxOutputBytes   int      `toml:"max_output_bytes"`
	MaxFileBytes     int64    `toml:"max_file_bytes"`
	MaxCommandChars  int      `toml:"max_command_chars"`
	ReadOnly         bool     `toml:"read_only"`
	CommandAllowlist []string `toml:"command_allowlist"`
	CommandDenylist  []string `toml:"command_denylist"`
	WriteAllowlist   []string `toml:"write_allowlist"`
	ReadDenylist     []string `toml:"read_denylist"`
	LocalDenylist    []string `toml:"local_denylist"`
	// contains filtered or unexported fields
}

Policy 生效中的策略快照。

func Default

func Default() *Policy

Default 返回内置安全默认(无 policy 文件时可用)。

func Load

func Load(path string) (*Policy, error)

Load 加载默认并与文件合并;文件不存在则纯默认。 未知键会导致 TOML 解码失败(Strict 元数据检查)。

func (*Policy) CheckAllowlist

func (p *Policy) CheckAllowlist(cmds ...string) error

CheckAllowlist 当 command_allowlist 非空时,命令须匹配至少一条白名单正则。

func (*Policy) CheckCommand

func (p *Policy) CheckCommand(cmds ...string) error

CheckCommand 对用户原始命令与最终发送串都匹配,任一命中即拒绝。 顺序:长度 → 白名单 → 黑名单(denylist + invoked-word)。

func (*Policy) CheckCommandLength

func (p *Policy) CheckCommandLength(cmds ...string) error

CheckCommandLength 校验命令串长度是否超过 max_command_chars。

func (*Policy) CheckLocalDest

func (p *Policy) CheckLocalDest(localPath, homeDir, repoRoot string) error

CheckLocalDest 校验 get 本机目标路径:local_denylist 与仓库 .git/ 均拒绝。

func (*Policy) CheckLocalSource

func (p *Policy) CheckLocalSource(localPath, homeDir string) error

CheckLocalSource 校验 put 本机源路径是否命中 local_denylist。

func (*Policy) CheckReadOnly

func (p *Policy) CheckReadOnly() error

CheckReadOnly 当 read_only 为 true 时拒绝写操作(Put 等);Exec 请用 CheckReadOnlyCommand。

func (*Policy) CheckReadOnlyCommand

func (p *Policy) CheckReadOnlyCommand(cmd string) error

CheckReadOnlyCommand 在 read_only 模式下仅允许冻结的只读命令集合;ReadOnly=false 时不限制。

func (*Policy) CheckReadPath

func (p *Policy) CheckReadPath(remotePath, remoteHome string) error

CheckReadPath 校验 get 远端路径是否命中 read_denylist。 remoteHome 为远端 $HOME,用于展开 ~/ 条目。

func (*Policy) CheckWritePath

func (p *Policy) CheckWritePath(remotePath, remoteHome string) error

CheckWritePath 校验 put 远端路径是否在白名单内。 remoteHome 为远端 $HOME(可为空;若白名单含 ~/ 且 home 为空则无法匹配 ~ 项)。

Jump to

Keyboard shortcuts

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