-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor refresh tokens #305
Conversation
We are using `require-env-variable` to ensure certain environment variables are properly set on service start. This adds in a few more required variables. Even though they are not directly passed into our service classes, they are used by third party libraries and so we want to ensure their existence.
We had organically coupled token management with the initial authentication flow, but they don't actually belong together. This separates token management (e.g. utilization of refresh tokens) from the SSH authentication system. It also refactors the sftp session handler to use the token manager rather than the authentication session. While doing these refactors we took out a redundant environment variable. Issue #289 Duplicated FusionAuth env vars
Auth tokens are now retrieved just-in-time by the permanent file system (rather than being passed during the creation of the permanent file system). This is a critical fix because (1) it prevents certain paths that would lead to stale tokens but also (2) it means that creating a permanent file system becomes a synchronous operation. This also resolves a bug where the failure to generate a token could result in a hanging sftp connection. Issue #288 Permanent file system errors can result in hung connections
When refactoring authentication to use refresh tokens we missed the 2FA flow. It's not clear that we should be supporting 2FA to begin with since rclone doesn't support it, and ultimately the real solution is to use keys instead of passwords for sftp authentication. That being said, while it's here we should make sure it isn't broken! Issue #298 2FA auth flow does not utilize refresh tokens
d497ef1
to
cd0d162
Compare
this.sftpConnection.status(reqId, SFTP_STATUS_CODE.NO_SUCH_FILE); | ||
break; | ||
default: { | ||
this.openExistingFileHandler( |
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.
Question, is there a bottleneck to not awaiting this for example and making the handler method async?
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.
We can't make the handler methods async because we don't control their signature -- the ssh2 library (which ultimately gets these handlers passed to them) expects handlers to be synchronous, which means they don't handle failed promises.
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.
Nothing looks out of place me, test works! Great work @slifty
This PR moves refresh token logic into a dedicated class that is ONLY responsible for generating a non-stale token.
It also changes when in the SFTP flow those tokens are actually generated, resulting in a more simple SFTP flow (and also ensuring that all SFTP processes are working with fresh tokens).
One side effect of this PR is we are no longer using the
FUSION_AUTH_SFTP_APP_ID
environment variable, and are instead only usingFUSION_AUTH_SFTP_CLIENT_ID
. These were two names for the same value, and I felt thatCLIENT_ID
was a the more consistent / clear name so decided on that one.Resolves #298
Resolves #289
Resolves #288