audit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: GPL-3.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package audit 记录守卫侧的安全事件。

审计的权威存储在扩展侧;本包记录 daemon 本地观察到的握手、配对、Origin 拒绝和限流事件, 补足未转发到扩展的安全信号,边界见 docs/threat-model.md。

事件只有固定字段(类型 / 客户端标识 / 原因分类),没有承载任意载荷的出口,以此保证 安全约束见 docs/threat-model.md:token 原文、脚本源码、含凭据的 URL 永不进入审计与日志。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	At     time.Time `json:"at"`
	Type   Type      `json:"type"`
	Client string    `json:"client,omitempty"`
	Reason Reason    `json:"reason,omitempty"`
}

Event 是一条安全事件。字段集合是封闭的(见包注释)。

type Reason

type Reason string

Reason 是失败原因分类。刻意用固定枚举而非原始错误串,避免错误信息把敏感内容带进审计。

const (
	ReasonHMACMismatch  Reason = "hmac_mismatch"
	ReasonTimeout       Reason = "timeout"
	ReasonProtocol      Reason = "protocol_violation"
	ReasonPairExpired   Reason = "pairing_expired"
	ReasonPairExhausted Reason = "pairing_attempts_exhausted"
)

type Recorder

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

Recorder 是固定容量的事件环形缓冲,同时把每条事件结构化输出到日志。 可查询的这份只驻内存(daemon 重启即清空);日志那份随 <dataDir>/logs 落盘, 两个出口都靠上面封闭的字段集合保证不含敏感内容。

func NewRecorder

func NewRecorder(capacity int, log *zap.Logger) *Recorder

NewRecorder 构造容量为 capacity 的记录器。

func (*Recorder) Record

func (r *Recorder) Record(ev Event)

Record 追加一条事件,超出容量时淘汰最旧的一条。At 为零值时由记录器打上时间戳。

func (*Recorder) Snapshot

func (r *Recorder) Snapshot() []Event

Snapshot 返回按发生顺序排列的事件副本。

type Type

type Type string

Type 是安全事件类型。

const (
	TypeHandshakeOK        Type = "handshake.ok"
	TypeHandshakeFailed    Type = "handshake.failed"
	TypeOriginRejected     Type = "origin.rejected"
	TypePairingRateLimited Type = "pairing.rate_limited"
	TypePairingFailed      Type = "pairing.failed"
)

type TypeCount

type TypeCount struct {
	Type  Type `json:"type"`
	Count int  `json:"count"`
}

TypeCount 是按类型聚合的事件计数。

func Summarize

func Summarize(events []Event) []TypeCount

Summarize 按类型聚合计数,数量相同时按类型名排序保证输出稳定。

Jump to

Keyboard shortcuts

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