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 seals the canary. PurposeCanary Purpose = "canary" // PurposeWebhookSecret seals the secrets signing webhook calls. PurposeWebhookSecret Purpose = "webhook secret" // PurposeSinkClickHousePassword seals the password of a ClickHouse sink. PurposeSinkClickHousePassword Purpose = "sink_clickhouse_password" // PurposeSinkObjectStorageSecret seals the secret access key of an // object storage sink. PurposeSinkObjectStorageSecret Purpose = "sink_object_storage_secret" // PurposeSinkWebhookSecret seals the secret signing a webhook sink's // calls. PurposeSinkWebhookSecret Purpose = "sink_webhook_secret" //nolint:gosec // a label, not a credential // PurposeOIDCClientSecret seals the client secrets of OIDC auth providers. PurposeOIDCClientSecret Purpose = "oidc client secret" //nolint:gosec // a label, not a credential // PurposeSMTPPassword seals the password the instance authenticates to // its SMTP server with. PurposeSMTPPassword Purpose = "smtp password" // PurposeSCIMToken seals the hashes of SCIM tokens, which are compared by // opening each one rather than found by an index. PurposeSCIMToken Purpose = "scim token" //nolint:gosec // a label, not a credential // PurposeSAMLSPKey seals the private keys the instance presents to SAML // identity providers. PurposeSAMLSPKey Purpose = "saml sp key" )
The purposes values are sealed for.
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.