Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt for MFA token when creating new profile #1235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cli/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ConfigureAddCommand(app *kingpin.Application, a *AwsVault) {
}

func AddCommand(input AddCommandInput, keyring keyring.Keyring, awsConfigFile *vault.ConfigFile) error {
var accessKeyID, secretKey string
var accessKeyID, secretKey, mfaSerial string

p, _ := awsConfigFile.ProfileSection(input.ProfileName)
if p.SourceProfile != "" {
Expand All @@ -73,6 +73,9 @@ func AddCommand(input AddCommandInput, keyring keyring.Keyring, awsConfigFile *v
if secretKey, err = prompt.TerminalSecretPrompt("Enter Secret Access Key: "); err != nil {
return err
}
if mfaSerial, err = prompt.TerminalPrompt("Enter MFA Device ARN (If MFA is not enabled, leave this blank): "); err != nil {
return err
}
}

creds := aws.Credentials{AccessKeyID: accessKeyID, SecretAccessKey: secretKey}
Expand All @@ -92,7 +95,8 @@ func AddCommand(input AddCommandInput, keyring keyring.Keyring, awsConfigFile *v
if _, hasProfile := awsConfigFile.ProfileSection(input.ProfileName); !hasProfile {
if input.AddConfig {
newProfileSection := vault.ProfileSection{
Name: input.ProfileName,
Name: input.ProfileName,
MfaSerial: mfaSerial,
}
log.Printf("Adding profile %s to config at %s", input.ProfileName, awsConfigFile.Path)
if err := awsConfigFile.Add(newProfileSection); err != nil {
Expand Down