secret

package
v0.167.0 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Account = "caprock"

Account names the item within its service.

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

View Source
const NotFound = 44

NotFound is `security`'s exit status for a missing item.

Variables

This section is empty.

Functions

func HomeFromDSCache

func HomeFromDSCache(out string) string

HomeFromDSCache reads "dir: /Users/name" from dscacheutil's answer.

func UserHome

func UserHome(ctx context.Context) string

UserHome is the current user's home directory as the system records it (Directory Services on macOS), not $HOME, which a caller may have changed. "" when it cannot be read.

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.

func (*Fallback) Delete

func (f *Fallback) Delete(ctx context.Context) error

func (*Fallback) Get

func (f *Fallback) Get(ctx context.Context) (string, error)

func (*Fallback) Kind

func (f *Fallback) Kind() string

func (*Fallback) Note

func (f *Fallback) Note() string

Note says why the secret is not where it would usually be, "" otherwise.

func (*Fallback) Set

func (f *Fallback) Set(ctx context.Context, value string) error

type File

type File struct {
	Path string
}

File stores a secret in a 0600 file in the data directory, where there is no Keychain.

func (File) Delete

func (f File) Delete(context.Context) error

func (File) Get

func (f File) Get(context.Context) (string, error)

func (File) Kind

func (File) Kind() string

func (File) Set

func (f File) Set(_ context.Context, value string) error

type FileWithNote

type FileWithNote struct {
	File
	Why string
}

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.

func (Keychain) Delete

func (k Keychain) Delete(ctx context.Context) error

func (Keychain) Get

func (k Keychain) Get(ctx context.Context) (string, error)

func (Keychain) Kind

func (Keychain) Kind() string

func (Keychain) Set

func (k Keychain) Set(ctx context.Context, value string) error

type Noted

type Noted interface{ Note() string }

Noted is a store with something to say about where it keeps the secret.

type Runner

type Runner func(ctx context.Context, args ...string) (stdout string, code int, err error)

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.

func Default

func Default(dataDir string, it Item, home string) Store

Default picks where Caprock keeps it: the user's login keychain on macOS when that file exists (with the 0600 file behind it), else the 0600 file in dataDir. home is the user's real home directory (UserHome), not $HOME.

type Where

type Where struct {
	Kind string `json:"kind"`           // keychain | file
	Path string `json:"path,omitempty"` // the file, when Kind is file
	Note string `json:"note,omitempty"` // why it is not in the Keychain, when it could have been
}

Where says where a store keeps its secret, for Settings.

func Locate

func Locate(s Store) Where

Locate describes s; a nil store is the zero Where.

Jump to

Keyboard shortcuts

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