-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
config.refresh() erases token specified when building initial config #4802
Comments
Yes this is some problematic behavior of the refresh logic that was noticed in #4702 as well. As you note this will happen only if you specify the token and have another token that can be picked up by the refresh logic - we're not currently tracking if the token and other fields were set from the auto configure or after the fact by the user. As a workaround I think you can prevent this from happening if you call config.setAutoConfigure(false) on the config you pass to the builder. This does not affect the openshift logic with #4702 as it will only try to refresh on a authentication failure, however the base token refresh interceptor will attempt to proactively refresh - which is causing this issue. There is currently no way to adjust that 1 minute interval. |
I found |
To recap - we will currently bypass refresh if autoconfigure is false and there is no associated kubeconfig file. If there isn't a kubeconfig file that is found which provides a competing token, you can either start with an empty / non-auto configured builder, or use withAutoConfigure new ConfigBuilder().withMasterUrl("https://url-to-my-kubernetes-master").withCaCertData("my-ca-cert-data").withOauthToken("my-token").withAutoConfigure(false).build() @manusa @rohanKanojia @Vlatombe The broader question is over expected behavior - if you call withOauthToken, or withOauthTokenProvider, should we track that so that the config is not proactively refreshed? If the token does expire, then should we try the more typical refresh mechanisms? |
I would expect that a Configuration built using |
Another thing that will work is using:
Even if the logic then finds another oauth token, it won't actually be used. I don't know if it's documented anywhere, but the token provider trumps setting the oauth token.
Both the token refresh interceptor and the openshift logic seemed to assume that regardless of how that token was set that it would still be refreshed. I'm honestly not sure if that is a mistake or if anyone is relying on that behavior. We can do one or both of theses:
We should also:
|
The Config logic is very confusing at this point wrt oauth tokens. We have ~5 token sources:
As mentioned in this issue, directly setting the oauthtoken on the config does not inhibit the refresh logic for 2-5. 3 and 5 also can provide the authproviderconfig to refresh the token from server - with the additional consideration that openshift token refresh is different (based just on username and password). I'm not confident that anyone using anything other than a default autoconfigured config would know / understand the interplay of options. |
We may want to expand this issue to a few additional scenarios. Looking at kubectl explicit behavior, there are other differences with our handling:
Other ill-defined behavior:
|
@shawkins : Do you think it makes sense to give user the option to control whether token should be refreshed or not? Interested users would just use |
@rohanKanojia I'm not sure what the right approach is given how overloaded the Config is wrt authentication handling. It may not be clear to users when they should opt out of refresh. Ideally we'd stop internally modifying the oauthtoken field (that would match the user expectation here) - if the user has set a value, it should remain that. That means how we are looking up the token in a refreshable way from the ENV, service account file, AuthInfo, AuthProvider, or ExecCredential should be done elsewhere - in particular as part of the refresh logic and not as part of the Config load. It's also not quite clear what the relationship is of this refresh to the client/server refreshes performed by the TokenRefreshInterceptor and the OpenShiftOAuthInterceptor. Based upon https://github.com/kubernetes/client-go/blob/master/plugin/pkg/client/auth/oidc/oidc.go and and a similar bit of code that was in fabric8 (but invalid for openshift) it appears that OIDC refresh is only used as a last resort if nothing else has set a token and it considers the expiration - not a proactive 1 minute refresh. There's also the OAuthTokenProvider to consider as it trumps all of this - at the very least it probably doesn't belong on the Config now that we have the KuberentesClientBuilder. It also seems like we should be able to encapsulate some of our refresh logic via this, but that looks like a very forced fit currently. |
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…s set (fabric8io#4802) + Add enum OAuthTokenSource in Config which tell us about the source from which Config's OAuthToken was set. + Skip refresh in case current OAuthTokenSource is set to USER (the scenario reported in the linked issue) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field authOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field authOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field authOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field authOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field authOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field authOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field autoOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field autoOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field autoOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field autoOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field autoOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field autoOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (fabric8io#4802) + Add a new string field autoOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…to differentiate between user and autoconfigured tokens (#4802) + Add a new string field autoOAuthToken in Config, this field would be used by Config internally to store token obtained during autoconfiguration process. + Remove setOAuthToken references from token interceptors and Config, it would only be called by user (during `new ConfigBuilder().withOAuthToken("...")` call) whenever custom token is required. + getOAuthToken would give most priority to token from provider, then actual value of `oauthToken` and finally `autoOAuthToken` value. All interceptors would keep using getOAuthToken to get resolved OAuth token value Signed-off-by: Rohan Kumar <rohaan@redhat.com>
Describe the bug
Relates to #4519
This is essentially the same problem but using a fixed token instead of a kubeconfig file when building the initial configuration.
Fabric8 Kubernetes Client version
6.3.1
Steps to reproduce
Instantiate the client using
and also have a file at
/var/run/secrets/kubernetes.io/serviceaccount/token
with some different token.After 1 minute, calls start failing with
Unauthorized
errors.Expected behavior
Calls don't fail after 1 minute
Runtime
Kubernetes (vanilla)
Kubernetes API Server version
1.23
Environment
Amazon
Fabric8 Kubernetes Client Logs
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: