-
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
fix (kubernetes-client-api) :Add new autoOAuthToken field in Config to differentiate between user and autoconfigured tokens (#4802) #4951
Conversation
7e7fb1c
to
073f641
Compare
@@ -94,6 +94,9 @@ public void before(BasicBuilder builder, HttpRequest httpRequest, RequestTags ta | |||
|
|||
@Override | |||
public CompletableFuture<Boolean> afterFailure(Builder builder, HttpResponse<?> response, RequestTags tags) { | |||
if (config.isTokenNonRefreshable()) { | |||
return CompletableFuture.completedFuture(true); |
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.
Returning true here and in the other interceptor means to try the request again, but since no modifications have been made on the builder, it would just re-issue the existing request.
Including the token provider in isTokenNonRefreshable could be confusing as it may refresh. That is:
if token source == user, then do nothing
if token source == provider, then attempt to get the token again and try once more.
014e0da
to
e80e14a
Compare
e453068
to
a2c43b8
Compare
7b636cd
to
3732033
Compare
3732033
to
a72435d
Compare
a72435d
to
d5ba32d
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.
This looks good. It's the easiest way to do this with the existing code structure.
- the user OauthTokenProvider will take precedence.
- the user oauthToken will be used next
- if neither of those were used, then every minute there will be a soft refresh or an open id refresh is the token is near expiration. The code was already doing this, but didn't check for expiration, so we probably can resolve the main thrust of Support for the expiration of the token #2112. The other issues mentioned on there likely remain.
- on unauthorized failure there will be a last chance refresh
Improvements that can be done later:
- Don't update the Config - move the autoOathToken and related refresh logic off of the Config and onto to the refresh interceptors. But this requires a lot of changing of how we "refresh" the Config.
- don't re-attempt the request if the token hasn't actually changed from the initial request
- coordinate the refresh Coordinate token refresh #4704 - and perform the time based soft refresh in a non IO thread.
...tes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/TokenRefreshInterceptor.java
Show resolved
Hide resolved
d5ba32d
to
bab3619
Compare
kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java
Outdated
Show resolved
Hide resolved
...tes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/TokenRefreshInterceptor.java
Outdated
Show resolved
Hide resolved
1091825
to
14fd505
Compare
@rohanKanojia @manusa opened a pr against this pr that updates to latest (as of yesterday), and takes the changes a little further rohanKanojia@d4fba9d - which further clarifies the behavior and tries to localize it better into the TokenRefreshInterceptor. The only thing that may be odd is that I removed some checks for empty string because they were not being applied consistently - they can of course be added back. |
14fd505
to
e0490a9
Compare
LGTM, should be ready after resolving conflicts. |
e36f439
to
be3e915
Compare
…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>
if (autoToken) { | ||
assertEquals("token", config.getAutoOAuthToken()); | ||
} else { | ||
assertEquals("token", config.getOauthToken()); | ||
} |
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.
This will need refactoring assertConfig
was already shady as it was.
Adding a boolean parameter and a conditional assert based on that boolean, makes it even more unclear.
Kudos, SonarCloud Quality Gate passed! |
Description
Fix #4802
used by Config internally to store token obtained during
autoconfiguration process.
would only be called by user (during
new ConfigBuilder().withOAuthToken("...")
call)whenever custom token is required.
actual value of
oauthToken
and finallyautoOAuthToken
value. Allinterceptors would keep using getOAuthToken to get resolved OAuth
token value
Updated TokenRefreshInterceptor / OpenShiftOAuthInterceptor to match these expectations:
Orignally posted by @shawkins:
oauthToken
is set), don't do any refresh logic at all.Type of change
test, version modification, documentation, etc.)
Checklist