Skip to content

Hosted two-factor sign-in: per-team rule, one factor per person on every way in - #332

Merged
nambok merged 1 commit into
mainfrom
feat/hosted-team-2fa
Oct 27, 2026
Merged

nambok merged 1 commit into
mainfrom
feat/hosted-team-2fa

Conversation

@nambok

@nambok nambok commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Two-factor sign-in on hosted CoderHelm (app.coderhelm.com), working the way it already does on a self-hosted install:

  • Each team's admins can require two-factor sign-in for that team (Settings, Sign-in). The rule is stored per team and read fresh on every request a session makes in that team, with a consistent read and no cache; if it can't be read, the request is refused. A session without a second factor is held there exactly as on self-host: it can see who it is, set up a second factor (only if it has none), and sign out. Someone on several teams is held only in the teams that require it.
  • One second factor per person, asked for on every way in. Hosted Google, GitHub and password sign-ins now ask for the person's factor (the authenticator-app code, or Cognito's code on the password account) before any session is made, whether or not a team requires it. Someone whose factor is on the password account and who uses Google or GitHub is sent back to the password sign-in, as on self-host. The factor belongs to the person, not a team: on hosted it is kept on one record per person (by email), so every team sees the same one.
  • Safe to turn on. The admin's own session must have passed a second factor first. Settings, Sign-in shows how many people haven't set one up. When the rule goes on, each of them gets an email (a new essential template, two_factor_required, through the existing mail path and recorded in Deliveries). Turning it on or off is logged.
  • Recovery is an admin resetting the person's factor after checking it's them, logged before anything changes, as on self-host. On hosted the factor protects every team the person is on, so:
    • their sessions end on every team;
    • they get an email saying so (two_factor_reset);
    • the reset is refused when the person is on another team (with other people on it) where this admin couldn't reset them. Without that check, an admin of one team who also knew someone's password could strip the factor that protects a different team, then sign in and set up their own.
  • API keys are handled as in Sign-in: one second factor per member; approval links check the team; narrower log reader role #328: keys made before the team's rule are flagged on Settings, Sign-in and Settings, API keys.

Dashboard and docs: CoderHelm/coderhelm#243

Changes

  • routes/sign_in.rs
    • Rule and team_rule: the organization's rule on self-host, pk = <team>, sk = SETTINGS#SIGN_IN on hosted.
    • hosted_home_key, home_key and factor_home: where a person's factor is kept. On self-host that is still the member record, so nothing moves there.
    • check_session now takes the acting team.
    • Every factor read and write goes through the factor's home: my_status, the app setup, verify and disable routes, check_enroll, needed_for, verify_second_step, reset_two_factor, note_factor and the key reviews.
    • person_records, must_keep and end_person_sessions cover a person across teams. A factor stays on while any of their teams requires it, and turning it off ends their other sessions on every team.
    • get_settings and update_settings work on both deployments. Hosted refuses domains and returns without_2fa and notified.
    • notify_required, notify_reset, may_reset_on and teams_beyond_reach are new.
    • The self-host-only 404s are gone from the setup, settings and reset routes.
  • middleware/auth.rs: the two-factor check runs on every deployment, for the team the session acts in, still after the member-record check and before the role check.
  • routes/auth.rs:
    • hosted Google, GitHub and password sign-ins call second_step / password_step before making a session;
    • hosted Google sessions now carry their sign-in proof (create_session_token replaces create_token);
    • a Cognito code passed on hosted is recorded on the person's record.
  • routes/users.rs: Cognito MFA setup, verify and disable use the one-factor checks on hosted too. Turning it off takes a session that passed it and is refused while a team of theirs requires it.
  • routes/api_keys.rs: key reviews for every deployment.
  • permissions.rs: the sign_in capability's label now describes hosted. Admins only, never in a custom role, as before.
  • common/src/mail: the two_factor_required and two_factor_reset templates, both essential.
  • Docs: self-host/sign-in.md and self-host/email.md cover the two new emails.

Verification

  • cargo fmt --check and cargo clippy --workspace --all-targets -D warnings: clean.
  • cargo test --workspace after rebasing on main (Runs that stop to ask: keep the questions, answer from CoderHelm, never ask twice #330): 2443 passed, 16 ignored. New and changed sign-in tests:
    • a hosted factor is kept once per person (Google, GitHub and a password give the same record; no email falls back to the member id; never read as a member), and every factor read or write goes through its home;
    • a team's rule reads back and is off by default;
    • every hosted way in asks for the factor before a session, at the top of the function rather than under the self-host branch, and no Google session is made without its proof;
    • the setup, settings and reset routes work on both deployments; turning a factor off checks every team of the person first;
    • turning the rule on: the admin's own factor comes first, it is logged first, the hosted rule is the team's record, and people without a factor are emailed after it is saved; both templates are registered and essential;
    • a hosted reset stays within what the admin manages (not on the team, an admin resetting an owner, a member, an invite: refused; a team with only the person on it: allowed), checked before anything is logged;
    • the middleware reads the acting team's rule on every request on both deployments, with a consistent read and no cache.
  • The diff has no customer names and no arrow glyphs.

…ery way in

Team admins on hosted can require two-factor sign-in for their team. The
rule is read fresh on every request in that team and fails closed. Hosted
Google, GitHub and password sign-ins ask for the person's one second
factor whether or not a team requires it. The admin must have a factor
before turning the rule on, members without one are emailed, and a reset
is logged, ends the person's sessions on every team, emails them, and
stays within teams the admin manages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant