Use cached remote clients in Connect#38202
Use cached remote clients in Connect#38202gzdunek merged 14 commits intogzdunek/cache-remote-clientfrom
Conversation
There was a problem hiding this comment.
If I didn't remove the "old" client, the user's access hasn't been changed.
9adb3f6 to
5536464
Compare
5536464 to
ad7405d
Compare
ad7405d to
75cc2a3
Compare
|
I didn't test the case when To fix this, I should add this error to the list of retryable errors teleport/web/packages/teleterm/src/ui/utils/retryWithRelogin.ts Lines 95 to 100 in 1b2f271 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 :/ |
ravicious
left a comment
There was a problem hiding this comment.
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.
* 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`
* 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)
* 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)
2/2 of #15603
This PR replaces calls to
clusterClient.ConnectToProxy()withdaemon.GetRemoteClient().Most of the callsites now receive
auth.ClientIthat they can use to make remote calls.This also aligns with the idea of refactoring
clusters.Cluster. Most of its methods now no longer needclusterClientand can be easily extracted to smaller packages likeunifiedresources.Changelog: Improve performance of remote calls in Teleport Connect.