Documentation
¶
Overview ¶
Package credential is the credential store (itd-2609221017023290, adr-2609221017021499): the one reader every adapter resolves an external credential through, by NAME (Store, store.go), the one write (Set), and the walkthrough that chooses a credential's home (Walk, walk.go). This file is the abcd home: one machine-scoped file, ~/.abcd.noindex/credentials.json, a JSON object mapping a credential name to its value. The keychain and external homes are keychain.go and external.go.
The file is refused, loudly and never treated as absent, unless it is a regular file (not a symlink), owned by the caller, and readable and writable by the owner alone (mode 0600 or tighter), in a ~/.abcd.noindex that is not itself a symlink: a secret that group or other can read is not kept, one that somebody else wrote is not the caller's, and one behind a symlinked ~/.abcd.noindex lives in whatever the link points at.
The value never leaves Resolve except as its return: no error formats it, nothing logs it, and nothing here writes to the repository. The one write is SetMachine, into this same file, which Set calls for the abcd home. A malformed file is refused without echoing a byte of it.
Index ¶
- Constants
- Variables
- func CheckValue(v string) error
- func Homes() []string
- func KeychainItem(name string) string
- func ResolvePointer(home, name string, p Pointer) (string, error)
- func Set(home, name string, c Choice) (changed bool, err error)
- func SetMachine(home, name, value string) (changed bool, err error)
- func ValidEnvName(name string) bool
- func ValidName(name string) bool
- func Walkthrough(name string) string
- func Where(home, name string) (string, error)
- func WritesFor(home, name string) []string
- type Choice
- type Pointer
- type Service
- type Source
- type WalkResult
Constants ¶
const ( // HomeExternal is a setup outside abcd; the store holds the pointer. HomeExternal = "external" // HomeABCD is abcd-only: the owner-only ~/.abcd.noindex/credentials.json. HomeABCD = "abcd" // HomeKeychain is the platform keychain. HomeKeychain = "keychain" )
The homes a credential lives in (adr-2609221017021499 ruling 2).
const IndexFileName = "credential-homes.json"
IndexFileName is the index under ~/.abcd.noindex/, and IndexPath its tilde form.
const MaxValueBytes = 4096
MaxValueBytes bounds one credential's value.
const StoreFileName = "credentials.json"
StoreFileName is the abcd home's file under ~/.abcd.noindex/.
Variables ¶
var ErrNotSet = errors.New("credential not set")
ErrNotSet is a credential that resolves to nothing: no store, no entry, or an empty value. It is the one error a caller may treat as "carry on without it".
var HomesProse = "Where the credential lives is your choice of three, made once. The platform keychain is " + "the home abcd recommends, because the secret stays in the operating system's own store rather than in a " + "file. A setup outside abcd keeps it with a tool you already use (an environment variable, or a field of " + "that tool's configuration file), and abcd stores only where to find it. The abcd-only home keeps it in " + StorePath + ", readable by you alone. The value never enters the harness's settings or a repository."
HomesProse is the prose above the choice of home: the keychain is recommended here, and never as a marked option.
var IndexPath = abcdhome.Display(IndexFileName)
var StorePath = abcdhome.Display(StoreFileName)
StorePath is where the abcd home lives, displayed with ~ so no developer-identity path reaches output.
Functions ¶
func CheckValue ¶
CheckValue refuses a value SetMachine would refuse, without echoing it, so a caller can refuse before any other work.
func Homes ¶ added in v0.12.0
func Homes() []string
Homes returns the homes in the order every walkthrough offers them. None is marked: the keychain is recommended in HomesProse, never in the list.
func KeychainItem ¶ added in v0.12.0
KeychainItem names the keychain's item for name as a surface shows it.
func ResolvePointer ¶ added in v0.13.0
ResolvePointer is resolvePointer for a caller outside the store: a setup that lists a service's models with the external key before the walkthrough verifies it (spc-2610031241482088). It refuses what resolvePointer refuses.
func Set ¶ added in v0.12.0
Set stores a credential under name in the chosen home: the one write every setup goes through (the walkthrough, Walk, is its only caller outside this package's tests). It refuses, before writing a value or an index entry and never echoing a value: a ~/.abcd.noindex that is a symlink, in every home, before anything is created; the abcd home inside a git working tree; a name another home already holds, or a different value in the same home, because a stored secret is never replaced unasked; a keychain on a platform without one; and a pointer that does not resolve. The same value again is no change. The whole write, from reading where the name is held to the last write, holds the index's lock, so concurrent Sets of one name cannot land in two homes.
func SetMachine ¶
SetMachine writes value under name in the abcd home at home (~/.abcd.noindex/credentials.json): the abcd home's write, which Set makes for it and no reader outside this package calls.
It refuses, before writing anything and without echoing either value: a name that is not plain; a value that is empty, longer than MaxValueBytes, padded with white space or carrying a control, bidirectional or zero-width character; a store Resolve would refuse (a symlink, group- or other- readable, not owned by the caller, malformed), so a write never launders an unsafe file; a ~/.abcd.noindex that is a symlink, because the secret would land wherever the link points (fsutil.EnsureHomeScope); and a name already holding a different value, because a stored secret is never replaced by a second one unasked. The same value already stored is no change (changed is false). The file is written atomically at mode 0600, and ~/.abcd.noindex is created owner-only when it is absent. The read, the change and the write hold the store's lock (fsutil.WithFileLockIn, beside the store), so concurrent writers never lose each other's entries.
func ValidEnvName ¶ added in v0.13.0
ValidEnvName reports whether name is an environment variable's name as an external pointer takes it.
func ValidName ¶
ValidName reports whether name is a plain credential name, the shape every source resolves, so a configuration that names a credential is checked when it is read rather than at the first call.
func Walkthrough ¶ added in v0.12.0
Walkthrough is the command that explains a credential and stores it, named by every refusal of a name that is not set.
func Where ¶ added in v0.12.0
Where names the home that holds name ("" when none does), reading the index and the abcd home and never a value: a surface shows presence and the home, and this is the home. Presence is Resolve.
func WritesFor ¶ added in v0.13.0
WritesFor names what storing name in home touches, in the tilde form and in the order a walkthrough reports it: the abcd home's file; the keychain's item and the index; the external home's index. A home that stores nothing (a keyless provider's none, or a name no home answers to) touches nothing. Walk's Wrote is built from it, so the list a setup shows before it runs and the list a run reports cannot drift apart (spc-2610031241482088).
Types ¶
type Choice ¶ added in v0.12.0
Choice is one home chosen for one credential: the value for the abcd and keychain homes, the pointer for the external one.
type Pointer ¶ added in v0.12.0
type Pointer struct {
Env string `json:"env,omitempty"`
File string `json:"file,omitempty"`
Field string `json:"field,omitempty"`
}
Pointer is an external home's pointer: an environment variable, or a field of a tool's JSON configuration file under the home directory.
type Service ¶ added in v0.12.0
type Service struct {
// Name is the credential's name.
Name string
// Unlocks is what the credential unlocks.
Unlocks string
// WithoutIt is what works without it.
WithoutIt string
// Verify is the adapter's own call, made with the value before it is
// stored. It must not carry the value into its error.
Verify func(ctx context.Context, value string) error
}
Service is one credential's walkthrough, supplied by the adapter that reads it.
type Source ¶
Source resolves a credential by name.
func Machine ¶
Machine is the abcd home alone, rooted at home (the caller's home directory). An empty home resolves every name to ErrNotSet. Every reader outside this package resolves through Store, which reads this home among the three; a test refuses any other.
type WalkResult ¶ added in v0.12.0
type WalkResult struct {
Name string `json:"name"`
Home string `json:"home"`
Verified bool `json:"verified"`
// Changed is false when the same credential was already stored there.
Changed bool `json:"changed"`
// Wrote names what the write touched, in the tilde form: the abcd home's
// file, or the index and the keychain. Empty when nothing changed.
Wrote []string `json:"wrote"`
}
WalkResult is what a walkthrough did. It never carries the value.
func Walk ¶ added in v0.12.0
Walk runs the walkthrough for s with the chosen home: the value (or, for the external home, what the pointer resolves to) is verified with the adapter's own call, and only then stored. A name another home holds, or a different value in the same home, is refused before the call, so a setup that cannot store its credential is never verified for nothing.