Skip to content

Commit 65dcbe1

Browse files
authored
feat: add two-factor sign-in with authenticator apps (#103) and sign in with passkeys (#104)
Adds two-factor sign-in with authenticator apps (TOTP). Anyone can turn it on for themselves, and admins can require it of everyone on the instance. Until now a password, or a password reset link, was enough to get into an account that holds a Claude subscription, starts agents that push to the project's repositories and reads its secrets. ## What people get - **Settings → Two-factor sign-in.** "Set up" opens a dialog with a QR code that ripples in from the middle, the key in groups of four for apps that can't scan, and an "Open in your app" link on phones (iOS and Android hand `otpauth://` links to the passwords app or the authenticator). The code field is a single input drawn as two groups of three boxes, so pasting, the phone's one-time-code suggestions and password managers fill it at once, and it submits on the sixth digit. Then come ten recovery codes to copy, download as a text file, or print on a page of their own. **Replace** (new phone) asks for a code from the current app or a recovery code first. **Turn off** asks for a code too. Recovery codes show how many are left and suggest new ones at three. A switch, **Ask for a code when I sign in with Google too**, sits beside them. - **Signing in.** After a correct password the page asks for the code, showing who is signing in ("Not you?"). A wrong code shakes the boxes, and after the second miss the page says to check that the phone sets its clock automatically. A recovery code works in place of the app code. Five wrong codes in a row make codes from the app wait a minute, then twice as long each time, up to an hour, with a live countdown; recovery codes still work meanwhile. Signing in with a recovery code says how many are left. - **Google.** Google sign-ins don't ask for a code, since Google has its own two-step verification, unless the person turns that on or the admins do for everyone. Then Google's callback lands on `/two-factor`, which finishes the sign-in and goes on to where it started. - **Password resets.** A reset link for an account with two-factor asks for a code, and the new password takes effect only once the code checks out. Whoever reads someone's email can't lock them out with a reset link alone. - **Admin → Settings → Sign-in.** **Require two-factor sign-in** applies to everyone who signs in with a password. **Ask for codes on Google sign-in too** applies to Google sign-ins, and with the requirement on, to people who sign in only with Google. A meter shows how many people use it and who doesn't yet. Turning either switch on when it would stop people asks first and names them, including the admin. Someone it is required of who hasn't set it up sees a page that sets it up instead of the app, and the control plane refuses their other requests, from browser sessions and CLI and access tokens alike, with `two_factor_setup_required`. - **Admin → Users** shows who has two-factor, notes who still has to set it up, and has **Reset two-factor** for people who lost their phone and their recovery codes. Only owners can reset an owner's. - **CLI.** `fctl account two-factor` (or `2fa`) has `status`, `enable` (prints the QR code in the terminal, asks for the code, shows recovery codes; `--json` plus `confirm` without a terminal), `disable`, `recovery-codes` and `google on|off`. Admins get `fctl admin set --require-two-factor on --two-factor-google on` and `fctl admin reset-two-factor <email>`. `fctl whoami` and `fctl admin users` show two-factor too. `fctl login` approves the device in the browser, so the codes are asked for there. - **Email**, when it's set up: turning two-factor on, replacing the app, turning it off, an admin's reset, a sign-in with a recovery code, and the first wait after wrong codes (whoever it was knew the password) email the person. All of these go in the audit log. ## How it works TOTP per RFC 6238 (HMAC-SHA1, six digits, 30-second steps, one step of drift either way), in `fctl-domain` with RFC 4226 and RFC 6238 test vectors. The QR code is made in Rust (`qrcode` crate, no default features), so the web app and the terminal draw the same modules. - **Setup.** Nothing is stored until the app's first code confirms the secret. Until then the secret travels sealed for the person (AES-GCM under the master key, bound to `totp-setup:<user>`, 15 minutes). D1 then keeps it sealed again (`authenticator_apps`, bound to `totp:<user>`), with SHA-256 hashes of the recovery codes (`recovery_codes`). Setting up an app takes the password unless the browser signed in within 15 minutes; CLI and access tokens always count as old. - **Sign-in.** A sign-in that asks for a code starts no session. It leaves a challenge (`sign_in_challenges`, ten minutes, kept by its hash) in an `HttpOnly` `__Host-fctl-2fa` cookie, so the second step works the same after a password, after Google's redirect and after a reset link, and survives a reload. Each code works once (`last_step`). A code is checked, then the challenge claimed, then the code used up, so racing requests yield one session and burn nothing. - **The requirement** is checked on every request without an extra round trip: the token lookup reads the instance's settings in the same query. The reasoning, and what it leaves open (enrollment races, older CLIs showing `two_factor_setup_required` as an HTTP 403), is in [ADR 0022](docs/adr/0022-two-factor-sign-in-with-authenticator-apps.md). docs/architecture.md, docs/security.md, docs/cli.md, docs/self-hosting.md and docs/getting-started.md describe the behavior. **Compatibility.** `AuthResponse.me` becomes optional, since login and reset answer with `two_factor` when a code is needed. Successful sign-ins answer exactly as before, and nothing but the web app reads it. New fields (`Me.two_factor`, `User.two_factor`, the instance settings) are optional with defaults. Migration `0011_two_factor.sql` adds three tables and a column. `ErrorCode::TwoFactorSetupRequired` is new; a CLI from before it shows such errors as an HTTP 403 with the message. ## How I verified it - `cargo xtask check` passes: fmt, generated types, Biome and TypeScript, Clippy native and wasm, `cargo test`, Vitest, production builds. New tests cover the TOTP vectors, base32, replay, the lockout schedule, the policy (who needs it, when Google asks), recovery codes, the QR matrix, the terminal QR (read back module by module), the code input (paste, autofill, six-digit cap), the QR component and the web helpers. - End to end on `cargo xtask dev`, with the CLI, curl and Playwright, computing codes from the secrets: - setting up in Settings and from the CLI (with and without a terminal), and replacing the app (current code first); - signing in with password and code, wrong codes, five wrong codes sent at once (all counted), the wait (app codes refused, recovery codes accepted), a recovery code used twice (refused); - a reset link with two-factor (the old password keeps working until the code is entered); - Google's second step (challenge inserted the way the callback leaves it); - requiring two-factor (the confirmation names who isn't set up), the setup-only page, an access token refused until setup, and an admin reset putting someone back on that page; - the downloaded recovery codes file, and the print view, which shows only the codes, from the dark theme too. - The QR codes in the screenshots decode to the expected `otpauth://` links (jsQR), with the key shown under "Can't scan it?". - A code review pass found seven issues, all fixed here: tokens counting as fresh sign-ins, replacing without a code, wrong codes counted by read-modify-write, the wait being usable to lock owners out, a code burned when a racing request claimed the challenge, the terminal quiet zone, and `fctl admin set` when the requirement also stops the admin. ## Screenshots At 31c7878, from `cargo xtask dev`'s accounts. The code step after the password, and after five wrong codes: | Code | Waiting | |---|---| | ![The code step after the password, light](https://app.fctl.sh/api/v1/published/EQ5vCYJ25OeqgqXDXdvk14qs6zt6jU2NJRQ7cPfPcv9/login-code-light.png) | ![After five wrong codes: a countdown, and a button that switches to recovery codes](https://app.fctl.sh/api/v1/published/afqIHeB7EXnDzrR5jK8hkk3gDAdH7ojpT2TDwt4fKve/lockout-light.png) | Setting it up in Settings: the QR code with the key behind "Can't scan it?", then the recovery codes, and the section once it's on: | Scan | Recovery codes | |---|---| | ![The setup dialog: QR code, steps, code boxes](https://app.fctl.sh/api/v1/published/3uIVFGOSoWzRCTlHGs2gLOWqlqo09vAv9Qu9lnTqMpb/setup-scan-light.png) | ![Two-factor is on: ten recovery codes to copy, download or print](https://app.fctl.sh/api/v1/published/0uGB3GVvuKLfGlE08gM1eDU2naAjMx4rff2lyB7WnKR/setup-codes-light.png) | ![Settings → Two-factor sign-in once it's on: the app, recovery codes left, replace and turn off](https://app.fctl.sh/api/v1/published/8cxpskEY2XPW4cgSztzr7pzHxycAPUy3mID4bhcZkGR/settings-on-light.png) When the instance requires it, someone without it sees this instead of the app (dark theme, and at 390 px): | Desktop | Phone | |---|---| | ![The page that sets up two-factor, dark](https://app.fctl.sh/api/v1/published/clY4LgmtSfXemZvpgHUP9HgteL4jm5TI8EFx3VnwbAx/gate-dark.png) | ![The same page on a phone, with "Open in your app"](https://app.fctl.sh/api/v1/published/PgznoOCwOarAiqeU2H1bf0ZJqj6CjEFMepSK3MWGmo8/gate-dark-phone.png) | Admin → Settings → Sign-in, the confirmation that names who isn't set up, and Admin → Users: ![Admin sign-in settings: require two-factor, the meter of who uses it, Google sign-ins](https://app.fctl.sh/api/v1/published/5r2qDmR871RSyImoioPslqNHRzuTv6qYz5YW6qUBJzJ/admin-sign-in-required-light.png) | Confirmation | Users | |---|---| | ![Require two-factor sign-in? Grace Hopper hasn't set it up yet](https://app.fctl.sh/api/v1/published/cNe87QAkTQY9CcuXTBuel8RrraSRTFkhHLeztxdPY6Y/admin-require-confirm-light.png) | ![Users with two-factor badges, Reset two-factor, and who sets it up next](https://app.fctl.sh/api/v1/published/r3EOMwxj8mxtKPmhxL50zIsEZioHqAzcUUlEK4fQ9q5/admin-users-light.png) | The CLI's `enable`, in a terminal (the QR code prints dark on a light ground with ANSI colors): ``` $ fctl account two-factor enable Scan this with your authenticator app: █▀▀▀▀▀█ █ ▄ ▄█▄ ▀█▄▄▀ █▀▀▀ ▀█▄ █▀▀▀▀▀█ █ ███ █ ▄▀█ ▀▄▀▀ ▀ ▀▄▄ █▄ ▄ ▀▄▄▀ █ ███ █ … Or type in this key: M3K3 E46S BSGG LMTY KBWJ TFXL APJ3 K57W Code from the app: 123456 ✓ Two-factor sign-in is on: signing in with your password now also takes a code. Recovery codes: each one signs you in once if you lose your phone. Save them somewhere safe now, such as your password manager: they are shown once. WCQJK-QRVVQ DJHTP-FXPTT … ``` ## Related - hyperstructure/fctl-site#22: the privacy policy says what two-factor sign-in keeps. Merge the two together. - #104: passkeys, stacked on this pull request. Session: https://app.fctl.sh/s/ses_01M58KEJWPFJKBCENF5HKRV5HV --------- Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com>
1 parent 8e4bc48 commit 65dcbe1

113 files changed

Lines changed: 9460 additions & 202 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.lock‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ hyper-rustls = { version = "0.27.10", default-features = false, features = ["rin
5555
hyper-util = { version = "0.1.21", features = ["client", "client-legacy", "http1", "http2", "tokio"] }
5656
libc = "0.2.191"
5757
nix = { version = "0.31.3", features = ["signal", "process", "fs", "term", "user"] }
58+
qrcode = { version = "0.14.1", default-features = false }
5859
rusqlite = { version = "0.40.2", features = ["bundled"] }
5960
rustls = { version = "0.23.46", default-features = false, features = ["ring", "std", "tls12", "logging"] }
6061
serde = { version = "1.0.229", features = ["derive"] }
6162
serde_json = "1.0.154"
6263
serde_with = { version = "3", default-features = false, features = ["macros"] }
64+
sha1 = "0.11.0"
6365
sha2 = "0.11.1"
6466
tar = "0.4.46"
6567
thiserror = "2.0.21"

‎crates/fctl-client/src/api.rs‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,104 @@ impl Api {
154154
.await
155155
}
156156

157+
// ── two-factor sign-in ──
158+
159+
/// Your two-factor sign-in, and what the instance requires.
160+
pub async fn two_factor(&self) -> Result<TwoFactor> {
161+
self.get("/me/two-factor").await
162+
}
163+
164+
pub async fn update_two_factor(&self, req: &UpdateTwoFactorRequest) -> Result<Me> {
165+
self.patch("/me/two-factor", req).await
166+
}
167+
168+
/// A new authenticator app's secret, link and QR code, to confirm with
169+
/// [`Api::confirm_authenticator`]. Replacing the app you have takes
170+
/// `code`, from it or a recovery code.
171+
pub async fn start_authenticator(&self, code: Option<&str>) -> Result<AuthenticatorSetup> {
172+
self.post(
173+
"/me/two-factor/authenticator",
174+
&StartAuthenticatorRequest {
175+
code: code.map(str::to_owned),
176+
},
177+
)
178+
.await
179+
}
180+
181+
pub async fn confirm_authenticator(
182+
&self,
183+
req: &ConfirmAuthenticatorRequest,
184+
) -> Result<AuthenticatorAdded> {
185+
self.post("/me/two-factor/authenticator/confirm", req).await
186+
}
187+
188+
/// Turns two-factor sign-in off; `code` is a current code.
189+
pub async fn remove_authenticator(&self, code: &str) -> Result<Me> {
190+
self.post(
191+
"/me/two-factor/authenticator/remove",
192+
&TwoFactorCodeRequest {
193+
code: code.to_owned(),
194+
},
195+
)
196+
.await
197+
}
198+
199+
/// New recovery codes in place of the old ones; `code` is a current code.
200+
pub async fn new_recovery_codes(&self, code: &str) -> Result<RecoveryCodes> {
201+
self.post(
202+
"/me/two-factor/recovery-codes",
203+
&TwoFactorCodeRequest {
204+
code: code.to_owned(),
205+
},
206+
)
207+
.await
208+
}
209+
210+
// ── passkeys ──
211+
//
212+
// Making a passkey and signing in with one take an authenticator's
213+
// answer (`navigator.credentials` in a browser); these carry it.
214+
215+
/// What an authenticator needs to make a passkey for you.
216+
pub async fn passkey_options(
217+
&self,
218+
req: &PasskeyOptionsRequest,
219+
) -> Result<PasskeyCreationOptions> {
220+
self.post("/me/passkeys/options", req).await
221+
}
222+
223+
/// Keeps the passkey an authenticator made with [`Api::passkey_options`].
224+
pub async fn add_passkey(&self, req: &AddPasskeyRequest) -> Result<Me> {
225+
self.post("/me/passkeys", req).await
226+
}
227+
228+
/// What an authenticator needs to sign in with a passkey.
229+
pub async fn passkey_sign_in_options(&self) -> Result<PasskeyRequestOptions> {
230+
self.post("/auth/passkey/options", &serde_json::json!({}))
231+
.await
232+
}
233+
234+
/// Signs in with a passkey's answer; the session comes as a cookie.
235+
pub async fn passkey_sign_in(&self, req: &PasskeySignInRequest) -> Result<AuthResponse> {
236+
self.post("/auth/passkey", req).await
237+
}
238+
239+
/// Renames one of your passkeys.
240+
pub async fn rename_passkey(&self, id: &str, name: &str) -> Result<Me> {
241+
self.patch(
242+
&format!("/me/passkeys/{}", enc(id)),
243+
&UpdatePasskeyRequest {
244+
name: name.to_owned(),
245+
},
246+
)
247+
.await
248+
}
249+
250+
/// Removes one of your passkeys.
251+
pub async fn remove_passkey(&self, id: &str) -> Result<Me> {
252+
self.delete(&format!("/me/passkeys/{}", enc(id))).await
253+
}
254+
157255
// ── notifications ──
158256

159257
/// What notifies you, and the browsers that show your notifications.
@@ -611,6 +709,12 @@ impl Api {
611709
self.delete(&format!("/admin/allowlist/{}", enc(id))).await
612710
}
613711

712+
/// Turns off a user's two-factor sign-in (they lost their phone).
713+
pub async fn reset_two_factor(&self, user_id: &str) -> Result<User> {
714+
self.delete(&format!("/admin/users/{}/two-factor", enc(user_id)))
715+
.await
716+
}
717+
614718
pub async fn instance_settings(&self) -> Result<InstanceSettings> {
615719
self.get("/admin/settings").await
616720
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
-- Two-factor sign-in (docs/architecture.md#two-factor-sign-in): after the
2+
-- password, and after Google when the person or the instance asks for it,
3+
-- a code from an authenticator app or a recovery code.
4+
5+
-- An authenticator app (TOTP, RFC 6238), at most one per person. The secret
6+
-- is sealed with the master key and bound to `totp:<user_id>`. Codes of time
7+
-- steps up to `last_step` are refused, so that each code works once.
8+
-- `failures` counts wrong codes in a row; after five, sign-ins wait until
9+
-- `locked_until`, longer each time.
10+
CREATE TABLE IF NOT EXISTS authenticator_apps (
11+
user_id TEXT PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
12+
secret_enc TEXT NOT NULL,
13+
last_step INTEGER NOT NULL DEFAULT 0,
14+
failures INTEGER NOT NULL DEFAULT 0,
15+
locked_until INTEGER,
16+
created_at INTEGER NOT NULL,
17+
last_used_at INTEGER
18+
);
19+
20+
-- One-time codes for when the authenticator app is gone, ten at a time.
21+
-- Only the SHA-256 of each (without its dash, in capitals) is kept.
22+
CREATE TABLE IF NOT EXISTS recovery_codes (
23+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
24+
code_hash TEXT NOT NULL,
25+
created_at INTEGER NOT NULL,
26+
used_at INTEGER,
27+
PRIMARY KEY (user_id, code_hash)
28+
);
29+
30+
-- Sign-ins that wait for the second factor, for ten minutes: after the
31+
-- password, after Google (`return_to`: where the app goes next) or after a
32+
-- reset link chose a new password (`reset_hash` names the link, and
33+
-- `password_hash` holds the new password until the code checks out). The
34+
-- browser holds the challenge in the `__Host-fctl-2fa` cookie; only its
35+
-- SHA-256 is kept here.
36+
CREATE TABLE IF NOT EXISTS sign_in_challenges (
37+
hash TEXT PRIMARY KEY,
38+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
39+
reason TEXT NOT NULL CHECK (reason IN ('password', 'google', 'password_reset')),
40+
return_to TEXT,
41+
reset_hash TEXT,
42+
password_hash TEXT,
43+
created_at INTEGER NOT NULL,
44+
expires_at INTEGER NOT NULL
45+
);
46+
CREATE INDEX IF NOT EXISTS sign_in_challenges_user ON sign_in_challenges (user_id);
47+
48+
-- Google sign-ins ask this person for the second factor too.
49+
ALTER TABLE users ADD COLUMN two_factor_google INTEGER NOT NULL DEFAULT 0;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- Passkeys (docs/architecture.md#passkeys): people sign in with their
2+
-- fingerprint, face or screen lock, and where two-factor sign-in is
3+
-- required a passkey is also a second factor.
4+
5+
-- A passkey: a WebAuthn credential its authenticator finds by itself.
6+
-- `public_key` is its COSE key (base64url), which checks each sign-in's
7+
-- signature; `sign_count` is the authenticator's counter, which must move on
8+
-- unless it stays 0, as synced passkeys' does. `aaguid` names the
9+
-- authenticator's model, and so the provider that keeps the passkey;
10+
-- `backed_up` says whether it syncs between devices.
11+
CREATE TABLE IF NOT EXISTS passkeys (
12+
id TEXT PRIMARY KEY,
13+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
14+
credential_id TEXT NOT NULL UNIQUE,
15+
public_key TEXT NOT NULL,
16+
algorithm INTEGER NOT NULL,
17+
sign_count INTEGER NOT NULL DEFAULT 0,
18+
transports TEXT,
19+
aaguid TEXT,
20+
backed_up INTEGER NOT NULL DEFAULT 0,
21+
name TEXT NOT NULL,
22+
created_at INTEGER NOT NULL,
23+
last_used_at INTEGER
24+
);
25+
CREATE INDEX IF NOT EXISTS passkeys_user ON passkeys (user_id);
26+
27+
-- The challenges passkeys sign, each good once for ten minutes, by its
28+
-- SHA-256: to make a passkey (`register`, for `user_id`), to sign in with one
29+
-- (`sign_in`), or to use one as the second factor of the waiting sign-in
30+
-- whose hash is `sign_in_hash` (`second_factor`).
31+
CREATE TABLE IF NOT EXISTS passkey_challenges (
32+
hash TEXT PRIMARY KEY,
33+
purpose TEXT NOT NULL CHECK (purpose IN ('register', 'sign_in', 'second_factor')),
34+
user_id TEXT REFERENCES users(id) ON DELETE CASCADE,
35+
sign_in_hash TEXT,
36+
created_at INTEGER NOT NULL,
37+
expires_at INTEGER NOT NULL
38+
);
39+
CREATE INDEX IF NOT EXISTS passkey_challenges_expiry ON passkey_challenges (expires_at);

‎crates/fctl-control/src/api/account.rs‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ pub async fn erase(ctx: &mut Ctx, user: &UserRow, plan: &Plan) -> AppResult<()>
169169
"session_followers",
170170
"notification_settings",
171171
"push_subscriptions",
172+
"authenticator_apps",
173+
"recovery_codes",
174+
"sign_in_challenges",
175+
"passkeys",
176+
"passkey_challenges",
172177
] {
173178
statements.push(q(
174179
db,
@@ -190,7 +195,7 @@ pub async fn erase(ctx: &mut Ctx, user: &UserRow, plan: &Plan) -> AppResult<()>
190195
statements.push(q(
191196
db,
192197
"UPDATE users SET email = ?, name = ?, given_name = NULL, family_name = NULL, avatar_url = NULL, commit_email = NULL, password_hash = NULL, role = 'member', \
193-
status = 'disabled', default_credential_id = NULL, last_login_at = NULL, updated_at = ? \
198+
status = 'disabled', default_credential_id = NULL, last_login_at = NULL, two_factor_google = 0, updated_at = ? \
194199
WHERE id = ? AND (EXISTS (SELECT 1 FROM sessions WHERE created_by = ?) OR EXISTS (SELECT 1 FROM projects WHERE created_by = ?))",
195200
&[
196201
s(&acct::tombstone_email(id)),
@@ -398,6 +403,41 @@ pub async fn export(ctx: &mut Ctx) -> AppResult<Response> {
398403
)
399404
.await?,
400405
);
406+
doc.insert(
407+
"two_factor".into(),
408+
json!({
409+
"ask_on_google_sign_in": user.two_factor_google,
410+
"authenticator_app": rows(
411+
ctx,
412+
"SELECT created_at, last_used_at, failures AS wrong_codes_in_a_row, locked_until FROM authenticator_apps WHERE user_id = ?",
413+
&me(),
414+
)
415+
.await?
416+
.as_array()
417+
.and_then(|a| a.first().cloned()),
418+
"recovery_codes": rows(
419+
ctx,
420+
"SELECT created_at, used_at FROM recovery_codes WHERE user_id = ? ORDER BY created_at, used_at",
421+
&me(),
422+
)
423+
.await?,
424+
"waiting_sign_ins": rows(
425+
ctx,
426+
"SELECT reason, created_at, expires_at FROM sign_in_challenges WHERE user_id = ? ORDER BY created_at",
427+
&me(),
428+
)
429+
.await?,
430+
}),
431+
);
432+
doc.insert(
433+
"passkeys".into(),
434+
rows(
435+
ctx,
436+
"SELECT name, aaguid AS authenticator_model, backed_up AS synced, transports, created_at, last_used_at FROM passkeys WHERE user_id = ? ORDER BY created_at",
437+
&me(),
438+
)
439+
.await?,
440+
);
401441
doc.insert(
402442
"devices_and_tokens".into(),
403443
rows(

‎crates/fctl-control/src/api/admin.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,17 @@ pub async fn update_settings(ctx: &mut Ctx, req: &mut Request) -> AppResult<Resp
444444
if let Some(on) = body.publish_screenshots {
445445
settings.publish_screenshots = on;
446446
}
447+
if let Some(on) = body.require_two_factor {
448+
// Without the master key nobody could set two-factor up, and
449+
// everyone it applies to would be stuck.
450+
if on {
451+
ctx.keys()?;
452+
}
453+
settings.require_two_factor = on;
454+
}
455+
if let Some(on) = body.two_factor_google {
456+
settings.two_factor_google = on;
457+
}
447458
crate::instance::save(&ctx.db, &settings).await?;
448459
ctx.audit(
449460
"instance.settings_updated",

0 commit comments

Comments
 (0)