Documentation
¶
Overview ¶
Package secrets keeps an app's secrets (contract.md section 9.5): API tokens and anything else that may not sit in plain text. One file, `<Config>/secrets.enc`, holds every name and value, encrypted with AES-256-GCM under a key derived with HKDF-SHA256 from a random key file next to it (`<Config>/secrets.key`, made on the first Save), this machine's id (`/etc/machine-id` on Linux, `IOPlatformUUID` on macOS) and the app's pepper, a string in the app's source. Both files are 0600 and written through atomicfile, so a reader sees the old file or the new one. The two files copied to another machine do not open there: the user enters the secrets again.
What it protects against: secrets.enc alone is useless, and with the key file it opens only where the machine id matches, so a copy of the Config directory does not open elsewhere. What it does not: any process running as the user on that machine can decrypt if it also has the pepper, and so can anyone holding the key file, the machine id (a full-disk backup holds both) and the pepper. The pepper is a secret for a private repo, obscurity for a public one: a scanner that knows this scheme also needs the private app's source or its binary, while a public app's pepper is only a label that keeps one app's key apart from another's.
Open registers the doctor section "secrets" with the names only, never the values.
Index ¶
Constants ¶
const ( FileName = "secrets.enc" KeyFileName = "secrets.key" )
The two files inside the Config directory.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the app's secrets file. Calls on one Store are serialized; two processes writing the same file both write a whole file, and the last one wins.
func Open ¶
Open gives the store of id's Config directory and registers its doctor section. It reads nothing until the first call. pepper is mixed into the key: any string is accepted, the empty one too, and a store saved with one pepper does not open with another.
func (*Store) Load ¶
Load returns the value stored under name; an unknown name is a not_found failure.