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

[server] Sync token refresh #19470

Merged
merged 2 commits into from
Feb 27, 2024
Merged

[server] Sync token refresh #19470

merged 2 commits into from
Feb 27, 2024

Conversation

geropl
Copy link
Member

@geropl geropl commented Feb 26, 2024

Description

Attempt two to fix token refresh (attempt one is here) using a redis mutex.

Code is guarded with the sync_refresh_token_exchange feature flag.

Related Issue(s)

Fixes EXP-1413

How to test

  • start a workspace on a repo on gitlab.com ✔️
  • extended test:
    • invalidate your GitLab token (by changing the expiryDate in the DB)
    • start another workspace on GitLab
    • see how the token got refreshed ✔️

Documentation

Preview status

gitpod:summary

Build Options

Build
  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer
  • analytics=segment
  • with-dedicated-emulation
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated
Preview Environment / Integration Tests
  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • /werft preemptible
    Saves cost. Untick this only if you're really sure you need a non-preemtible machine.
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh. If enabled, with-preview and with-large-vm will be enabled.
  • with-monitoring

/hold

Copy link
Contributor

@mustard-mh mustard-mh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM, but I don't understand why we add endpoint (Caddyfile) for public.v1 APIs. Not block but would be good to understand

@mustard-mh
Copy link
Contributor

Sorry, commented on wrong PR...

components/server/src/user/token-service.ts Show resolved Hide resolved
}

const aboutToExpireTime = new Date();
aboutToExpireTime.setTime(aboutToExpireTime.getTime() + 5 * 60 * 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] will a provider's token always expired in 5 minutes, then never make it works? 🤣

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the intend here is to treat all tokens as invalid that will expire in the next 5 minutes.


// EXPERIMENT(sync_refresh_token_exchange)
const syncRefreshTokenExchange = await getExperimentsClientForBackend().getValueAsync(
"sync_refresh_token_exchange",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retry_refresh_token_exchange and sync_refresh_token_exchange are different

  • sync_refresh_token_exchange will store them in database
  • retry_refresh_token_exchange will revoke (internally) token after it's used

Is it intent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention behind both paths is the same. Deep down they both call:

await authProvider.refreshToken(user); // updating/inserting a fresh token into the DB as side effect
return await this.userDB.findTokenForIdentity(identity);   // return said token

It's just that the existing path has this poor-man's sync approach (from before we had redis), which I did not want for the pure redis solution.
What I basically did for sync_refresh_token_exchange is to wrap it into a redis mutex, nothing more. The rest is noise/slight code re-arrangements.

const syncRefreshTokenExchange = await getExperimentsClientForBackend().getValueAsync(
"sync_refresh_token_exchange",
false,
{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add host as a property of Feature Flag? Just in case they have multiple SCM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are interested to role this out for all, so I think we should test it as such. The difference between SCMs should be properly abstracted behind the Token abstraction.

@mustard-mh
Copy link
Contributor

Approved to unblock

@geropl
Copy link
Member Author

geropl commented Feb 27, 2024

/unhold

@roboquat roboquat merged commit af0213b into main Feb 27, 2024
27 checks passed
@roboquat roboquat deleted the gpl/1413-sync branch February 27, 2024 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants