Skip to content

Conversation

@jimmidyson
Copy link
Member

@jimmidyson jimmidyson commented Nov 26, 2025

What this PR does / why we need it:

The current TLS configuration was overriding the TLSConfig for the global http.DefaultClient. This call is being used by controllers such as the ExtensionConfig controller which calls this function from multiple concurrent workers. This leads to a race where the TLS ServerName is configured differently to that of the URL it is trying to call and X509 validation fails. An example can be seen from the CAPI logs below:

"Reconciler error" err="failed to discover ExtensionConfig extension-config-a: failed to discover extension \"extension-config-a\": http call failed: Post \"https://extension-config-a-runtimehooks.extension-config-a-system.svc:443/hooks.runtime.cluster.x-k8s.io/v1alpha1/discovery?timeout=10s\": tls: failed to verify certificate: x509: certificate is valid for extension-config-a-runtimehooks.extension-config-a-system.svc, extension-config-a-runtimehooks.extension-config-a-system.svc.cluster.local, not extension-config-b.extension-config-b-system.svc" controller="extensionconfig" controllerGroup="runtime.cluster.x-k8s.io" controllerKind="ExtensionConfig" ExtensionConfig="extension-config-a" namespace="" name="extension-config-a" reconcileID="dfd00b69-3666-4818-b4a0-52eb1c391848"
"Reconciler error" err="failed to discover ExtensionConfig extension-config-b: failed to discover extension \"extension-config-b\": http call failed: Post \"https://extension-config-b.extension-config-b-system.svc:443/hooks.runtime.cluster.x-k8s.io/v1alpha1/discovery?timeout=10s\": tls: failed to verify certificate: x509: certificate is valid for extension-config-b.extension-config-b-system.svc, extension-config-b.extension-config-b-system.svc.cluster.local, not extension-config-a-runtimehooks.extension-config-a-system.svc" controller="extensionconfig" controllerGroup="runtime.cluster.x-k8s.io" controllerKind="ExtensionConfig" ExtensionConfig="extension-config-b" namespace="" name="extension-config-b" reconcileID="4cc93a96-cfcf-49f8-8276-b3725fc8e1b8"

Notice how the URL and the expected hostname are swapped in each log indicating a race (TLSConfig being reconfigured in the middle of the call by different worker threads).

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

The current TLS configuration was overriding the TLSConfig for the global
`http.DefaultClient`. This call is being used by controllers such as the
`ExtensionConfig` controller which calls this function from multiple
concurrent workers. This leads to a race where the TLS `ServerName` is
configured differently to that of the URL it is trying to call and X509
validation fails. An example can be seen from the CAPI logs below:

```
E1126 12:43:22.449064       1 controller.go:347] "Reconciler error" err="failed to discover ExtensionConfig extension-config-a: failed to discover extension \"extension-config-a\": http call failed: Post \"https://extension-config-a-runtimehooks.extension-config-a-system.svc:443/hooks.runtime.cluster.x-k8s.io/v1alpha1/discovery?timeout=10s\": tls: failed to verify certificate: x509: certificate is valid for extension-config-a-runtimehooks.extension-config-a-system.svc, extension-config-a-runtimehooks.extension-config-a-system.svc.cluster.local, not extension-config-b.extension-config-b-system.svc" controller="extensionconfig" controllerGroup="runtime.cluster.x-k8s.io" controllerKind="ExtensionConfig" ExtensionConfig="extension-config-a" namespace="" name="extension-config-a" reconcileID="dfd00b69-3666-4818-b4a0-52eb1c391848"
E1126 12:53:42.919995       1 controller.go:347] "Reconciler error" err="failed to discover ExtensionConfig extension-config-b: failed to discover extension \"extension-config-b\": http call failed: Post \"https://extension-config-b.extension-config-b-system.svc:443/hooks.runtime.cluster.x-k8s.io/v1alpha1/discovery?timeout=10s\": tls: failed to verify certificate: x509: certificate is valid for extension-config-b.extension-config-b-system.svc, extension-config-b.extension-config-b-system.svc.cluster.local, not extension-config-a-runtimehooks.extension-config-a-system.svc" controller="extensionconfig" controllerGroup="runtime.cluster.x-k8s.io" controllerKind="ExtensionConfig" ExtensionConfig="extension-config-b" namespace="" name="extension-config-b" reconcileID="4cc93a96-cfcf-49f8-8276-b3725fc8e1b8"
```

