Skip to content

Commit d382d09

Browse files
committed
Pass vault name and requested password type to askpass process
1 parent a4b88b7 commit d382d09

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

doc/man/vaulted.1

+11
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ intended to be shown to the user. The askpass implementation then writes the
115115
password to \fB\fCstdout\fR and returns a success code (0). If a failure code (non\-0)
116116
is returned, the password input is aborted.
117117
.PP
118+
The vault name, requested secret type (password, MFA token etc.) and password
119+
request reason is passed to the askpass process in the environment variables
120+
\fB\fCVAULTED_ENV\fR, \fB\fCVAULTED_PASSWORD_TYPE\fR and \fB\fCVAULTED_PASSWORD_REASON\fR
121+
respectively.
122+
.PP
123+
Valid values for \fB\fCVAULTED_PASSWORD_TYPE\fR are: \fB\fCpassword\fR, \fB\fClegacypassword\fR or
124+
\fB\fCmfatoken\fR\&.
125+
.PP
126+
Valid values for \fB\fCVAULTED_PASSWORD_REASON\fR are: \fB\fCnew\fR, \fB\fCnomatch\fR, \fB\fCconfirm\fR or
127+
the empty string if \fB\fCVAULTED_PASSWORD_TYPE\fR is not \fB\fCpassword\fR\&.
128+
.PP
118129
Vaulted is intended to integrate seamlessly with existing askpass
119130
implementations (e.g. \fB\fCssh\-askpass\fR).
120131
.PP

doc/vaulted.1.md

+11
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ intended to be shown to the user. The askpass implementation then writes the
106106
password to `stdout` and returns a success code (0). If a failure code (non-0)
107107
is returned, the password input is aborted.
108108

109+
The vault name, requested secret type (password, MFA token etc.) and password
110+
request reason is passed to the askpass process in the environment variables
111+
`VAULTED_ENV`, `VAULTED_PASSWORD_TYPE` and `VAULTED_PASSWORD_REASON`
112+
respectively.
113+
114+
Valid values for `VAULTED_PASSWORD_TYPE` are: `password`, `legacypassword` or
115+
`mfatoken`.
116+
117+
Valid values for `VAULTED_PASSWORD_REASON` are: `new`, `nomatch`, `confirm` or
118+
the empty string if `VAULTED_PASSWORD_TYPE` is not `password`.
119+
109120
Vaulted is intended to integrate seamlessly with existing askpass
110121
implementations (e.g. `ssh-askpass`).
111122

steward.go

+24-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ import (
1313
"github.com/miquella/vaulted/lib/legacy"
1414
)
1515

16+
const (
17+
PASSWORD_TYPE_PASSWORD = "password"
18+
PASSWORD_TYPE_LEGACY_PASSWORD = "legacypassword"
19+
PASSWORD_TYPE_MFATOKEN = "mfatoken"
20+
21+
PASSWORD_REASON_NEW = "new"
22+
PASSWORD_REASON_NOMATCH = "nomatch"
23+
PASSWORD_REASON_CONFIRM = "confirm"
24+
)
25+
1626
func NewSteward() vaulted.Steward {
1727
if askpass, present := os.LookupEnv("VAULTED_ASKPASS"); present {
1828
return &AskPassSteward{
@@ -56,18 +66,21 @@ func (t *AskPassSteward) GetPassword(operation vaulted.Operation, name string) (
5666
switch operation {
5767
case vaulted.SealOperation:
5868
for firstTry := false; ; firstTry = true {
69+
var passwordreason string
5970
var prompt string
6071
if firstTry {
72+
passwordreason = PASSWORD_REASON_NEW
6173
prompt = fmt.Sprintf("'%s' new password: ", name)
6274
} else {
75+
passwordreason = PASSWORD_REASON_NOMATCH
6376
prompt = fmt.Sprintf("'%s' new password (passwords didn't match): ", name)
6477
}
65-
password, err := t.askpass(prompt)
78+
password, err := t.askpass(name, PASSWORD_TYPE_PASSWORD, passwordreason, prompt)
6679
if err != nil {
6780
return "", err
6881
}
6982

70-
confirm, err := t.askpass(fmt.Sprintf("'%s' confirm password: ", name))
83+
confirm, err := t.askpass(name, PASSWORD_TYPE_PASSWORD, PASSWORD_REASON_CONFIRM, fmt.Sprintf("'%s' confirm password: ", name))
7184
if err != nil {
7285
return "", err
7386
}
@@ -78,19 +91,24 @@ func (t *AskPassSteward) GetPassword(operation vaulted.Operation, name string) (
7891
}
7992

8093
case legacy.LegacyOperation:
81-
return t.askpass("Legacy Password: ")
94+
return t.askpass(name, PASSWORD_TYPE_LEGACY_PASSWORD, "", "Legacy Password: ")
8295

8396
default:
84-
return t.askpass(fmt.Sprintf("'%s' password: ", name))
97+
return t.askpass(name, PASSWORD_TYPE_PASSWORD, "", fmt.Sprintf("'%s' password: ", name))
8598
}
8699
}
87100

88101
func (t *AskPassSteward) GetMFAToken(name string) (string, error) {
89-
return t.askpass(fmt.Sprintf("'%s' MFA token: ", name))
102+
return t.askpass(name, PASSWORD_TYPE_MFATOKEN, "", fmt.Sprintf("'%s' MFA token: ", name))
90103
}
91104

92-
func (t *AskPassSteward) askpass(prompt string) (string, error) {
105+
func (t *AskPassSteward) askpass(name string, passwordtype string, reason string, prompt string) (string, error) {
93106
cmd := exec.Command(t.Command, prompt)
107+
cmd.Env = append(os.Environ(),
108+
"VAULTED_ENV="+name,
109+
"VAULTED_PASSWORD_TYPE="+passwordtype,
110+
"VAULTED_PASSWORD_REASON="+reason,
111+
)
94112
output, err := cmd.Output()
95113
if err != nil {
96114
return "", ErrNoPasswordEntered

0 commit comments

Comments
 (0)