Skip to content

[v11] Connect: Add prerequisites for gracefully handling expired db proxy certs#18678

Merged
ravicious merged 2 commits intobranch/v11from
ravicious/v11/backport-18259
Nov 23, 2022
Merged

[v11] Connect: Add prerequisites for gracefully handling expired db proxy certs#18678
ravicious merged 2 commits intobranch/v11from
ravicious/v11/backport-18259

Conversation

@ravicious
Copy link
Copy Markdown
Member

Backport #18259.

…erts (#18259)

* Log gateway.Close errors during test cleanups

Unless gateway.Close is called on a gateway that was already closed, it
shouldn't return an error.

However, when working on handling expired certs in Connect I ran into a
buggy test where that error from gateway.Close provided a crucial clue
in fixing the bug. But because initially it was simply ignored, it took
me a while to figure out what was going on.

That's why this commit adds logging around those errors.

2 out of those 3 places are helper functions which get used in a variety
of tests, hence why they call t.Cleanup. The other place does call
gateway.Close eventually but we still use t.Cleanup in case the
execution doesn't get to that point.

* Automatically add useful fields to gateway loggers

It's useful to see what resource the gateway is targeting and what is
the URI of the gateway.

Previously the field with URI was hardcoded in cluster_gateways.go or
added only when cfg.Log was nil, meaning that we weren't able to benefit
from it in places such as gateway_test.go.

This commit makes it so that the `resource` and `gateway` fields are
added to any logger that is passed through gateway.Config.

* Remove copylocks warning from Gateway.NewWithLocalPort

gateway.Gateway holds a mutex in one of its fields. NewWithLocalPort
accepted gateway by value so vet was issuing a warning about copying a
lock.

NewWithLocalPort doesn't actually use the copied lock. But it makes
sense to get rid of the warning anyway.

* Make ReissueDBCerts accept tlsca.RouteToDatabase as arg

ReissueDBCerts used to accept a full-blown types.Database object just to
read a couple of fields from it. In the context of Connect, such object
is obtainable only by making a request to the cluster.

However, in the upcoming PR we want to be able to reissue the cert
without having to perform an unnecessary request to the cluster.

gateway.Gateway already holds all data we need to reissue the cert, so
let's make ReissueDBCerts accept tlsca.RouteToDatabase instead of
types.Database to avoid making that extra request.

* Add Gateway.ReloadCert

In the upcoming PR, after we reissue the db cert, we need to be able to
update the cert used by the running alpn.LocalProxy. This commit exposes
exactly that functionality.

Also, this commit adds RWMutex to Gateway to avoid a situation where
multiple goroutines attempt to reload the cert. This shouldn't happen
under normal circumstances but better safe than sorry.

RWMutex is also used for any field on Gateway that has a setter.

* Add basic implementation of LocalProxyMiddleware

* Add OnExpiredCert callback to gateway.Config

This callback will let the layer above gateway.Gateway handle a
situation in which the cert used by the gateway has expired but there's
a client that tries to make a connection through the gateway.

gateway.Gateway doesn't have the ability to reissue the cert by itself,
hence why we need to accept a callback from above.
@ravicious ravicious enabled auto-merge (squash) November 22, 2022 13:53
@ravicious ravicious merged commit c40418b into branch/v11 Nov 23, 2022
@ravicious ravicious deleted the ravicious/v11/backport-18259 branch November 23, 2022 11:04
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.

3 participants