Documentation
¶
Overview ¶
Package secret keeps the few credentials Caprock itself holds — the GitHub token, the DeepSeek API key, the Telegram bot token — out of the database, config.json and every log (ADR-039, ADR-024 amendment).
On macOS a secret is a generic password in the user's login keychain, written through /usr/bin/security with the value as an argument and the keychain file named explicitly, so no call can ever open a dialog. Elsewhere, or when the keychain is missing or refuses, it is a 0600 file in the data directory, and the store says so.
Index ¶
Constants ¶
const Account = "caprock"
Account names the item within its service.
const EnvStore = "CAPROCK_SECRET_STORE"
EnvStore forces the store: "file" uses the 0600 file even on macOS. Tests and throwaway daemons set it, so nothing touches a keychain.
const NotFound = 44
NotFound is `security`'s exit status for a missing item.
Variables ¶
This section is empty.
Functions ¶
func HomeFromDSCache ¶
HomeFromDSCache reads "dir: /Users/name" from dscacheutil's answer.
Types ¶
type Fallback ¶
type Fallback struct {
Keychain Keychain
File File
Noun string // "token" or "key"; "" reads as "token"
// contains filtered or unexported fields
}
Fallback is the Keychain with the 0600 file behind it: when the Keychain refuses (locked, missing, an error), the secret goes to the file instead and Note says so — never a dialog.
type File ¶
type File struct {
Path string
}
File stores a secret in a 0600 file in the data directory, where there is no Keychain.
type FileWithNote ¶
FileWithNote is the file store with the reason the Keychain is not used.
func (FileWithNote) Note ¶
func (f FileWithNote) Note() string
type Item ¶
type Item struct {
Service string // the keychain service, e.g. dev.caprock.github
Label string // the keychain item's label, e.g. "Caprock GitHub token"
File string // the fallback file's name in the data directory
Noun string // "token" or "key", for the notes; "" reads as "token"
}
Item names one secret: where it lives in the keychain and in the data directory, and how a note calls it.
type Keychain ¶
type Keychain struct {
Service string
Account string // the item within its service; "" is Account
Label string
Path string // the keychain file, e.g. ~/Library/Keychains/login.keychain-db
Run Runner // nil runs /usr/bin/security
}
Keychain stores a secret as a generic password through the `security` tool, with the value as an argument (no shell, no file). Every call names the keychain file explicitly (Path, the user's login keychain): without one, `security` falls back to the default keychain and, when it cannot find that, macOS shows a "Keychain Not Found" dialog — which a daemon must never cause. Default only builds one for a Path that exists.
type Noted ¶
type Noted interface{ Note() string }
Noted is a store with something to say about where it keeps the secret.
type Runner ¶
Runner runs the `security` tool with args and returns its stdout and exit status. Tests replace it: no test ever runs the real tool.
type Store ¶
type Store interface {
Get(ctx context.Context) (string, error) // "" with no error when nothing is stored
Set(ctx context.Context, value string) error
Delete(ctx context.Context) error
Kind() string // "keychain" or "file"
}
Store keeps one secret. Never the database, never config.json, never a log.