Documentation
¶
Overview ¶
Package keychain keeps small secrets in the operating system's credential store: the Windows Credential Manager, the macOS Keychain, or the Secret Service (GNOME Keyring, KWallet) on Linux.
A secret kept in a file next to the data it protects, such as the key that encrypts the stored API keys, shields nothing from a program running as the same user: it reads both. The operating system store is the place that separates them. On macOS another program reading an item prompts the user; on Windows the item is protected by the user's login (DPAPI).
The store is not always there (a container, a server with no desktop session, an SSH login with a locked keychain). Every function then returns ErrUnavailable, and the caller decides what to do: the callers of this package fall back to a file with owner-only permissions, as before, rather than refuse to run.
Index ¶
Constants ¶
const EnvDisable = "SESHAT_KEYCHAIN"
EnvDisable turns the operating system store off (value "off", "0" or "false"): the callers keep their file fallback. For containers and CI, where a store that blocks or prompts is worse than none.
const Service = "seshat"
Service is the name every item is stored under.
Variables ¶
var ( // ErrNotFound means the store works and holds no item of that name. ErrNotFound = errors.New("keychain: item not found") ErrUnavailable = errors.New("keychain: no usable credential store") )
Functions ¶
func Enabled ¶
func Enabled() bool
Enabled reports whether this process may use the operating system store. It is off when SESHAT_KEYCHAIN says so and inside Go test binaries, which must never write to the developer's real credential store (a test installs a fake with UseForTesting instead).
func Get ¶
Get returns the secret stored under account, ErrNotFound when there is none, ErrUnavailable when there is no usable store.
func UseForTesting ¶
func UseForTesting() (restore func())
UseForTesting installs an in-memory store and turns the package on, and returns the function that restores the previous state. It exists so that tests of the packages that call this one can exercise the store without touching the real one.
Types ¶
This section is empty.