credential

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 20 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 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

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

View Source
const IndexFileName = "credential-homes.json"

IndexFileName is the index under ~/.abcd.noindex/, and IndexPath its tilde form.

View Source
const MaxValueBytes = 4096

MaxValueBytes bounds one credential's value.

View Source
const StoreFileName = "credentials.json"

StoreFileName is the abcd home's file under ~/.abcd.noindex/.

Variables

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

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

StorePath is where the abcd home lives, displayed with ~ so no developer-identity path reaches output.

Functions

func CheckValue

func CheckValue(v string) error

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

func KeychainItem(name string) string

KeychainItem names the keychain's item for name as a surface shows it.

func ResolvePointer added in v0.13.0

func ResolvePointer(home, name string, p Pointer) (string, error)

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

func Set(home, name string, c Choice) (changed bool, err error)

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

func SetMachine(home, name, value string) (changed bool, err error)

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

func ValidEnvName(name string) bool

ValidEnvName reports whether name is an environment variable's name as an external pointer takes it.

func ValidName

func ValidName(name string) bool

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

func Walkthrough(name string) string

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

func Where(home, name string) (string, error)

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

func WritesFor(home, name string) []string

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

type Choice struct {
	Home    string
	Value   string
	Pointer Pointer
}

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.

func (Service) Explain added in v0.12.0

func (s Service) Explain() []string

Explain is the walkthrough's explanation, in the order it is given.

type Source

type Source interface {
	Resolve(name string) (string, error)
}

Source resolves a credential by name.

func Machine

func Machine(home string) Source

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.

func Store added in v0.12.0

func Store(home string) Source

Store is the one reader every adapter resolves a credential through, by name, rooted at home (the caller's home directory). An empty home resolves every name to ErrNotSet.

func UserStore added in v0.12.0

func UserStore() Source

UserStore is Store at the caller's home directory.

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

func Walk(ctx context.Context, home string, s Service, c Choice) (WalkResult, error)

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.

Jump to

Keyboard shortcuts

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