-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1123 from 99designs/add-mfa-process-config
Add `mfa_process` config
- Loading branch information
Showing
11 changed files
with
116 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package vault | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/99designs/aws-vault/v7/prompt" | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
) | ||
|
||
// Mfa contains options for an MFA device | ||
type Mfa struct { | ||
mfaSerial string | ||
mfaPromptFunc prompt.Func | ||
} | ||
|
||
// GetMfaToken returns the MFA token | ||
func (m *Mfa) GetMfaToken() (*string, error) { | ||
if m.mfaPromptFunc != nil { | ||
token, err := m.mfaPromptFunc(m.mfaSerial) | ||
return aws.String(token), err | ||
} | ||
|
||
return nil, errors.New("No prompt found") | ||
} | ||
|
||
// GetMfaSerial returns the MFA serial | ||
func (m *Mfa) GetMfaSerial() string { | ||
return m.mfaSerial | ||
} | ||
|
||
func NewMfa(config *Config) *Mfa { | ||
m := Mfa{ | ||
mfaSerial: config.MfaSerial, | ||
} | ||
if config.MfaToken != "" { | ||
m.mfaPromptFunc = func(_ string) (string, error) { return config.MfaToken, nil } | ||
} else if config.MfaProcess != "" { | ||
m.mfaPromptFunc = func(_ string) (string, error) { | ||
log.Println("Executing mfa_process") | ||
return ProcessMfaProvider(config.MfaProcess) | ||
} | ||
} else { | ||
m.mfaPromptFunc = prompt.Method(config.MfaPromptMethod) | ||
} | ||
|
||
return &m | ||
} | ||
|
||
func ProcessMfaProvider(processCmd string) (string, error) { | ||
cmd := exec.Command("/bin/sh", "-c", processCmd) | ||
cmd.Stderr = os.Stderr | ||
|
||
out, err := cmd.Output() | ||
if err != nil { | ||
return "", fmt.Errorf("process provider: %w", err) | ||
} | ||
|
||
return strings.TrimSpace(string(out)), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters