Skip to content

Commit

Permalink
Error if users attempt to do tsh login --headless (gravitational#30298
Browse files Browse the repository at this point in the history
)

* Do not trigger SSO warning for local auth

* Escalate headless debug log to error

* Tweak error message

Co-authored-by: Zac Bergquist <[email protected]>

---------

Co-authored-by: Zac Bergquist <[email protected]>
  • Loading branch information
codingllama and zmb3 authored Aug 10, 2023
1 parent ca74d87 commit 5d7ca18
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
6 changes: 6 additions & 0 deletions api/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ const (
OktaAssignmentTargetUnknown = "unknown"
)

// LocalConnectors are the system connectors that use local auth.
var LocalConnectors = []string{
LocalConnector,
PasswordlessConnector,
}

// SystemConnectors lists the names of the system-reserved connectors.
var SystemConnectors = []string{
LocalConnector,
Expand Down
5 changes: 3 additions & 2 deletions lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3531,8 +3531,9 @@ func (tc *TeleportClient) getSSHLoginFunc(pr *webclient.PingResponse) (SSHLoginF
return tc.headlessLogin(ctx, priv)
}, nil
}
log.Debug("Headless login is disabled for this command. Only 'tsh ls', 'tsh ssh', and 'tsh scp' are supported. Defaulting to local authentication methods.")
fallthrough
return nil, trace.BadParameter("" +
"Headless login is not supported for this command. " +
"Only 'tsh ls', 'tsh ssh', and 'tsh scp' are supported.")
case constants.LocalConnector, "":
// if passwordless is enabled and there are passwordless credentials
// registered, we can try to go with passwordless login even though
Expand Down
23 changes: 7 additions & 16 deletions tool/tsh/common/tsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -1838,23 +1838,14 @@ func onLogin(cf *CLIConf) error {
}
}

// If the cluster is using single-sign on, providing the user name
// with --user is likely a mistake, so display a warning.
if cf.Username != "" {
displayIgnoreUserWarning := false
if cf.AuthConnector != "" && cf.AuthConnector != constants.LocalConnector && cf.AuthConnector != constants.PasswordlessConnector {
displayIgnoreUserWarning = true
} else if cf.AuthConnector == "" {
// Get the Ping so we check if the default Auth type is SSO
pr, err := tc.Ping(cf.Context)
if err != nil {
return trace.Wrap(err, "Teleport proxy not available at %s.", tc.WebProxyAddr)
}
if pr.Auth.Type != constants.LocalConnector && pr.Auth.Type != constants.PasswordlessConnector {
displayIgnoreUserWarning = true
}
// If the cluster is using single-sign on, providing the user name with --user
// is likely a mistake, so display a warning.
if cf.Username != "" && !slices.Contains(constants.LocalConnectors, cf.AuthConnector) {
pr, err := tc.Ping(cf.Context)
if err != nil {
return trace.Wrap(err, "Teleport proxy not available at %s.", tc.WebProxyAddr)
}
if displayIgnoreUserWarning {
if !slices.Contains(constants.LocalConnectors, pr.Auth.Type) {
fmt.Fprintf(os.Stderr, "WARNING: Ignoring Teleport user (%v) for Single Sign-On (SSO) login.\nProvide the user name during the SSO flow instead. Use --auth=local if you did not intend to login with SSO.\n", cf.Username)
}
}
Expand Down

0 comments on commit 5d7ca18

Please sign in to comment.