feat(extension manager): dynamically reload CA certificates#5613
feat(extension manager): dynamically reload CA certificates#5613arkodg merged 18 commits intoenvoyproxy:mainfrom
Conversation
Signed-off-by: Sapir Pol <sapir.pol@sap.com>
Signed-off-by: Sapir Pol <sapir.pol@sap.com>
Signed-off-by: Sapir Pol <sapir.pol@sap.com>
|
cc @nareddyt |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5613 +/- ##
==========================================
+ Coverage 65.19% 65.23% +0.03%
==========================================
Files 214 214
Lines 34321 34339 +18
==========================================
+ Hits 22377 22401 +24
+ Misses 10591 10578 -13
- Partials 1353 1360 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Sapir Pol <30637290+sapirpol@users.noreply.github.com>
|
@nareddyt Could you please review? |
nareddyt
left a comment
There was a problem hiding this comment.
Thanks for making this PR! A few minor comments on the production code. Though the test may need another look.
|
|
||
| caCertPEMBytes, ok := secret.Data[corev1.TLSCertKey] | ||
| if !ok { | ||
| return nil, errors.New("no TLS certificate found in CA secret") |
There was a problem hiding this comment.
| return nil, errors.New("no TLS certificate found in CA secret") | |
| return nil, fmt.Errorf("no CA certificate found in Kubernetes Secret %s in namespace %s", secret.GetName(), secret.GetNamespace()) |
- This is parsing a CA certificate, not TLS certificate. The pre-existing naming of key
corev1.TLSCertKeyis incorrect unfortunately, but we need to support it for backwards compatibility. - Let's include secret name and namespace for debuggability.
There was a problem hiding this comment.
I fixed the error message
|
|
||
| func createGetRootCertificatesHandler(ctx context.Context, client k8scli.Client, ext *egv1a1.ExtensionManager, namespace string) func(*advancedtls.ConnectionInfo) (*advancedtls.RootCertificates, error) { | ||
| return func(params *advancedtls.ConnectionInfo) (*advancedtls.RootCertificates, error) { | ||
| cp, err := getCertPoolFromSecret(ctx, client, ext, namespace) |
There was a problem hiding this comment.
This function will run in the background in a goroutine inside advancedtls, correct?
If so, I suggest you don't pass in the parent context to this function, as someone may change the parent context to cancel or timeout in the future.
Instead, create a new context in this function ctx := context.Background()
| }, | ||
| Type: corev1.SecretTypeTLS, | ||
| Data: map[string][]byte{ | ||
| corev1.TLSCertKey: certData, |
There was a problem hiding this comment.
Unfortunately this doesn't seem right. extension_manager.go line 316 is reading CA cert from corev1.TLSCertKey (yes it is incorrectly named, but that is a legacy behavior we need to support).
If so, I'm not entirely sure how this test is working (?) Because the CA cert is not in the correct place.
There was a problem hiding this comment.
I checked the test, and it worked because both the CA and the server certificate were accepted — see: https://stackoverflow.com/questions/77084841/server-certificate-used-as-ca-cert-why-does-it-work/77084918#77084918
I've now updated the test to use a self-signed certificate, so the certificate acts as both the server cert and the CA.
There was a problem hiding this comment.
Wow, did not know that. Thanks for the explanation!
There was a problem hiding this comment.
I recommend modifying the test to only pass in the exact necessary data. This makes it clearer to readers that the current naming is incorrect.
Specifically, change the secret to just this, the test should still pass:
Data: map[string][]byte{
corev1.TLSCertKey: caCert,
},
Otherwise the PR looks good.
There was a problem hiding this comment.
Thanks! I updated the secret to include only the necessary data
Thanks! I’ve made the changes and replied back. |
Signed-off-by: Sapir Pol <sapir.pol@sap.com>
Signed-off-by: Sapir Pol <sapir.pol@sap.com>
|
@nareddyt Could you please re-review the PR and trigger the tests? |
|
Hey @sapirpol can you rebase the go.mod file |
Signed-off-by: Sapir Pol <30637290+sapirpol@users.noreply.github.com>
|
Hi @arkodg, I rebased the branch. Could you please review the PR and retrigger the tests? |
What type of PR is this?
Dynamically reload CA certificates for GRPC connections on extension-manager.
What this PR does / why we need it:
This PR introduces dynamic reloading of CA certificates used by Envoy Gateway's extension manager when establishing GRPC connections. Previously, certificates were loaded once, making updates difficult without restarting the service. To resolve this, the PR uses grpc-go's advancedtls library, enabling dynamic certificate management via a custom callback that reloads the certificate.
Comparison of TLS Settings: Before vs. After Update
This change was manually tested.
Which issue(s) this PR fixes:
Fixes #5396
Release Notes: Yes