Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
This PR adds a
Provider
struct in order to hold the TLS certificate and private key in memory, as well as somewatchers
.The
watchers
are responsible for watching for file events (e.g., file write) and executes a set of actions when those events are noticed. Two watchers have been created that have actionst to refresh the TLS certificate and key respectively when the files change. These are then used by theGetCertificate
function in the serverstls.Config
on every request.Rather than using
tls.LoadX509KeyPair
or something similar (which decodes the certificate PEMs) on eachGetCertificate
call (i.e., every request), we instead do this on the reloading of the cert and key into theProvider
struct. This means that CPU is saved because by the time it is being used byGetCertificate
the certificate and key are already parsed into a format that the TLS Config can use straight away.I have put this PR as WIP for now. I think it is worth spending some time explaining the changes made and making sure that everyone is happy with them. I have also written some functionality to hot reload the Gatekeeper
ClientCA
certificate, but I want to first validate that it is "safe" as it makes use of theVerifyPeerCertificate
which customises the TLS handshake flow on the server side.