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

Allow dropping tokens from the session manager for easier recovery on lookup failures #684

Closed
macstewart opened this issue Jan 6, 2022 · 5 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@macstewart
Copy link

macstewart commented Jan 6, 2022

For context, I'm using TokenAuthentication with LifecycleAwareSessionManager. The token used is a periodic token provided to the service at install-time.

To provide resilience against network blips during the LifecycleAwareSessionManager's renewal loop, I've set it to drop the token on error, and configured an event listener to respond to failure events by calling LifecycleAwareSessionManager::getSessionToken after a delay to restart the renewals.

This works well when failures happen during the renewal call. However, if there's a failure in LifecycleAwareSessionManager::doGetSessionToken in the try block that surrounds this line:

token = LoginTokenAdapter.augmentWithSelfLookup(this.restOperations, (VaultToken)token);

the token wrapper token is never upgraded to a LoginToken, which means the token is not considered renewable and the renewal loop will not start. In addition, this failure does not allow the token to be dropped, meaning that any further attempts to trigger a new login will just use the token stored in the wrapper. This token will still work in the short term but because the renewal loop is broken it will eventually quietly expire and break the application.

@macstewart
Copy link
Author

A near-solution was to wrap the TokenAuthentication in a LoginTokenAdaptor, which makes the augmentWithSelfLookup part of the login step, meaning any self lookup failures happen before the token is cached in LifecycleAwareSessionManager. However, this creates the side effect that the provided token is considered revokable and is therefore invalidated when the application stops. This is a deal-breaker for a service which may need to be restarted without providing a new token each time.

The only real workaround I found for the issue was to add a call to LifecycleAwareSessionManager::destroy in my login step that is triggered by the failure event listener. This is really misusing the DisposableBean method implementation though and there's nothing to say that LifecycleAwareSessionManager's implementation of this method won't affect more than just the cached token in future versions.

@mp911de mp911de added the status: waiting-for-triage An issue we've not yet triaged label Mar 17, 2023
@mp911de mp911de self-assigned this Mar 17, 2023
@mp911de
Copy link
Member

mp911de commented Mar 17, 2023

What would be a proper workaround? Rethrowing the exception would leave a potentially created token active, and we would need to revoke the token as outlined in your approach.

An alternative could be us providing a public revoke() method to drop and revoke the token, which would move the existing code from the destroy method into a proper one.

Let me know what you think.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Mar 17, 2023
@nbx-rosi
Copy link

nbx-rosi commented Mar 20, 2023

If I may join this discussion:
Having a public revoke() method (or dropCurrentToken() as its called in the ReactiveLifecycleAwareSessionManager ) would be highly appreciated! That is actually what we are missing in our setting as well, where we are using Kubernetes Authentication which fails from time to time due to network issues and/or rotating master. Currently we setup a dirty workaround with reflection to call this, followed by a manual renewToken() call to trigger a new login.

To make things worse, we observed, that having "an event listener to respond to failure events*" is not enough in case of the SecretLeaseContainers which are used to load spring configuration, because they have their own listeners and all they do by default is logging... So we ended up configuring custom LeaseErrorListeners here as well.

The only reason stopping us from setting up our own issue here is, that we can't clearly point to one problem, but seem to face a combination of a few.

(*) assuming you are talking about AuthenticationErrorEvent

@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Mar 20, 2023
@mp911de mp911de added this to the 3.0.2 milestone Mar 20, 2023
@mp911de mp911de changed the title LifecycleAwareSessionManager - Failing doGetSessionToken's augmentWithSelfLookup step prevents token dropping/automatic renewal Allow dropping tokens from the session manager for easier recovery on lookup failures Mar 20, 2023
mp911de added a commit that referenced this issue Mar 20, 2023
@macstewart
Copy link
Author

On my end, the public revoke() is an acceptable resolution here. Thanks for looking into it!

@mp911de
Copy link
Member

mp911de commented Mar 20, 2023

Thanks a lot for having a look. If you should run into other issues, let us know and we can work on these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants