-
Notifications
You must be signed in to change notification settings - Fork 167
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
Refreshed OIDC tokens should be persisted to configuration file #409
Comments
Interesting! Is that always true in OIDC? |
I don't think every authorization server implementation includes it, but the one we're using does. My testing: require 'openid_connect'
issuer_url = '<snip/>'
client_id = 'APP-HQ'
client_secret = '<snip/>'
refresh_token = '<snip/>'
discovery = OpenIDConnect::Discovery::Provider::Config.discover!(issuer_url)
client = OpenIDConnect::Client.new(
identifier: client_id,
secret: client_secret,
authorization_endpoint: discovery.authorization_endpoint,
token_endpoint: discovery.token_endpoint,
userinfo_endpoint: discovery.userinfo_endpoint
)
client.refresh_token = refresh_token
2.times do |attempt|
puts "Getting new token (attempt #{attempt})..."
access_token = client.access_token!
puts "ID Token: #{access_token.id_token}"
puts "Refresh token: #{access_token.refresh_token}"
end
On this second attempt, Dex logged the following:
|
Ack. It does add an important constraint to #393 -- to support renewal without re-creating Client objects, renewal state better be centralized, allowing single renewal object to serve multiple Client objects. (I kinda knew that already, but extra motivation / constraint is helpful.) |
This is of interest to me as well. Looking to create some |
OIDC auth support was added in #396. It includes support for expired ID tokens (expanded in #407 to handle certificate rotation on the authentication server) and refreshes them when fetching a context from configuration.
The README states:
This in itself would be ok if it were the whole story, since it would imply simply repeated token refreshes on each use.
What's not taken into account here is that refresh tokens are single-use. If kubeclient refreshes an ID token, it "spends" the corresponding refresh token such that it can never be used again, but it doesn't record the new refresh token anywhere. This means that any other tool which uses the configuration file, or indeed a follow-up use of the config file by kubeclient (even in the same process, even using the very same instance of
Kubeclient::Config
), will encounter both an expired ID token and an invalid refresh token, and will raise an exception like this one:In order to behave correctly, similarly to kubectl, kubeclient must update the configuration file it consumes with the new tokens when a refresh happens.
Is there any reason not to implement this? Does anyone have any thoughts on how it might be implemented? I made something of a start at #408, but I'm not really happy with the direction it's going right now. I wonder if it should be the responsibility of
Kubeclient::OIDCAuthProvider
to update theKubeclient::Config
instance's values?The text was updated successfully, but these errors were encountered: