mirror of
https://github.com/hashicorp/vault.git
synced 2026-07-04 23:06:12 -04:00
ldap auth via cli defaults username to env (#2137)
try to guess the username from 'LOGNAME' or if it isn't set 'USER'
This commit is contained in:
parent
3ea1a8a40e
commit
7bfecbd181
1 changed files with 14 additions and 1 deletions
|
|
@ -19,7 +19,10 @@ func (h *CLIHandler) Auth(c *api.Client, m map[string]string) (string, error) {
|
|||
|
||||
username, ok := m["username"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("'username' var must be set")
|
||||
username = usernameFromEnv()
|
||||
if username == "" {
|
||||
return "", fmt.Errorf("'username' var must be set. cannot default to environment variables 'LOGNAME' or 'USER' as neither are set")
|
||||
}
|
||||
}
|
||||
password, ok := m["password"]
|
||||
if !ok {
|
||||
|
|
@ -74,3 +77,13 @@ which MFA backend is in use, read "auth/[mount]/mfa_config".
|
|||
|
||||
return strings.TrimSpace(help)
|
||||
}
|
||||
|
||||
func usernameFromEnv() string {
|
||||
if logname, ok := os.LookupEnv("LOGNAME"); ok {
|
||||
return logname
|
||||
}
|
||||
if user, ok := os.LookupEnv("USER"); ok {
|
||||
return user
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue