Skip to content
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
21 changes: 12 additions & 9 deletions lib/teleterm/apiserver/handler/handler_auth.go
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding "as different user" to the changelog? The current version makes it sound more concerning than it really is. 😅

I'm also thinking if we need to include the changelog here at all. 🤔 OTOH it's good to have a point of reference in the changelog in case this change breaks something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding "as different user" to the changelog?

👍

OTOH it's good to have a point of reference in the changelog in case this change breaks something.

Agree, let's keep it.

Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ func (s *Handler) Login(ctx context.Context, req *api.LoginRequest) (*api.EmptyR
return nil, trace.BadParameter("cluster URI must be a root URI")
}

if err = s.DaemonService.ClearCachedClientsForRoot(cluster.URI); err != nil {
return nil, trace.Wrap(err)
}

if req.Params == nil {
return nil, trace.BadParameter("missing login parameters")
}
Expand All @@ -62,6 +58,13 @@ func (s *Handler) Login(ctx context.Context, req *api.LoginRequest) (*api.EmptyR
return nil, trace.BadParameter("unsupported login parameters")
}

// Clear the cache after login, not before.
// During a re-login, another thread might try to retrieve a client from the cache.
// Because the cache is empty, it could initialize a new client using the previous certificate.
if err = s.DaemonService.ClearCachedClientsForRoot(cluster.URI); err != nil {
return nil, trace.Wrap(err)
}

return &api.EmptyResponse{}, nil
}

Expand Down Expand Up @@ -92,16 +95,16 @@ func (s *Handler) LoginPasswordless(stream api.TerminalService_LoginPasswordless
// daemon.Service.ResolveClusterURI.
clusterClient.MFAPromptConstructor = nil

if err := s.DaemonService.ClearCachedClientsForRoot(cluster.URI); err != nil {
return trace.Wrap(err)
}

// Start the prompt flow.
if err := cluster.PasswordlessLogin(stream.Context(), stream); err != nil {
return trace.Wrap(err)
}

return nil
// Clear the cache after login, not before.
// During a re-login, another thread might try to retrieve a client from the cache.
// Because the cache is empty, it could initialize a new client using the previous certificate.
err = s.DaemonService.ClearCachedClientsForRoot(cluster.URI)
return trace.Wrap(err)
}

// Logout logs the user out of the cluster and cleans up associated resources.
Expand Down
Loading