configsecret

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: AGPL-3.0 Imports: 16 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 configsecret protects secrets inside monitor configurations (ADR 0015). A field is secret if the type's JSON Schema marks it with `writeOnly: true`. Secret values are taken out of the configuration, encrypted one by one (ADR 0011) and stored by JSON pointer; the stored configuration holds Mask in their place. Plaintext exists only in API input and, while a check runs, in memory.

Index

Constants

View Source
const Mask = "***"

Mask stands for a stored secret in configurations and API responses. In an update it means "keep the stored value" (same as notification channels).

Variables

View Source
var (
	// ErrMaskWithoutSecret is returned when the input contains Mask at a place
	// where no secret is stored, e.g. after a type change or for a new header.
	ErrMaskWithoutSecret = errors.New("masked value can only keep an existing secret")
	// ErrUnsupportedSchema is returned for schemas the walker cannot follow
	// safely ($ref); treating them as secret-free could leak secrets.
	ErrUnsupportedSchema = errors.New("unsupported JSON Schema construct for secret detection")
)

Errors returned for invalid input; callers report them as 422.

Functions

func AAD

func AAD(monitorID, pointer string) string

AAD binds a ciphertext to its monitor and field, so it cannot be copied to another monitor or position (ADR 0011).

func HasPlaintext

func HasPlaintext(paths Paths, config json.RawMessage) (bool, error)

HasPlaintext reports whether a stored configuration still contains a secret value that is not masked (written before ADR 0015).

func MaskConfig

func MaskConfig(paths Paths, config json.RawMessage) (json.RawMessage, error)

MaskConfig replaces every value at a secret position with Mask. Stored configurations already hold Mask; this guards API responses against configurations written before ADR 0015 that are not yet migrated.

func Migrate

func Migrate(ctx context.Context, opts MigrationOptions) (int, error)

Migrate rewrites every monitor whose configuration still contains a plaintext secret and returns how many were rewritten.

func Resolve

func Resolve(ctx context.Context, kr Keyring, monitorID string, config json.RawMessage, secrets Secrets) (json.RawMessage, error)

Resolve returns the configuration with the secrets decrypted and put back, for running a check. The result must stay in memory and never be logged.

func ResolveMonitor

func ResolveMonitor(ctx context.Context, kr Keyring, m store.Monitor) (json.RawMessage, error)

ResolveMonitor returns the configuration of a stored monitor with its secrets decrypted, for running a check.

func RunMigration

func RunMigration(ctx context.Context, opts MigrationOptions)

RunMigration encrypts secrets of monitors stored before ADR 0015. Only the leader proposes; the job ends after one complete pass without errors.

Types

type Applier

type Applier interface {
	Apply(ctx context.Context, cmd *pb.Command) (cluster.ApplyResult, error)
}

Applier proposes commands to the Raft cluster.

type Keyring

type Keyring interface {
	Encrypt(plaintext []byte, aad string) (string, error)
	Decrypt(ctx context.Context, ciphertext, aad string) ([]byte, error)
}

Keyring encrypts and decrypts single values (implemented by secrets.Keyring).

type MaskError

type MaskError struct{ Pointer string }

MaskError reports Mask at a pointer without a stored secret.

func (*MaskError) Error

func (e *MaskError) Error() string

func (*MaskError) Unwrap

func (e *MaskError) Unwrap() error

Unwrap makes errors.Is(err, ErrMaskWithoutSecret) work.

type MigrationOptions

type MigrationOptions struct {
	State    store.State
	Cluster  Applier
	Keyring  Keyring
	Schemas  *Schemas
	IsLeader func() bool
	Logger   *slog.Logger
	// Interval between attempts while not leader or after errors (default 30 s).
	Interval time.Duration
}

MigrationOptions configure RunMigration.

type Paths

type Paths [][]string

Paths lists where a schema allows secret values, as patterns of path segments; "*" matches any map key or array index.

func PathsOf

func PathsOf(schema json.RawMessage) (Paths, error)

PathsOf collects the writeOnly locations of a JSON Schema.

type Schemas

type Schemas struct {
	Registry *checker.Registry
	// contains filtered or unexported fields
}

Schemas returns the secret paths of each monitor type of a registry. The paths are derived once per type.

func (*Schemas) Paths

func (s *Schemas) Paths(typ string) (Paths, error)

Paths returns the secret paths of a type; unknown types have none.

type Secrets

type Secrets map[string]string

Secrets maps JSON pointers into the configuration to ciphertexts.

func Reencrypt

func Reencrypt(ctx context.Context, kr Keyring, fromID, toID string, secrets Secrets) (Secrets, error)

Reencrypt binds the secrets of one monitor to another (clone).

func Split

func Split(kr Keyring, paths Paths, monitorID string, config json.RawMessage, previous Secrets) (json.RawMessage, Secrets, error)

Split takes the secrets out of an input configuration. Values at secret positions are encrypted for monitorID and replaced by Mask. Mask keeps the secret from previous at the same pointer; an absent fixed-name field keeps it too if its parent object is present (PUT without re-entering the password). An empty string removes the field. previous must only be passed when the monitor keeps its type.

Jump to

Keyboard shortcuts

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