Skip to content

[shell-operator] fix: reload renewed TLS certificate in webhook server - #972

Open
yuminn-k wants to merge 1 commit into
flant:mainfrom
yuminn-k:fix-webhook-cert-reload
Open

yuminn-k wants to merge 1 commit into
flant:mainfrom
yuminn-k:fix-webhook-cert-reload

Conversation

@yuminn-k

Copy link
Copy Markdown

Overview

Reload the webhook server's TLS key pair when the certificate or key file changes on disk.

What this PR does / why we need it

WebhookServer.Start() loaded the key pair once and pinned it in tls.Config.Certificates, so a certificate renewed in place (for example by cert-manager) was never served until the process restarted.

The server now uses tls.Config.GetCertificate backed by a small certReloader. On each handshake it stats the cert and key files and reloads the pair when either mtime changed. If the new files fail to load (for example a half-written renewal), it logs a warning and keeps serving the previous pair. The initial load in Start() still fails fast. No new dependencies.

Test_ServerReloadsRenewedCertificate starts the server, overwrites the pair with a second one, and checks the leaf received via tls.Dial. It fails on main (serial = 1, want 2) and passes with this change.

Closes #487

Special notes for your reviewer

The check is a stat per handshake rather than a file watcher, which keeps the change dependency-free and also covers Kubernetes secret volume updates (symlink swaps change the resolved file's mtime).

This branch has not been deployed

No deployments
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.

Validating webhook does not pick up new certificate when renewed by certificate manager

1 participant