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

config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package config loads lockmq profiles from the project and user config files, applies the defaults, refuses anything that looks like a secret, and computes the security-relevant policy of a profile. The file lookup, the secret-safe decoding, the shared profile base and the diff helpers are lockkit's.

Index

Constants

View Source
const (
	// BodyRedactUnknown redacts every string leaf no allow rule names.
	BodyRedactUnknown = "redact-unknown"
	// BodyDetect masks what mask rules, key names and detectors find.
	BodyDetect = "detect"
)

Body modes: how the string leaves of a JSON message body are masked.

View Source
const (
	ReadMaxCeiling = 200
	PeekMaxCeiling = 20
)

Hard ceilings of the per-request message counts.

View Source
const (
	MinIdleTimeout = time.Minute
	MaxMaxSession  = 24 * time.Hour
)

Bounds of the session limits: MinIdleTimeout <= idle_timeout <= max_session <= MaxMaxSession.

View Source
const (
	DefaultIdleTimeout = 20 * time.Minute
	DefaultMaxSession  = 4 * time.Hour
)

Default session limits.

View Source
const DefaultMaskMode = "redact"

DefaultMaskMode is the mode of a mask rule that sets none.

Variables

This section is empty.

Functions

func DefaultBodyMode

func DefaultBodyMode(production bool) string

DefaultBodyMode is redact-unknown on production, detect elsewhere.

func DefaultDetectors

func DefaultDetectors() []string

DefaultDetectors is the detector set of a profile that sets none. National id detectors are opt-in.

func Load

func Load(cwd string) (map[string]Profile, string, error)

Load reads the project config (found by walking up from cwd) and the user config. On a profile name present in both, the project profile wins as a whole. It also returns the project root ("" when none).

func LoadFile

func LoadFile(path string) (map[string]Profile, error)

LoadFile reads the profiles of one config file.

func LoadFrom

func LoadFrom(cwd, userConfigPath string) (map[string]Profile, string, error)

LoadFrom is Load with an explicit user config path ("" for none). A missing user config file is not an error.

func ParseProfiles

func ParseProfiles(data []byte, name string) (map[string]Profile, error)

ParseProfiles decodes and validates config data; name labels errors. Errors never quote a value that could hold a secret.

Types

type Limits

type Limits struct {
	RequestTimeout time.Duration `json:"request_timeout"`
	// ReadMax and PeekMax are the most messages one stream read or one
	// queue peek returns.
	ReadMax int `json:"read_max"`
	PeekMax int `json:"peek_max"`
	// DeliveryHeadroom refuses a quorum queue peek this close to the
	// queue's delivery limit.
	DeliveryHeadroom int `json:"delivery_headroom"`
	// MaxBodyBytes caps one message body after masking.
	MaxBodyBytes   int `json:"max_body_bytes"`
	MaxOutputBytes int `json:"max_output_bytes"`
	ListPageSize   int `json:"list_page_size"`
}

Limits bound the cost and size of one request.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns the limits applied to unset limit fields.

type ParsedURL

type ParsedURL struct {
	Host string
	Port int // 0: the scheme's default
	TLS  bool
	Path string
}

ParsedURL is a validated broker URL.

func ParseURL

func ParseURL(key, s string) (ParsedURL, error)

ParseURL validates s for the key ("url", "amqp_url" or "stream_url"). Its errors never quote s.

type Policy

type Policy struct {
	Profile Profile  `json:"profile"`
	Mask    []string `json:"pii_mask"`
	Allow   []string `json:"pii_allow"`
	// Modes maps a mask rule to its mode when it is not redact.
	Modes map[string]string `json:"pii_modes,omitempty"`
}

Policy is the security-relevant view of one profile plus its PII rules: what the console fingerprints, compares with the last approved one and asks the human about before applying any loosening. Mask and Allow hold rules in their canonical text form (package msgmask).

func Canonical

func Canonical(p Policy) Policy

Canonical sorts and de-duplicates the lists of p and drops the modes of rules it does not hold and the default mode: its JSON is the fingerprinted form.

func NewPolicy

func NewPolicy(p Profile, mask, allow []string, modes map[string]string) Policy

NewPolicy builds the canonical policy of p with its PII rules.

func (Policy) Describe

func (p Policy) Describe() []string

Describe is the policy as lines for the console's status screen.

func (Policy) Diff

func (p Policy) Diff(approved kconfig.Policy) []kconfig.Change

Diff lists the changes from approved to p and marks each loosening (design §4): read → peek, a lower delivery_headroom, any larger limit, a longer request_timeout, a new vhost (or every vhost), any change of url, amqp_url or stream_url, body_mode redact-unknown → detect, a removed detector or mask rule, an added allow rule, a mask mode away from redact, and the shared rules of the profile base (kconfig.DiffBase).

type Profile

type Profile struct {
	Name string `json:"name"`
	kconfig.Base
	// URL is the management HTTP API; AMQPURL and StreamURL are optional.
	// None holds a user or a password.
	URL       string `json:"url"`
	AMQPURL   string `json:"amqp_url,omitempty"`
	StreamURL string `json:"stream_url,omitempty"`
	// VHosts are the vhosts served, sorted; empty serves every vhost the
	// account can see.
	VHosts    []string `json:"vhosts"`
	Tier      Tier     `json:"tier"`
	Detectors []string `json:"detectors"`
	BodyMode  string   `json:"body_mode"`
	Limits    Limits   `json:"limits"`
}

Profile is one named broker with its policy. It never holds a secret.

type Tier

type Tier int

Tier is what a profile lets the agent read. The order is TierRead < TierPeek: peek also reads classic and quorum queue messages, which is not strictly read-only.

const (
	TierRead Tier = iota
	TierPeek
)

Tiers, in increasing order of what they allow.

func ParseTier

func ParseTier(s string) (Tier, error)

ParseTier parses "read" or "peek". Its error never quotes s.

func (Tier) MarshalText

func (t Tier) MarshalText() ([]byte, error)

MarshalText encodes the tier by name.

func (Tier) String

func (t Tier) String() string

func (*Tier) UnmarshalText

func (t *Tier) UnmarshalText(b []byte) error

UnmarshalText decodes a tier name.

Jump to

Keyboard shortcuts

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