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

msgmask

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package msgmask masks the personal data of RabbitMQ messages: body, headers (application properties) and properties, from the rules of .lockmq/pii.toml, the profile's body mode, field-name heuristics and value detectors (lockkit's pii).

Index

Constants

View Source
const (
	ModeRedactUnknown = "redact-unknown"
	ModeDetect        = "detect"
)

Body modes (the profile's body_mode).

Variables

This section is empty.

Functions

func AppendMask

func AppendMask(path string, r Rule) error

AppendMask adds r as a [[mask]] table at the end of the rules file at path (created when missing), leaving the rest of the file as it is.

Types

type Masked

type Masked struct {
	Properties map[string]any `json:"properties,omitempty"`
	Headers    map[string]any `json:"headers,omitempty"`
	// Body is the parsed JSON, a string, or "<bytes:N sha256:H type:T>".
	Body      any      `json:"body"`
	Truncated bool     `json:"truncated,omitempty"`
	Proposals []string `json:"proposals,omitempty"`
}

Masked is a message fit for a client: every personal value masked.

type Masker

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

Masker masks the messages of one console session.

func NewMasker

func NewMasker(r Rules, detectors []pii.Detector, bodyMode string, refs *pii.RefStore, maxBody int) *Masker

NewMasker returns a masker. bodyMode is redact-unknown or detect (any other value is redact-unknown: fail closed); refs keeps the clear values behind the references; maxBody caps a body after masking.

func (*Masker) Mask

func (m *Masker) Mask(result int, vhost, queue string, msg Message) Masked

Mask masks msg, read from queue (or stream) on vhost, for result number result of the reference store (RefStore.Begin).

type Message

type Message struct {
	Properties map[string]any
	// Headers are the AMQP headers or the stream's application properties.
	Headers         map[string]any
	Body            []byte
	ContentType     string
	ContentEncoding string
	// Exchange is the exchange the message was published to, "" if unknown.
	Exchange string
	// Origin is the queue named by the message's first x-death entry; ""
	// takes it from Headers.
	Origin string
}

Message is one message as read from the broker.

type Rule

type Rule struct {
	// Queues and Exchanges are "vhost/name" globs ("*/*", "orders/order-*");
	// the vhost "/" is written as a leading "/" ("//orders").
	Queues, Exchanges []string
	// Exactly one of Body (a JSON path), Header (a name glob) and Property.
	Body, Header, Property string
	// Mode is the mask mode of a mask rule (redact, partial, email); empty
	// in an allow rule.
	Mode string
	// contains filtered or unexported fields
}

Rule masks (or, in an allow list, clears) one body path, header name glob or property of the messages of some queues or exchanges.

func ParseRule

func ParseRule(text string) (Rule, error)

ParseRule parses a mask rule's canonical text (mode redact).

func (Rule) String

func (r Rule) String() string

String is the rule's canonical text: the form stored in the policy and sent by clients ("queue=*/* body=$.customer.email"). The mode is kept apart (Texts).

type Rules

type Rules struct {
	Mask, Allow []Rule
}

Rules are the mask and allow rules of a project.

func FromTexts

func FromTexts(mask, allow []string, modes map[string]string) (Rules, error)

FromTexts rebuilds rules from their canonical texts and the modes of the mask rules (the policy's form, Texts).

func LoadRules

func LoadRules(path string) (Rules, error)

LoadRules reads .lockmq/pii.toml (design §7). A missing file is no rules.

func (Rules) Texts

func (rs Rules) Texts() (mask, allow []string, modes map[string]string)

Texts returns the canonical texts of the mask and allow rules and the modes of the mask rules that are not redact: the policy's form.

Jump to

Keyboard shortcuts

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