forge
Explore
Log in

Don't you dare go Hollow

Migrated İzlek users enrol TOTP on first login

Browse files at this commit

f675a3dfb8af889a27c2666cb91e345b362ec7caAhmet Kaan GümüşParent: 71f9a9c
  • feat
    • migrated İzlek users enrol TOTP on first login
    • ship im-migrate in deploys
Show full message
feat: migrated İzlek users enrol TOTP on first login; ship im-migrate in deploys

- accounts without confirmed 2FA are routed through /enrol before any
  session exists — same bar as invited accounts; a migrated user mid-
  /authorize continues to their app after enrolling
- deploy stages im-migrate alongside im-web so the import runs on the server
- fix: im-migrate's duplicated schema had drifted (no admin/app_sessions/
  events/settings), producing databases the server could not log into —
  synced to store::SCHEMA, with the drift lesson in the doc comment

Verified live: fixture izlek.db -> im-migrate -> password login (hash
verbatim) -> forced TOTP enrolment -> signed-in session.
.github/workflows/main.ymlmodified+5 -3
@@ -88,10 +88,13 @@ jobs:
88 run: |88 run: |
89 set -euo pipefail89 set -euo pipefail
90 # One compile: this builds im-web and writes out the asset bundle90 # One compile: this builds im-web and writes out the asset bundle
91- # for the binary it produced.91+ # for the binary it produced. im-migrate rides along for the
92+ # one-time İzlek import (run by hand on the server).
92 topcoat asset bundle --package im-web --profile "$PROFILE" --out stage/assets93 topcoat asset bundle --package im-web --profile "$PROFILE" --out stage/assets
94+ cargo build --package im-migrate --profile "$PROFILE"
93 cp "target/$TARGET/$PROFILE/im-web" stage/im-web95 cp "target/$TARGET/$PROFILE/im-web" stage/im-web
94- strip stage/im-web96+ cp "target/$TARGET/$PROFILE/im-migrate" stage/im-migrate
97+ strip stage/im-web stage/im-migrate
95 ls -l stage stage/assets98 ls -l stage stage/assets
96 99
97 - name: Install SSH keys100 - name: Install SSH keys
@@ -99,7 +102,6 @@ jobs:
99 mkdir -p ~/.ssh102 mkdir -p ~/.ssh
100 echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa103 echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
101 ssh-keyscan -H ${{ secrets.SSH_HOST }} > ~/.ssh/known_hosts104 ssh-keyscan -H ${{ secrets.SSH_HOST }} > ~/.ssh/known_hosts
102-
103 - name: Upload the release105 - name: Upload the release
104 run: |106 run: |
105 set -euo pipefail107 set -euo pipefail
crates/im-migrate/src/main.rsmodified+25 -1
@@ -21,7 +21,9 @@ use turso::Builder;
21 21
22 /// im's schema, duplicated literally from im-core's `store::SCHEMA` — the22 /// im's schema, duplicated literally from im-core's `store::SCHEMA` — the
23 /// tool stays dependency-free of im-core so a build of this binary never23 /// tool stays dependency-free of im-core so a build of this binary never
24-/// drags the argon2/rsa tree along.24+/// drags the argon2/rsa tree along. When im-core's schema changes, change
25+/// this in the same diff: a drifted copy once produced a database the
26+/// server could not read, and every login answered "bad_login".
25 const IM_SCHEMA: &str = "27 const IM_SCHEMA: &str = "
26 CREATE TABLE IF NOT EXISTS users (28 CREATE TABLE IF NOT EXISTS users (
27 id TEXT PRIMARY KEY,29 id TEXT PRIMARY KEY,
@@ -30,6 +32,7 @@ CREATE TABLE IF NOT EXISTS users (
30 password_hash TEXT NOT NULL,32 password_hash TEXT NOT NULL,
31 totp_secret BLOB,33 totp_secret BLOB,
32 totp_confirmed INTEGER NOT NULL DEFAULT 0,34 totp_confirmed INTEGER NOT NULL DEFAULT 0,
35+ admin INTEGER NOT NULL DEFAULT 0,
33 disabled INTEGER NOT NULL DEFAULT 0,36 disabled INTEGER NOT NULL DEFAULT 0,
34 created_at TEXT NOT NULL37 created_at TEXT NOT NULL
35 );38 );
@@ -37,6 +40,7 @@ CREATE TABLE IF NOT EXISTS invites (
37 token TEXT PRIMARY KEY,40 token TEXT PRIMARY KEY,
38 email TEXT NOT NULL,41 email TEXT NOT NULL,
39 invited_by TEXT,42 invited_by TEXT,
43+ admin INTEGER NOT NULL DEFAULT 0,
40 created_at TEXT NOT NULL,44 created_at TEXT NOT NULL,
41 expires_at TEXT NOT NULL,45 expires_at TEXT NOT NULL,
42 accepted_at TEXT46 accepted_at TEXT
@@ -81,6 +85,26 @@ CREATE TABLE IF NOT EXISTS signing_keys (
81 created_at TEXT NOT NULL,85 created_at TEXT NOT NULL,
82 active INTEGER NOT NULL DEFAULT 186 active INTEGER NOT NULL DEFAULT 1
83 );87 );
88+CREATE TABLE IF NOT EXISTS app_sessions (
89+ token_hash TEXT PRIMARY KEY,
90+ user_id TEXT NOT NULL REFERENCES users(id),
91+ client_id TEXT NOT NULL REFERENCES oidc_clients(client_id),
92+ session_hash TEXT NOT NULL REFERENCES sessions(token_hash),
93+ created_at TEXT NOT NULL,
94+ expires_at TEXT NOT NULL,
95+ revoked_at TEXT
96+);
97+CREATE TABLE IF NOT EXISTS events (
98+ id TEXT PRIMARY KEY,
99+ at TEXT NOT NULL,
100+ kind TEXT NOT NULL,
101+ actor TEXT,
102+ detail TEXT
103+);
104+CREATE TABLE IF NOT EXISTS settings (
105+ key TEXT PRIMARY KEY,
106+ value TEXT NOT NULL
107+);
84 ";108 ";
85 109
86 #[derive(Debug)]110 #[derive(Debug)]
crates/im-web/src/auth.rsmodified+17 -7
@@ -62,12 +62,16 @@ async fn login(cx: &Cx, Form(input): Form<LoginForm>) -> Redirect {
62 see("/login/totp".to_string())62 see("/login/totp".to_string())
63 }63 }
64 Ok(user) => {64 Ok(user) => {
65- // Accounts enrol TOTP at invite time, so this is the path for one65+ // An account without confirmed 2FA — everyone who migrated from
66- // created before that rule — sign it in, enrolment comes next.66+ // İzlek — enrols before any session exists: same bar as an
67- let token = im_core::sessions::create_session(store, &user.id).await?;67+ // invited account.
68- im_core::events::log(store, "login_ok", Some(&user.email), None).await;68+ if im_core::totp::totp_secret(store, &user.id).await?.is_none() {
69- server::set_session_cookie(cx, token.expose());69+ let secret = im_core::totp::generate_secret();
70- see(back)70+ im_core::totp::set_totp(store, &user.id, &secret).await?;
71+ }
72+ let sealed = server::mint_pending(cx, &user.id, PendingPurpose::Enroll, back);
73+ server::set_pending_cookie(cx, sealed);
74+ see("/enroll".to_string())
71 }75 }
72 Err(_) => {76 Err(_) => {
73 // The failure is logged against the address tried, never the77 // The failure is logged against the address tried, never the
@@ -199,7 +203,13 @@ async fn enroll(cx: &Cx, Form(input): Form<TotpForm>) -> Redirect {
199 im_core::events::log(store, "enrolled", email.as_deref(), None).await;203 im_core::events::log(store, "enrolled", email.as_deref(), None).await;
200 server::clear_pending_cookie(cx);204 server::clear_pending_cookie(cx);
201 server::set_session_cookie(cx, token.expose());205 server::set_session_cookie(cx, token.expose());
202- see("/?ok=enrolled".to_string())206+ // A migrated user who was mid-`/authorize` continues to their app; a
207+ // fresh invite lands on the welcome banner.
208+ if pending.back == "/" {
209+ see("/?ok=enrolled".to_string())
210+ } else {
211+ see(pending.back)
212+ }
203 }213 }
204 214
205 /// "Sign out everywhere": the central session dies, and with it every215 /// "Sign out everywhere": the central session dies, and with it every