keychain

package
v1.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

View Source
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.

View Source
const Service = "seshat"

Service is the name every item is stored under.

Variables

View Source
var (
	// ErrNotFound means the store works and holds no item of that name.
	ErrNotFound = errors.New("keychain: item not found")
	// ErrUnavailable means there is no usable store: disabled, absent, locked or too slow to answer.
	ErrUnavailable = errors.New("keychain: no usable credential store")
)

Functions

func Delete

func Delete(account string) error

Delete removes the item stored under account; a missing item is not an error.

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

func Get(account string) (string, error)

Get returns the secret stored under account, ErrNotFound when there is none, ErrUnavailable when there is no usable store.

func Set

func Set(account, value string) error

Set stores value under account.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL