-
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
Implement OIDC Auth Provider #396
Conversation
Adds ability for Kubeclient to utilize the oidc auth-provider both by re-using the id-token that is inside the kubeconfig if it is not expired and refreshing it if the token has passed expiry.
Sorry for delay, reviewing... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent 💯, very minor comments
README.md
Outdated
If the id-token specified in your `$KUBECONFIG` file has not expired the OIDC Auth Provider will simply use that token. | ||
If it has expired then the provider will refresh the token and use that. | ||
|
||
Currently tokens are only valid for one hour and the provider will not automatically refresh them. Fresh id-tokens are also |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it always 1 hour? Isn't expiration up to the oidc server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated for clarity.
README.md
Outdated
#### OIDC Auth Provider | ||
|
||
If the cluster you are using has OIDC authentication enabed you can use the `openid_connect` gem to refresh | ||
id-tokens when they have expired. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See next comment about the wording "refresh".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated for clarity.
|
||
def expired?(id_token) | ||
# If token expired or expiring within 60 seconds | ||
Time.now.to_i + 60 > id_token.exp.to_i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this timezone independent? 👍 looks good, Time.now knows its timezone and Time.now.to_i is same either way:
~ $ env TZ= ruby -e 'p Time.now'
2019-02-27 10:47:22 +0000
~ $ ruby -e 'p Time.now'
2019-02-27 12:47:26 +0200
~ $ env TZ= ruby -e 'p Time.now.to_i'
1551264454
~ $ env ruby -e 'p Time.now.to_i'
1551264463
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The openid_connect gem performs the same check except for the 60 second grace so I believe it will be fine.
lib/kubeclient/oidc_auth_provider.rb
Outdated
end | ||
|
||
class << self | ||
def token(auth_provider) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional nit, your call] The name auth_provider
sounds like this would contain the ['auth-provider'] part of the config, but it contains the ['auth-provider']['config'] sub-part. Maybe config
? auth_provider_config
(ouch)? provider_config
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've gone with provider_config
.
lib/kubeclient/oidc_auth_provider.rb
Outdated
issuer_url = auth_provider['idp-issuer-url'] | ||
discovery = OpenIDConnect::Discovery::Provider::Config.discover! issuer_url | ||
|
||
id_token = OpenIDConnect::ResponseObject::IdToken.decode auth_provider['id-token'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the config doesn't contain id-token
at all? (Is that possible?)
As we can always obtain a new one, let's allow this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how you'd get into that state but kubectl
supports it so I've implemented it too.
README.md
Outdated
like [`dexter`](https://github.com/gini/dexter) in order to configure the auth-provider in your `$KUBECONFIG` file. | ||
|
||
If the id-token specified in your `$KUBECONFIG` file has not expired the OIDC Auth Provider will simply use that token. | ||
If it has expired then the provider will refresh the token and use that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wordings "will refresh" ... "will not automatically refresh" sounds confusing on a quick read.
I propose here saying:
If you use
Config.context(...).auth_options
and the kubeconfig file hasuser: {auth-provider: {name: gcp}}
, kubeclient will automatically obtain a token (or useid-token
if still valid)
to me "obtain" is one-time action, doesn't imply ability to keep refreshing it, nor sounds as action done to the token so less expectation it'll write it back to the config file (the disclaimer below is still good).
The other change is because this section talks abstractly about "the OIDC Auth Provider" but I wanted to say specifically how to invoke this (Client
doesn't do this, Config
does)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(one day if we implement #393, we can reword these sections in terms of "refresh" or "renewal")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated README for more clarity, let me know what you think.
22c43ef
to
f0a750c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect!
BTW, a security question: On one hand, making a network request is not risky to your machine(?). |
added changelog for ManageIQ#396
released in gem 4.3.0. |
Adds ability for Kubeclient to utilize the oidc auth-provider both by
re-using the id-token that is inside the kubeconfig if it is not expired
and refreshing it if the token has passed expiry.