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 KnownVault(addr, home string, environ map[string]string) bool
- func LocateRC(environ map[string]string, cwd, home string) string
- type HTTPError
- type JWTAuth
- 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) RC() map[string]any
- func (v *Vauth) Request(method, path, token string, payload any, expect int) (int, []byte, error)
- func (v *Vauth) VAULT_ADDR() string
- func (v *Vauth) VAULT_TOKEN() 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 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, or the environment's VAULT_ADDR. The environment is trusted even without a readable home file.
Types ¶
type JWTAuth ¶
type JWTAuth struct {
Path string `json:"path" yaml:"path"`
JWT string `json:"jwt" yaml:"jwt"`
Role string `json:"role" yaml:"role"`
}
JWTAuth configures a Vault jwt login.
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 `json:"vault_addr" yaml:"vault_addr"`
SSHAuth *SSHAuth `json:"ssh_auth" yaml:"ssh_auth"`
JWTAuth *JWTAuth `json:"jwt_auth" yaml:"jwt_auth"`
TokenCache *bool `json:"token_cache" yaml:"token_cache"`
// KnownVaults lists, in ~/.vauthrc, the Vault addresses a project's
// ./.vauthrc is allowed to select.
KnownVaults []string `json:"known_vaults" yaml:"known_vaults"`
// contains filtered or unexported fields
}
RC is the private authentication view, with the complete JSON snapshot retained.
type Vauth ¶
type Vauth struct {
// 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
// contains filtered or unexported fields
}
Vauth is a configured client. New builds one from the process environment; authentication data and the selected file path are private.
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 Vault API call after checking destination trust. A JSON payload is sent when non-nil. With expect > 0, another status is returned as *HTTPError.
func (*Vauth) VAULT_ADDR ¶ added in v1.1.4
VAULT_ADDR returns the effective address, including the environment fallback.
func (*Vauth) VAULT_TOKEN ¶ added in v1.1.4
VAULT_TOKEN returns the current token; Connect owns changes to it.
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. |