tokenstore

package
v3.0.0-rc49 Latest Latest
Warning

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

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

Documentation

Overview

Package tokenstore keeps the secrets a client caches between its runs, as the refresh token of a login, in the most protected place the machine offers.

Three backends are known, tried in this order when none is asked:

  • keyring: the keyring of the user session, the Secret Service of a linux desktop, the macOS keychain or the Windows credential manager. A headless server usually has none.

  • agent: a file encrypted with a key derived from a signature the ssh-agent of the user makes, with an ed25519 or an rsa key, whose signatures are the same each time. The file is of no use without the agent holding that key: a backup, a copied home directory or a stolen disk do not open it. Whoever can use the agent can, as they can use the key itself.

  • file: a file only the user reads. It is what a token is worth on a machine whose other users the user trusts not to be root.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Backends are the backends, in the order Auto tries them.
	Backends = []Backend{Keyring, Agent, File}

	// ErrNotFound is returned on the load of a secret the store does not
	// hold.
	ErrNotFound = errors.New("not found in the token store")
)
View Source
var ErrAgentKeyMissing = errors.New("the ssh-agent does not hold the key the token was encrypted with")

ErrAgentKeyMissing is returned on the load of a secret encrypted with a key the agent does not hold now.

Functions

This section is empty.

Types

type Backend

type Backend string

Backend names a place secrets are kept in.

const (
	Keyring Backend = "keyring"
	Agent   Backend = "agent"
	File    Backend = "file"
)

func ParseBackend

func ParseBackend(s string) (Backend, error)

ParseBackend returns the backend s names, Auto being the empty string.

type Store

type Store interface {
	Backend() Backend
	Load(name string) ([]byte, error)
	Save(name string, b []byte) error
	Delete(name string) error
}

Store keeps named secrets in a backend.

func Auto

func Auto(dir string) Store

Auto returns the store of the first backend usable on this machine, the file one being always usable.

func New

func New(backend Backend, dir string) (Store, error)

New returns the store of a backend, keeping its files under dir, or an error saying why the backend can not be used on this machine.

Jump to

Keyboard shortcuts

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