Only create the dex TLS key pair when dex is enabled - #5141
Open
tmjd wants to merge 1 commit into
Open
Conversation
tmjd
commented
Aug 5, 2026
utils.DexEnabled() returns false when Authentication.spec.oidc.type is Tigera, and dex is not deployed in that case. The authentication controller nonetheless called GetOrCreateKeyPair() for tigera-dex-tls unconditionally, which generates a new key pair whenever the existing secret is missing, expired or otherwise unusable. The component that persists that key pair is only rendered when dex is enabled, so on those clusters nothing ever writes the new secret. Every reconcile therefore generated and discarded a key pair, and an expired tigera-dex-tls secret was re-detected indefinitely, producing a steady stream of "KeyPair is an expired legacy operator cert, make a new one" log lines plus wasted RSA key generation on a hot controller. Compute enableDex before the key pair is needed and only build it when dex is enabled. render.Dex() previously required a key pair even on the DeleteDex path, because Objects() builds the Deployment and the ConfigMap before checking DeleteDex and both dereference TLSKeyPair. Those two are only ever deleted on that path, so identify them by name instead. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tmjd
force-pushed
the
tsla-11722-dex-keypair-only-when-enabled
branch
from
August 5, 2026 15:22
b98bd91 to
ea82a7d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Bug fix.
utils.DexEnabled()returns false whenAuthentication.spec.oidc.typeisTigera, and dex is not deployed in that case. The authentication controller nonetheless callsGetOrCreateKeyPair()fortigera-dex-tlsunconditionally (authentication_controller.go:282), which generates a new key pair whenever the existing secret is missing, expired or otherwise unusable.The component that persists that key pair —
rcertificatemanagement.CertificateManagement(...)— is only appended tocomponentswhenenableDexis true. So on a cluster that does not run dex, nothing ever writes the newly generated secret. The result is that every reconcile generates and immediately discards an RSA key pair, and an expiredtigera-dex-tlssecret is re-detected forever:This never converges: while dex is disabled nothing can replace the expired secret, so the same log line repeats on every reconcile indefinitely. The cost is wasted key generation and signing on a hot controller, plus permanent log noise.
What changed
pkg/controller/authentication/authentication_controller.go— hoistenableDex(it only depends on the already-fetchedAuthentication) above the point where the key pair is built, and only callGetOrCreateKeyPair()when dex is enabled.CheckKeyPairWarnings()is guarded the same way, since it dereferences the key pair.pkg/render/dex.go—Objects()builtc.deployment()andc.configMap()before checkingDeleteDex, and both dereferencec.cfg.TLSKeyPair, so a nil key pair would panic on the teardown path. Those two objects are only ever deleted on that path, so they are now identified by name and GVK instead of being fully rendered.Not changed: when dex is enabled the behaviour is identical, and this does not alter the contents of any rendered object.
Testing
pkg/render/dex_test.gocoveringDeleteDex: truewith a nilTLSKeyPair, asserting nothing is rendered for creation and that the Deployment and ConfigMap are in the delete list. This test panics without thedex.gochange.go test ./pkg/render— 516 specs pass.go test ./pkg/controller/authentication/...— passes.gofmtclean;go vetclean on both changed packages.Components affected
The authentication controller and the dex renderer only. Clusters using
oidc.typeother thanTigera(i.e. those that actually deploy dex) are unaffected.Release Note
For PR author
make gen-filesmake gen-versionsFor PR reviewers
A note for code reviewers - all pull requests must have the following:
kind/bugif this is a bugfix.kind/enhancementif this is a a new feature.enterpriseif this PR applies to Calico Enterprise only.