Documentation
¶
Overview ¶
Package audit 记录管理后台的操作审计日志:谁、何时、从哪个 IP、做了什么。
日志以 JSON Lines 追加写入配置目录下的 audit.log,超过大小上限后轮转。 审计只记录方法、路径、结果与操作者,不记录请求体,因此不会泄露密钥。
Index ¶
Constants ¶
View Source
const ( CategoryLogin = "login" // 登录、登出 CategoryChange = "change" // 配置或状态变更 CategoryAccess = "access" // 读取敏感内容(备份、诊断包、终端连接等) )
操作类别
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
Time time.Time `json:"time"`
// Actor 为操作者:用户名,或 api-token:<令牌名>
Actor string `json:"actor"`
IP string `json:"ip"`
// Via 为转发该请求的本机代理地址;直连时为空
Via string `json:"via,omitempty"`
// Category 见 Category* 常量
Category string `json:"category"`
// Module 为所属模块 ID,系统级操作为空
Module string `json:"module,omitempty"`
Method string `json:"method,omitempty"`
Path string `json:"path,omitempty"`
// Status 为 HTTP 状态码,非请求类记录为 0
Status int `json:"status,omitempty"`
// Detail 为补充说明(例如登录失败原因)
Detail string `json:"detail,omitempty"`
}
Entry 是一条审计记录。
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log 是审计日志文件的句柄。
func (*Log) Middleware ¶
Middleware 记录经过认证后的变更类请求与敏感读取。必须挂在认证中间件之内,才能取到操作者。
Click to show internal directories.
Click to hide internal directories.