Documentation
¶
Overview ¶
Package policy 实现命令黑名单、写路径白名单与限额(Spec §8)。
Index ¶
- func DefaultPolicyPath() string
- type Policy
- func (p *Policy) CheckAllowlist(cmds ...string) error
- func (p *Policy) CheckCommand(cmds ...string) error
- func (p *Policy) CheckCommandLength(cmds ...string) error
- func (p *Policy) CheckLocalDest(localPath, homeDir, repoRoot string) error
- func (p *Policy) CheckLocalSource(localPath, homeDir string) error
- func (p *Policy) CheckReadOnly() error
- func (p *Policy) CheckReadOnlyCommand(cmd string) error
- func (p *Policy) CheckReadPath(remotePath, remoteHome string) error
- func (p *Policy) CheckWritePath(remotePath, remoteHome string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (*Policy) CheckAllowlist ¶
CheckAllowlist 当 command_allowlist 非空时,命令须匹配至少一条白名单正则。
func (*Policy) CheckCommand ¶
CheckCommand 对用户原始命令与最终发送串都匹配,任一命中即拒绝。 顺序:长度 → 白名单 → 黑名单(denylist + invoked-word)。
func (*Policy) CheckCommandLength ¶
CheckCommandLength 校验命令串长度是否超过 max_command_chars。
func (*Policy) CheckLocalDest ¶
CheckLocalDest 校验 get 本机目标路径:local_denylist 与仓库 .git/ 均拒绝。
func (*Policy) CheckLocalSource ¶
CheckLocalSource 校验 put 本机源路径是否命中 local_denylist。
func (*Policy) CheckReadOnly ¶
CheckReadOnly 当 read_only 为 true 时拒绝写操作(Put 等);Exec 请用 CheckReadOnlyCommand。
func (*Policy) CheckReadOnlyCommand ¶
CheckReadOnlyCommand 在 read_only 模式下仅允许冻结的只读命令集合;ReadOnly=false 时不限制。
func (*Policy) CheckReadPath ¶
CheckReadPath 校验 get 远端路径是否命中 read_denylist。 remoteHome 为远端 $HOME,用于展开 ~/ 条目。
func (*Policy) CheckWritePath ¶
CheckWritePath 校验 put 远端路径是否在白名单内。 remoteHome 为远端 $HOME(可为空;若白名单含 ~/ 且 home 为空则无法匹配 ~ 项)。