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

[v15] fix: Respect the --no-allow-passwordless flag #49935

Merged
merged 1 commit into from
Dec 9, 2024
Merged
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
18 changes: 10 additions & 8 deletions tool/tsh/common/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,14 @@ type mfaAddCommand struct {
devName string
devType string

// allowPasswordless is initially true if --allow-passwordless is set, false
// if not explicitly requested.
// It can only be set by users if wancli.IsFIDO2Available() is true.
// allowPasswordless and allowPasswordlessSet hold the state of the
// --(no-)allow-passwordless flag.
//
// allowPasswordless can only be set by users if wancli.IsFIDO2Available() is
// true.
// Note that Touch ID registrations are always passwordless-capable,
// regardless of other settings.
allowPasswordless bool
allowPasswordless, allowPasswordlessSet bool
}

func newMFAAddCommand(parent *kingpin.CmdClause) *mfaAddCommand {
Expand All @@ -214,7 +216,9 @@ func newMFAAddCommand(parent *kingpin.CmdClause) *mfaAddCommand {
c.Flag("type", fmt.Sprintf("Type of the new MFA device (%s)", strings.Join(defaultDeviceTypes, ", "))).
EnumVar(&c.devType, defaultDeviceTypes...)
if wancli.IsFIDO2Available() {
c.Flag("allow-passwordless", "Allow passwordless logins").BoolVar(&c.allowPasswordless)
c.Flag("allow-passwordless", "Allow passwordless logins").
IsSetByUser(&c.allowPasswordlessSet).
BoolVar(&c.allowPasswordless)
}
return c
}
Expand Down Expand Up @@ -266,9 +270,7 @@ func (c *mfaAddCommand) run(cf *CLIConf) error {
switch c.devType {
case webauthnDeviceType:
// Ask the user?
// c.allowPasswordless=false at this point only means that the flag wasn't
// explicitly set.
if !c.allowPasswordless && wancli.IsFIDO2Available() {
if !c.allowPasswordlessSet && wancli.IsFIDO2Available() {
answer, err := prompt.PickOne(ctx, os.Stdout, prompt.Stdin(), "Allow passwordless logins", []string{"YES", "NO"})
if err != nil {
return trace.Wrap(err)
Expand Down
Loading