audit

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package audit 提供 AI/opsctl 工具调用的审计写入接口与默认实现。

命令摘要提取走 RegisterExtractor 注册表:审计自带常见工具(run_command/exec_sql 等) 的默认提取器;协议特有的(kafka_*, exec_k8s)由各自子包在 init() 中注册。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractCommandForAudit

func ExtractCommandForAudit(toolName string, args map[string]any) string

ExtractCommandForAudit 调用已注册的提取器返回命令摘要,未注册返回空串。 opsctl 兼容:"exec" 工具名被规整为 "run_command"。

func RegisterExtractor

func RegisterExtractor(toolName string, fn CommandExtractorFunc)

RegisterExtractor 注册工具名 → 命令摘要提取器。 通常各协议子包在 init() 中调用本函数;同名重复注册以最后一次为准。

func WriteGrantSubmitAudit

func WriteGrantSubmitAudit(ctx context.Context, assetID int64, assetName string, patterns []string)

WriteGrantSubmitAudit 记录会话级"始终允许"模式变更

Types

type AuditWriter

type AuditWriter interface {
	WriteToolCall(ctx context.Context, info ToolCallInfo)
}

AuditWriter 审计日志写入接口

type CommandExtractorFunc

type CommandExtractorFunc func(args map[string]any) string

CommandExtractorFunc 从工具参数 map 抽出命令摘要,供审计日志展示。

type DefaultAuditWriter

type DefaultAuditWriter struct{}

DefaultAuditWriter 默认审计日志写入实现

func NewDefaultAuditWriter

func NewDefaultAuditWriter() *DefaultAuditWriter

NewDefaultAuditWriter 创建默认审计写入器

func (*DefaultAuditWriter) WriteToolCall

func (w *DefaultAuditWriter) WriteToolCall(ctx context.Context, info ToolCallInfo)

WriteToolCall 写入一次工具调用的审计日志

type LimitedBuffer

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

LimitedBuffer 限制大小的缓冲区,用于审计日志捕获输出

func NewLimitedBuffer

func NewLimitedBuffer(limit int) *LimitedBuffer

NewLimitedBuffer 创建限制大小的缓冲区

func (*LimitedBuffer) String

func (b *LimitedBuffer) String() string

String 返回缓冲区内容

func (*LimitedBuffer) Write

func (b *LimitedBuffer) Write(p []byte) (int, error)

type ToolCallInfo

type ToolCallInfo struct {
	ToolName string
	ArgsJSON string
	Result   string
	Error    error
	Decision *aictx.CheckResult // 可选,权限检查结果
}

ToolCallInfo 一次工具调用的完整信息

Jump to

Keyboard shortcuts

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