credentials¶
Storage-mode abstraction for user-supplied secrets in Go CLIs. The config
records how a secret is stored (an env-var name, a keychain reference, or
a literal), never a plaintext secret unless you explicitly ask for it. A
pluggable Backend sits behind the modes, and the OS keychain is an auditable
opt-in.
gitlab.com/phpboyscout/go/credentials is the credential-storage layer extracted
from go-tool-base, where it backs
every setup wizard, doctor check, and runtime resolver. It answers one question
consistently: where does this secret live, and how do I get it back? A tool
then does not re-implement the same env/keychain/literal switch at every call site.
Why¶
- Framework-free. The core's only dependencies are
go/errorsandgolang.org/x/term(for the stdlib prompt's masked entry). No config framework, no TUI, no go-tool-base. Adepfootprint_test.goguard enforces the boundary. - Secrets stay out of config by default.
ModeEnvVarrecords a variable name;ModeKeychainrecords aservice/accountreference. OnlyModeLiteralwrites the secret itself, andRefuseLiteralUnderCIrefuses it underCI=trueif you call it (nothing calls it for you). - Auditable keychain opt-out. The go-keyring backend lives in the optional
credentials/keychainsubpackage. Omit its blank import and go-keyring and all keychain IPC never enter your binary, which an SBOM of the linked artefact will show. See the keychain opt-out. - UI-agnostic capture, overridable. A
Prompterseam captures the interactive input; a stdlib default ships in the box, and a tool swaps in a themed TUI so prompts match the rest of its UX.
Where next¶
- Getting started: capture and resolve a credential end to end in a few lines.
- Choose a storage mode: env-var reference vs OS keychain vs literal, and when to use each.
- Enable OS-keychain storage: one blank import, plus the regulated-build opt-out.
- Implement a custom backend:
plug in Vault, AWS SSM, or 1Password by satisfying
Backend. - Hold a credential that expires: renew a short-lived token before it expires, or when the server rejects it.
- Theme the prompts: override the stdlib prompter with your own TUI.
- Trust model: what each mode does and does not protect against.
- API reference: every exported symbol, its defaults, and what it does when it fails.
Reference¶
| Page | Answers |
|---|---|
| API reference | What does this function do, what does it default to, and what does it return when it fails? |
| Storage modes | What are the exact Mode values, and which modes may I offer? |
| Errors | Which error is this, and should I fall through or surface it? |
| Configuration | What does the module read from the environment, and what happens when it is wrong? |
| Limitations | Is that supported? Usually the answer is no, and this page says which. |
Generated Go signatures and doc comments are on pkg.go.dev; the pages above add the behaviour a signature does not show.
Further reading¶
The blog carries a curated route through this subject: Building a command-line tool in Go collects everything written about it, ordered so you can start at the beginning rather than newest-first.
Ask phpbotscout

He answers questions about the projects over on the Discord, citing the docs where they already cover it, and offering to raise an issue where they don't. Bring a bug, an idea, or a questionable engineering decision.