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
- Variables
- func Base62(random io.Reader, n int) string
- func IsBase62(s string) bool
- type Binding
- type Keyring
- func (k *Keyring) CheckCanary(canary string) error
- func (k *Keyring) Key(use Use) []byte
- func (k *Keyring) NewCanary() (string, error)
- func (k *Keyring) Open(purpose Purpose, sealed string, binding Binding) ([]byte, error)
- func (k *Keyring) Rebind(purpose Purpose, sealed string, binding Binding) (string, error)
- func (k *Keyring) Seal(purpose Purpose, plaintext []byte, binding Binding) (string, error)
- type Purpose
- type String
- type Use
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 Binding ¶ added in v0.5.0
type Binding string
Binding names the row a sealed value belongs to, so a sealed value copied into another row, by whoever can write the database, does not open there.
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.
func (*Keyring) Open ¶
Open returns the plaintext of a value sealed for purpose and binding, or ErrCannotOpen. A value in the version before rows were bound opens whatever the binding.
func (*Keyring) Rebind ¶ added in v0.5.0
Rebind returns sealed bound to binding: a value sealed before rows were bound is opened and sealed again for binding, so that the write of its row leaves it bound. A value already bound, an empty one and one that does not open are returned as they are: rebinding never makes an unrelated write of the row fail over a value that only its own use can judge.
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.