Repository navigation
Conversation
_load_oid_token read the JWT exp claim to decide whether to refresh at load time but never set self.expiry, so the refresh callback installed by _set_config never reloaded OIDC credentials and later requests failed with 401 once the token expired. Record the expiry of the id-token in use, read from the final token since a refresh replaces it, so OIDC refreshes like GCP and exec-plugin credentials. Signed-off-by: xh123637 <3324733895@qq.com>
|
|
Welcome @xh123637! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: xh123637 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 |
What type of PR is this?
/kind bug
What this PR does / why we need it:
KubeConfigLoader._load_oid_tokenread the JWTexpclaim to decide whether to refresh the token at load time, but never recorded it on the loader. The refresh callback installed by_set_configonly reloads authentication whenself.expiryexists and is expired, so OIDC tokens were never refreshed after client initialization and later requests failed with401 Unauthorizedonce the token expired.This PR records the expiry of the id-token in use (via a new
_get_jwt_expiryhelper) so the existing refresh hook refreshes OIDC tokens like it already does for GCP and exec-plugin credentials. The expiry is read from the final id-token because a refresh replaces it, and the existing five-minute skew in_is_expiredstill applies, so tokens are refreshed shortly before expiry rather than on every request. Tokens without anexpclaim, and non-JWT refresh results, leaveexpiryunset exactly as before.The asyncio client is intentionally untouched: it has no
refresh_api_key_hook/expiryrefresh mechanism, so this issue is specific to the sync client.Which issue(s) this PR fixes:
Fixes #2780
Special notes for your reviewer:
New tests in
kubernetes/config/kube_config_test.py:test_oidc_sets_expiry_from_id_token: loading a config with an unexpired OIDC token records its expiry.test_oidc_refresh_api_key_hook: end-to-end throughload_and_set— the installed hook refreshes the token (mocked IdP) once the recorded expiry passes and records the new token's expiry.Both tests fail on unmodified code (
AttributeError: 'KubeConfigLoader' object has no attribute 'expiry') and pass with the fix. Fullkubernetes/config/kube_config_test.py: 79 passed.