Skip to content

Use cached remote clients in Connect#38202

Merged
gzdunek merged 14 commits intogzdunek/cache-remote-clientfrom
gzdunek/use-cached-remote-client
Feb 28, 2024
Merged

Use cached remote clients in Connect#38202
gzdunek merged 14 commits intogzdunek/cache-remote-clientfrom
gzdunek/use-cached-remote-client

Conversation

@gzdunek
Copy link
Copy Markdown
Contributor

@gzdunek gzdunek commented Feb 14, 2024

2/2 of #15603

This PR replaces calls to clusterClient.ConnectToProxy() with daemon.GetRemoteClient().
Most of the callsites now receive auth.ClientI that they can use to make remote calls.
This also aligns with the idea of refactoring clusters.Cluster. Most of its methods now no longer need clusterClient and can be easily extracted to smaller packages like unifiedresources.

Changelog: Improve performance of remote calls in Teleport Connect.

Comment thread lib/teleterm/daemon/daemon.go Outdated
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.

If I didn't remove the "old" client, the user's access hasn't been changed.

@gzdunek gzdunek marked this pull request as ready for review February 14, 2024 11:54
@gzdunek gzdunek requested a review from ravicious February 14, 2024 11:54
@github-actions github-actions Bot requested review from lxea and probakowski February 14, 2024 11:54
@gzdunek gzdunek requested review from espadolini and rosstimothy and removed request for lxea and probakowski February 14, 2024 11:55
@gzdunek gzdunek marked this pull request as draft February 15, 2024 14:14
@gzdunek gzdunek force-pushed the gzdunek/use-cached-remote-client branch from 9adb3f6 to 5536464 Compare February 15, 2024 18:16
@gzdunek gzdunek marked this pull request as ready for review February 15, 2024 18:17
@gzdunek gzdunek force-pushed the gzdunek/use-cached-remote-client branch from 5536464 to ad7405d Compare February 20, 2024 14:30
@gzdunek gzdunek force-pushed the gzdunek/use-cached-remote-client branch from ad7405d to 75cc2a3 Compare February 20, 2024 14:37
@gzdunek
Copy link
Copy Markdown
Contributor Author

gzdunek commented Feb 21, 2024

I didn't test the case when disconnect_expired_cert is false properly, in that situation the connection is not closed, and a call to GenerateUserCerts with expired cert returns *interceptors.RemoteError access denied: client credentials have expired, please relogin error. The user just sees 'access denied' message instead of a login modal.

To fix this, I should add this error to the list of retryable errors

export function isRetryable(error: unknown): boolean {
// TODO(ravicious): Replace this with actual check on metadata.
return (
error instanceof Error &&
(error.message.includes('ssh: handshake failed') ||
error.message.includes('ssh: cert has expired'))

but since it is an access denied error, the actual message is removed and I'm not able to inspect it #32550.

I think I have to fix the linked issue first and then come back here :/

Comment thread lib/teleterm/daemon/daemon_headless.go Outdated
Comment thread lib/teleterm/daemon/daemon.go
@ravicious ravicious self-requested a review February 21, 2024 09:34
Comment thread lib/teleterm/apiserver/middleware.go Outdated
Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

Fantastic work. I managed to get through the first commit and QA the app a little bit. I'll continue the review tomorrow.

Note to myself: test access requests and headless auth.

Comment thread lib/teleterm/clusters/cluster_databases.go
Comment thread lib/teleterm/daemon/daemon.go
@ravicious ravicious self-requested a review February 22, 2024 17:06
Comment thread lib/teleterm/apiserver/handler/handler_auth.go Outdated
Comment thread lib/teleterm/clusters/cluster_access_requests.go Outdated
Comment thread lib/teleterm/clusters/cluster_headless.go Outdated
Comment thread lib/teleterm/daemon/daemon.go Outdated
Comment thread lib/teleterm/daemon/daemon.go Outdated
Comment thread lib/teleterm/daemon/daemon.go Outdated
Comment thread lib/teleterm/daemon/daemon_test.go Outdated
Comment thread lib/teleterm/clusters/cluster_gateways.go Outdated
Comment thread lib/teleterm/clusters/gateway_creator.go
Comment thread lib/teleterm/apiserver/handler/handler_auth.go Outdated
Comment thread lib/teleterm/apiserver/handler/handler_auth.go Outdated
Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

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

Nice work @gzdunek!

@gzdunek gzdunek merged commit 97c48cb into gzdunek/cache-remote-client Feb 28, 2024
@gzdunek gzdunek deleted the gzdunek/use-cached-remote-client branch February 28, 2024 07:27
@public-teleport-github-review-bot
Copy link
Copy Markdown

@gzdunek See the table below for backport results.

Branch Result
branch/v15 Failed

github-merge-queue Bot pushed a commit that referenced this pull request Feb 28, 2024
* Add remote client cache

* Add an integration test

* Close all clients when stopping the service

* Move RemoteClientCache to the place where it is used

* Do not check client cert in `Get`

* Fix code style issues

* Prevent potential race condition when removing a cached client

* Test concurrent calls to `Get`

* Add TODO

* `remoteclientcache` -> `clientcache`

* Reduce the `err` scope

* Move `Config` closer to `New` and docs

* Fix lint

* Improve logging and error handling

* Add missing comments

* `Close` -> `Clear`

* Improve the test

* Remove mentions about "remote" client

* Pass `cfg` directly to `Cache`

* `InvalidateForRootCluster` -> `ClearForRootCluster`

* Add docs for the interface

* `ClearForRootCluster` -> `ClearForRoot`

* Add config validation

* Log multiple fields at once

* Improve setting logger

* Use cached remote clients in Connect (#38202)

* Replace all simple `c.clusterClient.ConnectToProxy()` calls

* Use cached proxy client to create gateways

* Use cached proxy client to assume roles

* Invalidate clients when logging in and out

* Gracefully handle expired cert error returned by the server

* Drop `GetRootClusterURI` in headless auth watcher since URIs are already root URIs

* Simplify error check

* Make `auth.ClientI` parameter naming more consistent, use `root` prefix when needed

* Reduce error scope where possible

* Clear cached clients before passwordless login

* Use `fakeClientCache` without pointers

* Move separate `proxyClient` parameter to `CreateGatewayParams` in the gateways code

* Replace checking error string with `client.ErrClientCredentialsHaveExpired`
gzdunek added a commit that referenced this pull request Mar 6, 2024
* Add remote client cache

* Add an integration test

* Close all clients when stopping the service

* Move RemoteClientCache to the place where it is used

* Do not check client cert in `Get`

* Fix code style issues

* Prevent potential race condition when removing a cached client

* Test concurrent calls to `Get`

* Add TODO

* `remoteclientcache` -> `clientcache`

* Reduce the `err` scope

* Move `Config` closer to `New` and docs

* Fix lint

* Improve logging and error handling

* Add missing comments

* `Close` -> `Clear`

* Improve the test

* Remove mentions about "remote" client

* Pass `cfg` directly to `Cache`

* `InvalidateForRootCluster` -> `ClearForRootCluster`

* Add docs for the interface

* `ClearForRootCluster` -> `ClearForRoot`

* Add config validation

* Log multiple fields at once

* Improve setting logger

* Use cached remote clients in Connect (#38202)

* Replace all simple `c.clusterClient.ConnectToProxy()` calls

* Use cached proxy client to create gateways

* Use cached proxy client to assume roles

* Invalidate clients when logging in and out

* Gracefully handle expired cert error returned by the server

* Drop `GetRootClusterURI` in headless auth watcher since URIs are already root URIs

* Simplify error check

* Make `auth.ClientI` parameter naming more consistent, use `root` prefix when needed

* Reduce error scope where possible

* Clear cached clients before passwordless login

* Use `fakeClientCache` without pointers

* Move separate `proxyClient` parameter to `CreateGatewayParams` in the gateways code

* Replace checking error string with `client.ErrClientCredentialsHaveExpired`

(cherry picked from commit 39f9951)
github-merge-queue Bot pushed a commit that referenced this pull request Mar 7, 2024
* Cache remote clients in Connect  (#38201)

* Add remote client cache

* Add an integration test

* Close all clients when stopping the service

* Move RemoteClientCache to the place where it is used

* Do not check client cert in `Get`

* Fix code style issues

* Prevent potential race condition when removing a cached client

* Test concurrent calls to `Get`

* Add TODO

* `remoteclientcache` -> `clientcache`

* Reduce the `err` scope

* Move `Config` closer to `New` and docs

* Fix lint

* Improve logging and error handling

* Add missing comments

* `Close` -> `Clear`

* Improve the test

* Remove mentions about "remote" client

* Pass `cfg` directly to `Cache`

* `InvalidateForRootCluster` -> `ClearForRootCluster`

* Add docs for the interface

* `ClearForRootCluster` -> `ClearForRoot`

* Add config validation

* Log multiple fields at once

* Improve setting logger

* Use cached remote clients in Connect (#38202)

* Replace all simple `c.clusterClient.ConnectToProxy()` calls

* Use cached proxy client to create gateways

* Use cached proxy client to assume roles

* Invalidate clients when logging in and out

* Gracefully handle expired cert error returned by the server

* Drop `GetRootClusterURI` in headless auth watcher since URIs are already root URIs

* Simplify error check

* Make `auth.ClientI` parameter naming more consistent, use `root` prefix when needed

* Reduce error scope where possible

* Clear cached clients before passwordless login

* Use `fakeClientCache` without pointers

* Move separate `proxyClient` parameter to `CreateGatewayParams` in the gateways code

* Replace checking error string with `client.ErrClientCredentialsHaveExpired`

(cherry picked from commit 39f9951)

* Temporarily disable flaky part of `TestClientCache` (#38798)

(cherry picked from commit 7067a88)

* Make calls to the auth server concurrently (#38955)

* Make calls to the auth server concurrently

* Enhance the comment about preferences upsert

* Summarize how `userpreferences.Update` works

(cherry picked from commit ddc45a4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants