Page MenuHomePhabricator

[keyserver] Login or register before tables are created
ClosedPublic

Authored by inka on Apr 3 2024, 7:18 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 3, 1:41 AM
Unknown Object (File)
Tue, Oct 22, 2:46 PM
Unknown Object (File)
Tue, Oct 22, 2:46 PM
Unknown Object (File)
Tue, Oct 22, 2:46 PM
Unknown Object (File)
Tue, Oct 22, 2:46 PM
Unknown Object (File)
Oct 11 2024, 11:49 AM
Unknown Object (File)
Oct 11 2024, 7:17 AM
Unknown Object (File)
Oct 11 2024, 3:58 AM
Subscribers

Details

Summary

issue: ENG-7267
We want to login / register before db starts being set up, so that if the credential are incorrect, and an error is thrown, the db is not left in an inconsistent state
unpickleAndUseCallback is modeled on fetchCallUpdateOlmAccount, but was rid of code that is used for fetching from and saving to the db. I also skipped retries, which only make sense if we operate on the db - they imitate transactions. Instead of fetching and saving account in the db, I remember them in the memory, and return them from verifyUserLoggedInWithoutDB to be saved once the tables get created

Test Plan

Ran my nix script that created a new ks, checked that the admin got correctly registered with identity.
Ran my nix script and provided incorrect credentials - checked that there are no tables in the db
Checked that the accounts saved to the db are the accounts after transformations (logged the accounts at the end of verifyUserLoggedInWithoutDB and checked that the same ones are in the db)

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

inka requested review of this revision.Apr 3 2024, 7:34 AM

Some nits left but looks good.

keyserver/src/database/migration-config.js
851 ↗(On Diff #38732)

I would be good to change the name of this function to indicate that it is supposed only to save brand new olm accounts in the database that doesn't already have any.

keyserver/src/user/login.js
88 ↗(On Diff #38732)

This violates the convention: ServerError should contain short and generic message. Look for examples in the code,

94 ↗(On Diff #38732)

It looks confusing. I think that using picklingKey directly is more readable.

This revision is now accepted and ready to land.Apr 5 2024, 3:18 AM
keyserver/src/user/login.js
88 ↗(On Diff #38732)

This is code copied from fetchCallUpdateOlmAccount.... And I don't know how I could fix that, since this is an error thrown from callback, which can throw anything. We could always throw 'unknown_error', would you prefer that?

94 ↗(On Diff #38732)

But this will make code more error prone in case we add another field to pickledOlmAccount in the future. This is how we usually do this

keyserver/src/user/login.js
88 ↗(On Diff #38732)

That said it looks like we started too loosen this convention some time ago so it is probably fine to leave it as it is.

94 ↗(On Diff #38732)

Your point is right - I didn't consider this code being modified in future.