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
- Variables
- func AAD(monitorID, pointer string) string
- func HasPlaintext(paths Paths, config json.RawMessage) (bool, error)
- func MaskConfig(paths Paths, config json.RawMessage) (json.RawMessage, error)
- func Migrate(ctx context.Context, opts MigrationOptions) (int, error)
- func Resolve(ctx context.Context, kr Keyring, monitorID string, config json.RawMessage, ...) (json.RawMessage, error)
- func ResolveMonitor(ctx context.Context, kr Keyring, m store.Monitor) (json.RawMessage, error)
- func RunMigration(ctx context.Context, opts MigrationOptions)
- type Applier
- type Keyring
- type MaskError
- type MigrationOptions
- type Paths
- type Schemas
- type Secrets
Constants ¶
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 ¶
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 ¶
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 ¶
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 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.
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.
type Schemas ¶
Schemas returns the secret paths of each monitor type of a registry. The paths are derived once per type.
type Secrets ¶
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.