Skip to content

Improve the refreshing of tokens from inside the cluster #1949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

AlexisZam
Copy link

@AlexisZam AlexisZam commented Nov 10, 2022

What type of PR is this?

kind/design

What this PR does / why we need it:

Requests from inside the cluster misuse the API to refresh tokens.

Which issue(s) this PR fixes:

Fixes #1948

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

Requests from inside the cluster misuse the API to refresh tokens.

Signed-off-by: Alexis Zamanis <[email protected]>
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Nov 10, 2022
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Nov 10, 2022
@roycaihw
Copy link
Member

roycaihw commented Dec 5, 2022

/assign @yliaog

@yliaog
Copy link
Contributor

yliaog commented Jan 16, 2023

thanks for the pr. is there a test to show the pr fixes the problem stated in the issue: #1948

@AlexisZam
Copy link
Author

AlexisZam commented Jan 17, 2023

@yliaog This PR fixes a design problem, rather than a bug. As explained in #1948, the code works, but the API is misused. The proposed solution properly uses the API, and brings the in-cluster code in line with the out-of-cluster code.

Compare the in-cluster code:

def _refresh_api_key(client_configuration):
if self.token_expires_at <= datetime.datetime.now():
self._read_token_file()
self._set_config(client_configuration)
client_configuration.refresh_api_key_hook = _refresh_api_key

and the out-of-cluster code:

def _refresh_api_key(client_configuration):
if ('expiry' in self.__dict__ and _is_expired(self.expiry)):
self._load_authentication()
self._set_config(client_configuration)
client_configuration.refresh_api_key_hook = _refresh_api_key

@yliaog
Copy link
Contributor

yliaog commented Jan 17, 2023

thanks.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 17, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlexisZam, yliaog

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 Jan 17, 2023
@k8s-ci-robot k8s-ci-robot merged commit 2a27133 into kubernetes-client:master Jan 17, 2023
@AlexisZam AlexisZam deleted the feature-in-cluster-token-refresh branch January 17, 2023 18:46
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. 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. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. 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.

Requests from inside the cluster misuse the API to refresh tokens
4 participants