Help us shape the future of Go! Take the 2026 Go Developer Survey

logredact

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logredact 日志/审计载荷凭据脱敏:连接串/URL/头中的凭据在落日志前模式化打码。 与 fence(Markdown/HTML 注入卫生)正交——本包打码凭据。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Redact

func Redact(s string) string

Redact 返回打码后的文本(无命中原样返回)。

func RedactSecrets

func RedactSecrets(s string, secrets ...string) string

RedactSecrets 抹除调用方已知的确切秘密(clone URL 内嵌 token、动态签发的临时 凭据等):与模式化 Redact 互补——Redact 靠规则打码未知形态的凭据,本函数抹除 已知值。与 Masker 相反,高敏感秘密不做令牌、不回填(Masker 只收低敏感拓扑标识)。 长秘密优先替换(防短串是长串前缀时留下尾段泄漏),空串忽略。

func RedactValue

func RedactValue(v any) any

RedactValue 递归脱敏任意 JSON 形态值:map/slice 逐字段下探,字符串过 Redact,其余原样。 事件载荷入库前的统一出口——tool_call 参数与 tool_result 文本常含连接串、webhook key、Bearer 头。

Types

type Masker

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

Masker 低敏感掩码+令牌回填器(K8sGPT anonymize 形态,bianque spec 2026-09-14-aiops-uplift-design §3):把目标机拓扑标识(IPv4 + 调用方注册的精确串) 在进 LLM 前替换为 «Tn» 令牌,在最终展示面 Restore 回填原名——LLM 解释里引用的 「主机 «T1»」在报告中还原为真名,可读性与隐私兼得。

分级纪律:高敏感(密码/密钥/连接串/Bearer)不走本机制——那是 Redact 的领域, 删除后永不回填;Masker 只收低敏感拓扑标识,且回填只发生在展示面、不回灌二次 LLM 输入(防掩码词表被 prompt 注入探测绕过)。令牌用全角书名号+序号,难以仿造; Restore 对未知令牌原样保留(不猜、不误回填)。

func NewMasker

func NewMasker() *Masker

NewMasker 构造(零值不可用,一律经本构造)。

func (*Masker) AddSecret

func (m *Masker) AddSecret(v string) string

AddSecret 注册精确串(会话主机名、实例名等调用方已知标识),返回其令牌。空串忽略。

func (*Masker) Count

func (m *Masker) Count() int

Count 已签发令牌数(测试/观测用)。

func (*Masker) Mask

func (m *Masker) Mask(s string) string

Mask 掩码文本:先精确注册串,再 IPv4 模式(动态注册,同址恒同令牌)。

func (*Masker) Restore

func (m *Masker) Restore(s string) string

Restore 回填令牌为原文(展示面专用;未知令牌原样保留)。

Jump to

Keyboard shortcuts

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