Skip to content

Connect: Check db cert before using it for local proxy#18740

Merged
ravicious merged 12 commits intomasterfrom
ravicious/check-cert-subject
Nov 29, 2022
Merged

Connect: Check db cert before using it for local proxy#18740
ravicious merged 12 commits intomasterfrom
ravicious/check-cert-subject

Conversation

@ravicious
Copy link
Copy Markdown
Member

@ravicious ravicious commented Nov 23, 2022

This PR addresses an issue that was found during the review of another PR (#18259 (comment)). Best reviewed commit by commit.

At the moment, when Connect creates a local db proxy, it obtains a cert for the database, saves it to disk, then loads it from disk and provides it to alpnproxy.LocalProxy. Between being saved and loaded, the cert can be modified by another process, such as the user executing tsh db login with different --db-user or --db-name than we issued the cert for. It's unlikely to happen but still possible.

Why not just avoid saving the cert to disk? This is a form of tech debt that stems from Connect using TeleportClient.ReissueUserCerts to obtain db certs. That method doesn't return the cert, it saves it directly to disk.

Once we add per-session MFA support to Connect, we'll be able to address this. But for now, we have to check the cert after loading it from disk. In case the check fails, the user will see the error message and will be able to recreate the local proxy with the same params (thus effectively reissuing the cert).


Since we now check the cert when initializing gateway.Gateway, I had to update the tests to use valid certs since in the past I provided some bogus ones – they wouldn't be checked until something established an actual connection through the proxy.

@github-actions github-actions Bot requested review from Tener and smallinsky November 23, 2022 11:34
@ravicious ravicious requested review from GavinFrazar and removed request for Tener November 23, 2022 11:34
@ravicious ravicious force-pushed the ravicious/check-cert-subject branch from 100740b to 7279a2b Compare November 25, 2022 16:51
Those tests are too fast and simple to run them in parallel.
Those helpers will be useful in lib/teleterm tests where we need to create
a gateway which spawns an alpnproxy.LocalProxy underneath.
We're going to need a standalone version of this function in the next
commit.
This function builds on top of alpnproxytest.MustGenCertSignedWithCA.

In alpnproxy, LocalProxy operates on certs solely in memory through
NewLocalProxy and LocalProxy.SetCerts.

Connect on the other hand assumes that the key pair can be loaded from disk,
so we have to provide a function which generates the certs and then saves
them to file.

In the next commit, we're going to check the subject of the cert, so Connect
tests need a way of generating valid certs.
@ravicious ravicious force-pushed the ravicious/check-cert-subject branch from 7279a2b to 00dc268 Compare November 25, 2022 17:13
Comment thread lib/srv/alpnproxy/helpers_test.go Outdated
Comment thread lib/teleterm/api/uri/uri_test.go Outdated
Comment thread lib/teleterm/gatewaytest/helpers.go Outdated
Comment thread lib/teleterm/api/uri/uri.go
@ravicious ravicious requested a review from smallinsky November 28, 2022 11:13
Comment thread lib/teleterm/api/uri/uri.go Outdated
Co-authored-by: Marek Smoliński <marek@goteleport.com>
Copy link
Copy Markdown
Contributor

@GavinFrazar GavinFrazar left a comment

Choose a reason for hiding this comment

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

approved with some nits

Comment thread lib/teleterm/gateway/gateway.go Outdated
Comment thread lib/srv/alpnproxy/local_proxy.go Outdated
@ravicious ravicious enabled auto-merge (squash) November 29, 2022 09:54
@ravicious ravicious merged commit 59a96be into master Nov 29, 2022
@github-actions
Copy link
Copy Markdown
Contributor

@ravicious See the table below for backport results.

Branch Result
branch/v11 Failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants