Skip to content
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

Refresh expired OIDC tokens #125

Open
jacobtomlinson opened this issue Jul 25, 2023 · 4 comments
Open

Refresh expired OIDC tokens #125

jacobtomlinson opened this issue Jul 25, 2023 · 4 comments
Labels
auth Authenticating with Kubernetes bug Something isn't working kr8s

Comments

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Jul 25, 2023

In #126 I added support for authenticating with an OIDC token. However, I did not implement automatically refreshing that token.

This issue tracks adding token refreshing.

@jacobtomlinson jacobtomlinson added the enhancement New feature or request label Jul 25, 2023
@jacobtomlinson
Copy link
Member Author

Here's an Apache 2.0 Licensed implementation frompykube-ng that might be useful for reference when implementing the JWT token refreshing.

https://codeberg.org/hjacobs/pykube-ng/src/commit/c1ac2c97587249e418d04d91f1297d4ffe3631c3/pykube/http.py#L282

@droctothorpe
Copy link
Contributor

Our organization prohibits refresh tokens with OIDC to optimize security. We would greatly appreciate it if kr8s didn't assume the presence of a refresh-token field in the Kubernetes configuration file, and returned a 401 when the token was expired.

@jacobtomlinson
Copy link
Member Author

Ok I've opened #126 which just uses the OIDC token directly with no refreshing. This was pretty quick to implement.

We probably do want to support refreshing too if other libraries do that, but as @droctothorpe we only want to do that if a refresh-token field is present.

Looking at pykube-ngs implementation they seem to do the following:

  • Decode the token and check the validity of the format against the OIDC token spec.
  • Check the expiry isn't very soon.
  • If invalid or expired make a request to refresh the token.
  • Write the token back to .kube/config.

I would be interested to dig into other libraries and see if they do any of this validation/refreshing/writing as it feels a little out of scope. But equally if everyone is doing it we probably should too.

@jacobtomlinson
Copy link
Member Author

Looking at the Kubernetes go-client they check the expiry of the token and if it is expired (or will in the next 10 seconds) they refresh it. I haven't yet found where that gets written back to the config, but I assume it must happen in kubectl somewhere.

https://github.com/kubernetes/client-go/blob/c5b1c13ccbedeb03c00ba162ef27566b0dfb512d/plugin/pkg/client/auth/oidc/oidc.go#L221-L288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Authenticating with Kubernetes bug Something isn't working kr8s
Projects
None yet
Development

No branches or pull requests

2 participants