Documentation
¶
Overview ¶
Package secret holds values that must never reach a log: passwords, keys, tokens. Every way of printing one (fmt, slog, JSON) writes [redacted]; only an explicit Reveal gives the value, at the one place that needs it.
A Keyring seals values under the instance's secret key for storage, so only an instance holding the key reads them back, and derives the keys of other uses from it.
Index ¶
Constants ¶
const Base62Alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Base62Alphabet is the alphabet credential values are drawn from: letters and digits, safe in a header, a URL and a shell without quoting.
const MinKeyLength = 32
MinKeyLength is the fewest bytes a secret key may have. Every key the keyring uses is derived from the secret key, and derivation adds no strength: a short key would make sealed secrets and session signatures guessable.
Variables ¶
var ErrCannotOpen = errors.New("the sealed value cannot be opened")
ErrCannotOpen is every failure to open a sealed value alike: another key, another purpose, a tampered value or no sealed value at all, since telling them apart would help whoever tampers.
var ErrSecretKeyChanged = errors.New("FLAGNETIC_SECRET_KEY does not open this instance's canary: " +
"it is not the key the instance was set up with, and what the instance sealed cannot be read without that key; " +
"start with the original key")
ErrSecretKeyChanged is a secret key that does not open the canary the instance stored: not the key the instance was set up with.
Functions ¶
Types ¶
type Keyring ¶
type Keyring struct {
// contains filtered or unexported fields
}
Keyring seals and opens values, and derives keys, under the instance's secret key.
func NewKeyring ¶
NewKeyring returns the keyring of secretKey.
func (*Keyring) CheckCanary ¶
CheckCanary returns ErrSecretKeyChanged unless the secret key opens canary.
func (*Keyring) NewCanary ¶
NewCanary returns a new canary: random bytes sealed under the secret key, stored once by the instance and opened on every start.
type Purpose ¶
type Purpose string
Purpose names what a sealed value is for. Each purpose seals under a key of its own, so a value sealed for one purpose never opens as another.
const PurposeCanary Purpose = "canary"
PurposeCanary seals the canary.
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is a secret string. Its zero value is the empty secret.
func (String) MarshalText ¶
MarshalText returns [redacted], so an encoded configuration hides it too.