Documentation
¶
Overview ¶
Package vauthlogin authenticates to Vault using ssh-agent or JWT and caches the token with ssh-agent-crypt. It does not resolve environments.
Index ¶
- Constants
- Variables
- func CheckProjectVersion(manifest, version string) error
- func Environ() map[string]string
- func HumanDiff(seconds float64, max int) string
- func KnownVault(addr, home string, environ map[string]string) bool
- func LocateRC(environ map[string]string, cwd, home string) string
- func ReplaceEnv(str string, dict Lookup) string
- type HTTPError
- type JWTAuth
- type Lookup
- type LookupToken
- type RC
- type SSHAuth
- type Vauth
- func (v *Vauth) Connect(renew bool) (string, error)
- func (v *Vauth) LookupSelf(token string) (*LookupToken, error)
- func (v *Vauth) Request(method, path, token string, payload any, expect int) (int, []byte, error)
- func (v *Vauth) TokenCacheFile() string
- func (v *Vauth) TokenCacheKey() string
- func (v *Vauth) VaultURL(path string) string
Constants ¶
const PackageName = "vauth-login"
PackageName is the npm name a project uses to pin vauth: `"dependencies": {"vauth-login": "^1.0.0"}` in its package.json.
Variables ¶
var Version string
Version is the running version (ldflags -X or debug.ReadBuildInfo), checked by New against the current directory's package.json; empty or non-semver values ("(devel)") skip the check.
Functions ¶
func CheckProjectVersion ¶
CheckProjectVersion fails when manifest (a package.json) declares a dependency on PackageName that version does not satisfy. A missing manifest, dependency or unparseable version is not an error.
func HumanDiff ¶
HumanDiff formats a duration in seconds with at most max units ("1d 3h"), like nyks/date/humanDiff.
func KnownVault ¶ added in v1.1.0
KnownVault reports whether addr is the vault_addr or one of the known_vaults of the user's ~/.vauthrc at home. A missing or unreadable file knows nothing.
func LocateRC ¶
LocateRC returns the first existing configuration file among VAUTHRC, ./.vauthrc and ~/.vauthrc, or an empty string.
func ReplaceEnv ¶
ReplaceEnv expands $$key and $${key} macros against dict (nyks string/replaceEnv semantics): unknown keys stay, expansions recurse.
Types ¶
type LookupToken ¶
type LookupToken struct {
TTL float64 `json:"ttl"`
Renewable bool `json:"renewable"`
CreationTTL int64 `json:"creation_ttl"`
EntityID string `json:"entity_id"`
LeaseDuration int64 `json:"lease_duration"`
}
LookupToken is the token metadata returned by lookup-self.
type RC ¶
type RC struct {
VaultAddr string `yaml:"vault_addr"`
SSHAuth *SSHAuth `yaml:"ssh_auth"`
JWTAuth *JWTAuth `yaml:"jwt_auth"`
TokenCache *bool `yaml:"token_cache"`
// KnownVaults lists, in ~/.vauthrc, the Vault addresses a project's
// ./.vauthrc may select without confirmation.
KnownVaults []string `yaml:"known_vaults"`
// contains filtered or unexported fields
}
RC is the parsed .vauthrc, after $${env.X} expansion.
type Vauth ¶
type Vauth struct {
RC RC
VaultAddr string
VaultToken string
// Agent is the ssh-agent address; empty disables ssh authentication.
Agent string
// TokenCache enables the on-disk token cache in CacheDir.
TokenCache bool
CacheDir string
HomeDir string
// Environ is the process environment snapshot used for macros.
Environ map[string]string
// Stderr defaults to the process error stream.
Stderr io.Writer
HTTPClient *http.Client
// Now overrides the clock (tests).
Now func() time.Time
// RCFile is the configuration file New selected, if any.
RCFile string
// Confirm is asked once before the first request to a Vault selected by
// a project's ./.vauthrc that ~/.vauthrc does not know; nil prompts on
// the terminal and refuses without one.
Confirm func(addr, file string) (bool, error)
// Accept trusts the selected Vault without confirmation (--accept, CI).
Accept bool
// contains filtered or unexported fields
}
Vauth is a configured client. New builds one from the process environment; fields may be set directly for programmatic use.
func New ¶
New loads the configuration from the environment and the first .vauthrc found (VAUTHRC, ./.vauthrc, ~/.vauthrc).
func (*Vauth) Connect ¶
Connect establishes VaultToken: an inherited token is returned as is; otherwise the cached one (renewed in the last third of its lease), then a new login. With renew, a new login is forced. Without an authentication method, no token is used.
func (*Vauth) LookupSelf ¶
func (v *Vauth) LookupSelf(token string) (*LookupToken, error)
LookupSelf validates a token online and returns metadata including entity ID.
func (*Vauth) Request ¶
Request performs a JSON Vault call. Set expect to zero to handle status yourself.
func (*Vauth) TokenCacheFile ¶
TokenCacheFile is the armored cache file for this configuration.
func (*Vauth) TokenCacheKey ¶
TokenCacheKey isolates cached tokens by Vault address and authentication configuration. It matches the Node implementation byte for byte.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
vauth-login
command
Command vauth-login authenticates to Vault and writes the token to stdout.
|
Command vauth-login authenticates to Vault and writes the token to stdout. |