Fix OIDC token refresh failing on Windows when idp-certificate-authority-data is set#2644
Conversation
_refresh_oidc wrote the IdP CA certificate by reopening a NamedTemporaryFile by name, which raises PermissionError on Windows while the original handle is still open. Reuse the module's existing _create_temp_file_with_content helper, which is mkstemp-based (Windows-safe) and cleans up via atexit instead of relying on GC timing.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ealeonraz The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
|
|
Welcome @ealeonraz! |
|
/kind bug |
What this does
KubeConfigLoader._refresh_oidcwrote the IdP CA certificate by creating atempfile.NamedTemporaryFile(delete=True)and then re-opening it by name. On Windows that second open raisesPermissionError(the file is held exclusively while open), so OIDC token refresh fails at runtime for any kubeconfig usingidp-certificate-authority-data. This is the temp-file portion of #2427.The fix reuses the module's existing
_create_temp_file_with_contenthelper (mkstemp-based, closed before reuse, cleaned up via the existing atexit handler) — the same mechanism this file already uses for other inline certificate data, so behavior is now consistent across platforms and cleanup no longer depends on GC timing.Testing
pytest kubernetes/base/config/kube_config_test.pyon Windows 11: 75 passed — includingtest_oidc_with_refresh, which fails withPermissionErrorbefore this change. No test modifications were needed; the existing tests cover the path once the production code is fixed.Ref #2427 — planned as the first of a short series of small Windows fixes discussed there.