agent

package
v0.0.0-...-6310218 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const AgentVersion = "0.2.0"

AgentVersion is the current reach-agent version.

Variables

View Source
var Capabilities = []string{"stats", "dryrun"}

Capabilities lists the features this agent supports beyond v0.1.0 baseline.

Functions

func BuildBlacklist

func BuildBlacklist(cfg *SecurityConfig) []*regexp.Regexp

BuildBlacklist 根据配置构建最终黑名单

func CheckDangerous

func CheckDangerous(command string, patterns []*regexp.Regexp) error

CheckDangerous 检查命令是否在黑名单中

func Serve

func Serve(cfg *AgentConfig) error

Serve 启动 HTTPS server

func WriteFile

func WriteFile(path string, content string, mode string) error

WriteFile 原子写入文件。mode 为空时保留原文件权限(若不存在则用 0644)。

Types

type AgentConfig

type AgentConfig struct {
	Port       int    `yaml:"port"`
	Token      string `yaml:"token"`
	TLSCert    string `yaml:"tls_cert"`
	TLSKey     string `yaml:"tls_key"`
	MaxOutput  int    `yaml:"max_output"`
	MaxTimeout int    `yaml:"max_timeout"`

	// 安全配置
	Security SecurityConfig `yaml:"security"`
}

AgentConfig 对应 config.yaml

func LoadConfig

func LoadConfig(path string) (*AgentConfig, error)

LoadConfig 从 yaml 文件加载配置

type ExecResult

type ExecResult struct {
	Stdout    string `json:"stdout"`
	Stderr    string `json:"stderr"`
	ExitCode  int    `json:"exit_code"`
	Truncated bool   `json:"truncated"`
}

ExecResult 命令执行结果

func Execute

func Execute(command string, timeout int, maxOutput int, blacklist []*regexp.Regexp) *ExecResult

Execute 在独立进程组中执行 shell 命令,支持超时与输出截断

type InitResult

type InitResult struct {
	Token       string
	Fingerprint string
	CertPath    string
	KeyPath     string
	ConfigPath  string
}

InitResult 包含初始化后的关键信息

func Init

func Init(configDir string) (*InitResult, error)

Init 生成自签证书、Token,并写入配置文件

type ReadResult

type ReadResult struct {
	Content   string `json:"content"`
	Size      int    `json:"size"`
	Truncated bool   `json:"truncated"`
}

ReadResult 文件读取结果

func ReadFile

func ReadFile(path string, maxSize int) (*ReadResult, error)

ReadFile 读取文件内容,最多 maxSize 字节 拒绝非常规文件(设备、管道、/proc 等),防止无限阻塞或内存爆炸

type SecurityConfig

type SecurityConfig struct {
	// 命令黑名单开关 (默认 true)
	CommandBlacklist *bool `yaml:"command_blacklist"`
	// 自定义黑名单正则(追加到内置列表)
	CustomBlacklist []string `yaml:"custom_blacklist"`
	// AUTH_FAIL 日志(供 fail2ban 使用,默认 true)
	AuthFailLog *bool `yaml:"auth_fail_log"`
}

SecurityConfig 安全相关可选配置

Jump to

Keyboard shortcuts

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