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

[MSAL] Settings Sync logs out after a few hours #229456

Closed
winstliu opened this issue Sep 23, 2024 · 26 comments · Fixed by #234716, #236011 or #236623
Closed

[MSAL] Settings Sync logs out after a few hours #229456

winstliu opened this issue Sep 23, 2024 · 26 comments · Fixed by #234716, #236011 or #236623
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders microsoft-authentication Issues with the Microsoft Authentication extension settings-sync verified Verification succeeded
Milestone

Comments

@winstliu
Copy link
Member

winstliu commented Sep 23, 2024

Does this issue occur when all extensions are disabled?: Didn't try without extensions because this is a multi-hour repro and I need to stay productive, sorry!

Version: 1.94.0-insider (user setup)
Commit: 1926933
Date: 2024-09-23T05:12:01.964Z
Electron: 30.5.0
ElectronBuildId: 10198947
Chromium: 124.0.6367.243
Node.js: 20.16.0
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.22631

Steps to Reproduce:

  1. Enable MSAL
  2. Log into Settings Sync with a Microsoft account
  3. Wait a few hours and notice you're logged out

https://gist.github.com/winstliu/b858f9e8f600301676a04cdd3f16f3cb

@TylerLeonhardt
Copy link
Member

Can you include the Window & Microsoft authentication logs as well?

I'm gonna loop in @sandy081 to help out understanding the Settings Sync stuff

@TylerLeonhardt TylerLeonhardt added bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster microsoft-authentication Issues with the Microsoft Authentication extension labels Sep 24, 2024
@TylerLeonhardt TylerLeonhardt added this to the October 2024 milestone Sep 24, 2024
@winstliu
Copy link
Member Author

winstliu commented Sep 25, 2024

@winstliu
Copy link
Member Author

winstliu commented Oct 8, 2024

@sandy081 any progress here? I'm still continuously getting logged out.

@TylerLeonhardt
Copy link
Member

Sandeep and I will sit down soon to discuss these MSAL related bugs. My suspicion is that Settings Sync is keeping track of the id of a session, rather than the account being used with Settings Sync. The session id is suppose to be different every time a token is refreshed but the account should stay the same.

@alex180500
Copy link

Please fix this

@vs-code-engineering vs-code-engineering bot removed the info-needed Issue requires more information from poster label Oct 31, 2024
@sandy081
Copy link
Member

@TylerLeonhardt Given the latest improvements in auth and settings sync areas, Should we ask user to try insiders and see if the issue can be still reproducible? Or do you think these changes are not related to this issue?

@TylerLeonhardt
Copy link
Member

@sandy081 I don't think those changes were related to this issue and this should be investigated

@winstliu
Copy link
Member Author

Indeed, this is still happening on 0c9dd26

@sandy081
Copy link
Member

sandy081 commented Nov 26, 2024

@TylerLeonhardt I believe following logging explains why settings sync is logging out

2024-09-25 11:52:47.722 [info] Settings Sync: Updating due to token failure
2024-09-25 11:52:47.729 [trace] Settings Sync: Updating the token for the account winstonliu@microsoft.com
2024-09-25 11:52:47.729 [trace] Settings Sync: Token updated for the account winstonliu@microsoft.com
2024-09-25 11:52:47.742 [info] Settings Sync: Reset current session
2024-09-25 11:52:47.742 [info] Settings Sync: Updating due to auth failure
2024-09-25 11:52:47.745 [trace] Settings Sync: Account status changed from available to unavailable

My suspicion is that when the token fails for the first time, workbench tries to refresh the token (requesting auth service for sessions) and I believe the token that is given back is not refreshed and probably the same token. Therefore, when workbench tries to sync again it fails again and Settings Sync logs out to prevent recursive invalid auth requests.

@winstliu Can you please share the window log again when this happens again? This might help in prove the theory.

@sandy081
Copy link
Member

@winstliu Also share the settings sync log. Over all following logs needed

  • F1 > Open View... > Window
  • F1 > Open View... > Settings Sync
  • F1 > Open View... > Microsoft

@TylerLeonhardt
Copy link
Member

I think I found the issue... @sandy081 your analysis really helped! PR sent.

@vs-code-engineering vs-code-engineering bot added the unreleased Patch has not yet been released in VS Code Insiders label Nov 27, 2024
@vs-code-engineering vs-code-engineering bot added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Nov 28, 2024
@dbaeumer dbaeumer added this to the January 2025 milestone Dec 6, 2024
TylerLeonhardt added a commit that referenced this issue Dec 13, 2024
and force expiration in a similar way to the way MSAL does it for access tokens.

Fixes #229456
@TylerLeonhardt
Copy link
Member

Omg... I think I figured this one out for real this time. In some places we use jsonwebtoken.verify passing in the idToken to verify audience. This also verifies expiration.

Talking with MSAL folks, apparently publicClient.acquireTokenSilent(...) will only auto-refresh access tokens if they're near expiration. Not id tokens. So this API does return expired idTokens thinking no one will verify them. This wasn't clear at all from the SDK or docs.

The solution is to manually check the expiration of the idtoken and refresh it if it's close.

@vs-code-engineering vs-code-engineering bot added the unreleased Patch has not yet been released in VS Code Insiders label Dec 13, 2024
@vs-code-engineering vs-code-engineering bot added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Dec 13, 2024
@winstliu
Copy link
Member Author

Image

Appreciate your persistence here, but it looks like it's still something else :(
Version: 1.97.0-insider (user setup)
Commit: 21a129e
Date: 2024-12-13T12:38:52.505Z
Electron: 32.2.6
ElectronBuildId: 10629634
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Windows_NT x64 10.0.26100

As usual, let me know which logs would be helpful.

@vs-code-engineering vs-code-engineering bot removed the insiders-released Patch has been released in VS Code Insiders label Dec 13, 2024
@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Dec 13, 2024

logs would be helpful. Trace level.

  • F1 > Open View... > Window
  • F1 > Open View... > Settings Sync
  • F1 > Open View... > Microsoft Auth

@winstliu
Copy link
Member Author

Window: https://gist.github.com/winstliu/ecc822a8bb9f55067b5797abea252430 (I believe this might be truncated, I'm pretty sure I enabled Settings Sync at 12:30)
Settings Sync: https://gist.github.com/winstliu/193cb9a8caae483db34ec105b5130f2b
Microsoft Auth: https://gist.github.com/winstliu/09684962a4a2b0641153a89d1872935e (this one's even more truncated, with only results from the past ~6 minutes)

@TylerLeonhardt
Copy link
Member

I am able to repro only on the broker side... I wonder if my fix doesn't work in the broker scenario. That would be really sad...

@TylerLeonhardt
Copy link
Member

Confirmed... the broker flow does not support forceRefresh... I need to once again be creative.

TylerLeonhardt added a commit that referenced this issue Dec 19, 2024
Looks like the Broker doesn't support `forceRefresh`... This is an alternative way of forcing a refresh.

Fixes #229456
@vs-code-engineering vs-code-engineering bot added the unreleased Patch has not yet been released in VS Code Insiders label Dec 19, 2024
@TylerLeonhardt
Copy link
Member

Alright @winstliu ... my fingers are crossed. Tomorrow will tell... let me know how it goes, and please do attach logs again if you see the issue (I added another log statement).

@vs-code-engineering vs-code-engineering bot added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Dec 20, 2024
@winstliu
Copy link
Member Author

Yes, this seems to be fixed!!! Thanks 😁

@TylerLeonhardt
Copy link
Member

FINALLY 😭

@TylerLeonhardt TylerLeonhardt added the verified Verification succeeded label Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders microsoft-authentication Issues with the Microsoft Authentication extension settings-sync verified Verification succeeded
Projects
None yet
6 participants