Notice how the URL and the expected hostname are swapped in each log
indicating a race (TLSConfig being reconfigured in the middle of the
call by different worker threads.
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area PR is missing an area label labels Nov 26, 2025
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Nov 26, 2025
@jimmidyson
Copy link
Member Author

/area clusterclass

@k8s-ci-robot k8s-ci-robot added area/clusterclass Issues or PRs related to clusterclass and removed do-not-merge/needs-area PR is missing an area label labels Nov 26, 2025
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, reusing the DefaultClient seems like a bug here.

/lgtm
/hold
/cc @chrischdi
PTAL for second review if possible.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 26, 2025
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 26, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 6ce10d71fe63f6473fb69822fd1a88e49da8bc44

@sivchari
Copy link
Member

Thx!

/lgtm

@neolit123
Copy link
Member

/approve
/hold cancel

if there are follow-up concerns, let's revert.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 27, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: neolit123

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 27, 2025
@k8s-ci-robot k8s-ci-robot merged commit 4209d6c into kubernetes-sigs:main Nov 27, 2025
32 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.13 milestone Nov 27, 2025
@jimmidyson
Copy link
Member Author

jimmidyson commented Nov 27, 2025

@neolit123 Are you OK for me to backport this to release-1.12, release-1.11 and release-1.10? Are you still cutting upstream releases for those minors?

@jimmidyson
Copy link
Member Author

/cherry-pick release-1.12
/cherry-pick release-1.11
/cherry-pick release-1.10

@k8s-infra-cherrypick-robot

@jimmidyson: new pull request created: #13061

In response to this:

/cherry-pick release-1.12
/cherry-pick release-1.11
/cherry-pick release-1.10

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

@jimmidyson: new pull request created: #13062

In response to this:

/cherry-pick release-1.12
/cherry-pick release-1.11
/cherry-pick release-1.10

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

@jimmidyson: new pull request created: #13063

In response to this:

/cherry-pick release-1.12
/cherry-pick release-1.11
/cherry-pick release-1.10

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@neolit123
Copy link
Member

@neolit123 Are you OK for me to backport this to release-1.12, release-1.11 and release-1.10? Are you still cutting upstream releases for those minors?

yes, releases are being cut for these.

@fabriziopandini
Copy link
Member

if there are follow-up concerns, let's revert.

@neolit123 please give maintainers time to look into PRs
we would prefer if maintainers can chime in before merging instead of dealing with revert across four branches.

@jimmidyson
Copy link
Member Author

@fabriziopandini Do you have concerns with this PR? Let me know so I can fix anything up 🙏

@fabriziopandini
Copy link
Member

I will take a look at the change, but It would have been better if a mantainers can do this before PR are merged and in this case also backported.

@chrischdi
Copy link
Member

💯 , that would be great! We are close to the release and should be careful on the changes we do.

@jimmidyson
Copy link
Member Author

I will take a look at the change

Let me know once you've had a look and if it needs a different approach.

It would have been better if mantainers can do this before PR are merged and in this case also backported.

If that's the case, perhaps the approvers group needs to be trimmed accordingly?

@fabriziopandini
Copy link
Member

Note: this PR merged without running any E2E test that exercise the most of the runtime extension machinery, we should check periodic tomorrow.

Comment on lines +521 to +522
client := &http.Client{}
defer client.CloseIdleConnections()
Copy link
Member

@fabriziopandini fabriziopandini Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimmidyson with this change we are moving away from a single, long lived http.Client and starting using many short lived httpClients, which as far as I understand, it means to give up on all the optimisations that exists inside golang http client (and defer client.CloseIdleConnections() makes this very explicit)

I need some time to dig more into details, but I was wondering what is your take on this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I'm not too worried about it because from what I can see this client is not that heavily used.

However I can take a look and try to provide a custom transport instead that dynamically configures the TLSConfig instead of creating a new client each time.

Copy link
Member Author

@jimmidyson jimmidyson Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabriziopandini Pushed #13064 as an alternative implementation that fixes the same issue without creating a new http.Client every call, while avoiding reconfiguring the global http.DefaultClient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I can see this client is not that heavily used

This client is used by all the runtime extension calls; it is true that we did a few optimisations to reduce the number of calls, but it is definitely used in few controllers now.

However I can take a look and try to provide a custom transport instead that dynamically configures the TLSConfig instead of creating a new client each time.

Thanks. I will try to discuss with other maintainers what is the best solution here.

However, I also think that we should split the discussion in two parts:

  • what to do with the change that was already backported (we are past rc.0 and we should not take any risk)
  • what to do on main

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if #13064 is applied on top of all branches it will be exactly the same as it was before perf wise, but actually not having the bug of TLS config race..

and yes, i'd find it highly unlikely that a new client for each call would kick any bee hives.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to fix the race one way or another. I can understand being rush averse at this stage of an RC, but we need to fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimmidyson BTW, i think something that is missing in the OP is the explanation of the issue at extension discovery.
i.e. what happens due to the TLS config race at scale.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this occurs the ExtensionConfigs become unreconciled and therefore ClusterClasses that reference them also become unreconcilable. Sorry I don't have resource histories showing this but the log I shared in the OP would trigger this.

We're hitting this with just 2 ExtensionConfigs and luckily for us so far this has recovered pretty quickly on requeue and thanks to jitter etc this does not materially affect cluster deployments. However, at scale with more ExtensionConfigs this race will be hit more often and could lead to worse outcomes.

I'll update the new PR with this detail as well as the original description from this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/clusterclass Issues or PRs related to clusterclass cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants