Documentation
¶
Overview ¶
Package secretsource resolves a secret (a FIDO2 PIN, a container password, a recovery code) from a REFERENCE instead of a plaintext file the caller has to leave on disk.
A reference is "scheme:value":
file:PATH a regular file readable by its owner alone
keychain:SERVICE/ACCOUNT a macOS Keychain generic-password item
secretservice:SERVICE/ACCOUNT a freedesktop Secret Service item whose
attributes are service=SERVICE, account=ACCOUNT
(GNOME Keyring, KWallet, KeePassXC with "Secret
Service Integration" enabled)
systemd-creds:NAME a systemd credential (Linux): the file NAME in
$CREDENTIALS_DIRECTORY, else NAME decrypted from
a credstore.encrypted directory by systemd-creds
There is deliberately no scheme that runs a command of the caller's choosing: a reference reaches the program through a command-line flag, and a flag must never be able to start a process. (systemd-creds runs one fixed program, systemd-creds, with a validated name; the reference never picks the program or its other arguments.) A reference never holds the secret itself, so it may sit in argv, a shell history or a script; the secret travels only from the manager to the returned Secret, which the caller wipes with Secret.Close.
s, err := secretsource.Open(ctx, "keychain:fido/yubikey-5c")
if err != nil { ... }
defer s.Close()
use(s.Bytes())
Every call is bounded: a secret longer than MaxSize is refused, and the call ends with the context (or after Timeout when the context has no deadline) even when the manager is waiting for the person to unlock it.
Index ¶
Constants ¶
const MaxGenerate = 256
MaxGenerate bounds Generate.
const MaxSize = 4096
MaxSize is the longest secret accepted, in bytes.
const Timeout = 2 * time.Minute
Timeout bounds a call whose context has no deadline. It is generous because a manager may be asking the person to unlock it.
Variables ¶
var ( // ErrBadRef is a reference that does not parse. ErrBadRef = errors.New("secretsource: bad reference") // ErrScheme is a reference whose scheme is not supported. ErrScheme = errors.New("secretsource: unsupported scheme") // ErrNotFound means the manager answered and holds no such entry. ErrNotFound = errors.New("secretsource: no such entry") // wrong platform, or it is locked and refused to ask. ErrUnavailable = errors.New("secretsource: secret manager unavailable") // ErrEmpty means the entry exists and holds nothing. ErrEmpty = errors.New("secretsource: the entry is empty") // ErrTooLarge means the secret is longer than [MaxSize]. ErrTooLarge = errors.New("secretsource: the secret is too long") )
Sentinel errors, comparable with errors.Is.
var ErrAmbiguous = errors.New("secretsource: the reference matches several entries")
ErrAmbiguous means the reference matches more than one KeePassXC entry; a secret is never picked among several.
var ErrDenied = errors.New("secretsource: KeePassXC refused the request")
ErrDenied means the person refused the request in KeePassXC.
var ErrExists = errors.New("secretsource: the entry already exists (use --replace to overwrite it)")
ErrExists means the entry is already there and Replace was not asked.
var ErrNoDelete = errors.New("secretsource: cannot delete this reference")
ErrNoDelete means the reference cannot be deleted by this package: a file or a systemd credential is never managed here, and a Secret Service lookup by arbitrary attributes names no single item to remove.
var ErrNoStore = errors.New("secretsource: cannot store into this reference")
ErrNoStore means the reference cannot be written by this package.
var ErrNotAssociated = errors.New("secretsource: not associated with the KeePassXC database")
ErrNotAssociated means this machine has no (or no longer a valid) association with the open KeePassXC database: run `secretsource keepassxc associate` once and approve the request in KeePassXC.
Functions ¶
func Delete ¶ added in v0.11.0
Delete removes the entry ref names and never prints it:
keychain:SERVICE/ACCOUNT the Keychain generic-password item secretservice:SERVICE/ACCOUNT the Secret Service item keepassxc:URL the KeePassXC entry whose URL field is URL
An absent entry is an error that is both ErrNotFound and fs.ErrNotExist, so a caller that wants "already gone" to succeed says so with errors.Is. Several matching entries are ErrAmbiguous and nothing is deleted. file:, systemd-creds: and a Secret Service lookup by attributes are ErrNoDelete.
The managers have no "does it exist" call, so the entry is looked up first the way Store does before it replaces one: the value may transit memory (a keychain or Secret Service item) and is wiped at once; a KeePassXC reply is decoded without its password field. Nothing is returned or logged.
KeePassXC deletes with its browser protocol's delete-entry (BrowserAction.cpp handleDeleteEntry, BrowserService.cpp deleteEntry in 2.8.0): KeePassXC asks the person to confirm, then MOVES the entry to the database's Recycle Bin. The password stays in the database until the Recycle Bin is emptied.
func Generate ¶ added in v0.4.0
Generate draws n random characters (no look-alikes: no 0 O 1 l I) from crypto/rand, without modulo bias. The caller wipes the result.
func Store ¶ added in v0.4.0
Store writes secret under ref and never reads or prints it elsewhere:
keychain:SERVICE/ACCOUNT a Keychain generic-password item secretservice:SERVICE/ACCOUNT a Secret Service item keepassxc:URL a KeePassXC entry whose URL field is URL
An existing entry is ErrExists unless o.Replace. file: is refused: this package exists to move secrets off plaintext files. A KeePassXC entry is created by the browser protocol's set-login, so it always carries the URL that finds it again.
Types ¶
type Association ¶ added in v0.2.0
type Association struct {
// Database is KeePassXC's hash of the open database.
Database string
// ID is the name the person gave the connection in KeePassXC.
ID string
}
Association names what Associate stored.
func Associate ¶ added in v0.2.0
func Associate(ctx context.Context) (Association, error)
Associate registers this machine with the database open in KeePassXC. The person approves it in KeePassXC and names the connection; nothing else in this package ever creates trust. The association (the connection's name and an identification public key, no secret) is kept by the OS keychain on macOS, the Secret Service on Linux when one answers, otherwise a 0600 file in the user's configuration directory.
type Ref ¶
type Ref struct {
// Scheme is "file", "keychain" or "secretservice".
Scheme string
// Path is the file path (file scheme).
Path string
// Service and Account name the entry (keychain, secretservice).
Service, Account string
// Entry names a KeePassXC entry (keepassxc): by-uuid/HEX, by-path/PATH
// or a URL the entry holds.
Entry string
// Attrs is a secretservice lookup by arbitrary attributes, canonical
// ("key=value,key=value", keys sorted); see [Ref.AttrMap].
Attrs string
// Name is a systemd credential name (systemd-creds).
Name string
}
Ref is a parsed reference.
func Parse ¶
Parse reads a reference. It never touches a manager. A reference without a scheme is refused rather than guessed to be a path: "file:PATH" is how a path is written.
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
Secret is a resolved secret. Its bytes live until Secret.Close overwrites them.
type StoreOptions ¶ added in v0.4.0
type StoreOptions struct {
// Replace overwrites an existing entry; without it an existing one is ErrExists.
Replace bool
// Login is the user name of a KeePassXC entry (default: the URL's host).
Login string
// Group is the KeePassXC group a new entry goes into, as a path of names
// below the root group ("Keys/FIDO"). Default: the group KeePassXC picks,
// "KeePassXC-Browser Passwords" in 2.8.0 (BrowserService.cpp:57, created
// under the root when absent).
Group string
}
StoreOptions are the knobs of Store.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
secretsource
command
Command secretsource sets up and checks the references that fido and theca read their secrets from (--pin-from, --password-from, --recovery-from).
|
Command secretsource sets up and checks the references that fido and theca read their secrets from (--pin-from, --password-from, --recovery-from). |
|
Package secretflag lets a command take a secret by reference.
|
Package secretflag lets a command take a secret by reference. |