Skip to content

Commit

Permalink
Close sso mfa redirector once mfa ceremony is complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joerger committed Oct 21, 2024
1 parent 0ac421c commit 4a442ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
3 changes: 3 additions & 0 deletions api/mfa/ceremony.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type CreateAuthenticateChallengeFunc func(ctx context.Context, req *proto.Create
// req may be nil if ceremony.CreateAuthenticateChallenge does not require it, e.g. in
// the moderated session mfa ceremony which uses a custom stream rpc to create challenges.
func (c *Ceremony) Run(ctx context.Context, req *proto.CreateAuthenticateChallengeRequest, promptOpts ...PromptOpt) (*proto.MFAAuthenticateResponse, error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

switch {
case c.CreateAuthenticateChallenge == nil:
return nil, trace.BadParameter("mfa ceremony must have CreateAuthenticateChallenge set in order to begin")
Expand Down
16 changes: 15 additions & 1 deletion lib/client/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,28 @@ import (
"github.com/gravitational/teleport/api/client/proto"
"github.com/gravitational/teleport/api/mfa"
libmfa "github.com/gravitational/teleport/lib/client/mfa"
"github.com/gravitational/teleport/lib/client/sso"
)

// NewMFACeremony returns a new MFA ceremony configured for this client.
func (tc *TeleportClient) NewMFACeremony() *mfa.Ceremony {
return &mfa.Ceremony{
CreateAuthenticateChallenge: tc.createAuthenticateChallenge,
PromptConstructor: tc.NewMFAPrompt,
SSOMFACeremonyConstructor: tc.newSSOMFACeremony,
SSOMFACeremonyConstructor: func(ctx context.Context) (mfa.SSOMFACeremony, error) {
rdConfig, err := tc.ssoRedirectorConfig(ctx, "" /*connectorDisplayName*/)
if err != nil {
return nil, trace.Wrap(err)
}

rd, err := sso.NewRedirector(rdConfig)
if err != nil {
return nil, trace.Wrap(err)
}

context.AfterFunc(ctx, rd.Close)
return &sso.MFACeremony{Ceremony: sso.NewCLICeremony(rd, nil /*init*/)}, nil
},
}
}

Expand Down
16 changes: 0 additions & 16 deletions lib/client/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,11 @@ import (

"github.com/gravitational/trace"

"github.com/gravitational/teleport/api/mfa"
"github.com/gravitational/teleport/api/utils/prompt"
"github.com/gravitational/teleport/lib/client/sso"
"github.com/gravitational/teleport/lib/utils"
)

func (tc *TeleportClient) newSSOMFACeremony(ctx context.Context) (mfa.SSOMFACeremony, error) {
rdConfig, err := tc.ssoRedirectorConfig(ctx, "" /*connectorDisplayName*/)
if err != nil {
return nil, trace.Wrap(err)
}

rd, err := sso.NewRedirector(rdConfig)
if err != nil {
return nil, trace.Wrap(err)
}
defer rd.Close()

return &sso.MFACeremony{Ceremony: sso.NewCLICeremony(rd, nil /*init*/)}, nil
}

// ssoRedirectorConfig returns a standard configured sso redirector for login.
// A display name for the SSO connector can optionally be provided for minor UI improvements.
func (tc *TeleportClient) ssoRedirectorConfig(ctx context.Context, connectorDisplayName string) (sso.RedirectorConfig, error) {
Expand Down

0 comments on commit 4a442ac

Please sign in to comment.