Skip to content
Docs
Request access

Turn on two-step sign-in

Two-step sign-in (multi-factor sign-in, MFA) asks for a six-digit code from an authenticator app after the password. It uses TOTP: 6 digits, a new code every 30 seconds. A person who turns it on also gets 10 recovery codes, each good once. In the examples every code is written as 123456 or obviously-fake-example; none is a real value.

  • A running server with sign-in on, and your own account on it (Accounts and roles).
  • An authenticator app that supports TOTP.
  • An HTTP client for the API: the app has no screens for this yet (see below).
  • The operator has made the server’s key file: What the server needs.
  1. The operator makes the key file and sets NURAMESH_AUTH_KEY_FILE: What the server needs.
  2. Enrol and confirm with the first code: Turn it on for yourself.
  3. Store the 10 recovery codes somewhere other than the authenticator app.
  4. Sign out and in again: Sign in with a code.
  • App screens for enrolling and signing in with a code. Until then, use the API.
  • A command to enrol from the command line. The nuramesh auth mfa commands are for the operator only: status and reset.
  • A fresh code for risky actions in general. Only the two actions in When a fresh code is asked for ask today; other risky actions do not ask yet.

A fresh code is one entered at sign-in or since, within the last 10 minutes. A hosted deployment asks for it on the two actions below. A self-hosted server asks only a person who has turned on two-step sign-in.

  • Changing a stored model key: PUT and DELETE on /v1/models/connections/{provider}/key.
  • A solo approval of a high-risk action: POST /v1/approvals/{approval_id}/approve (and the older decision route) when you are the only person in the organization who can decide. The high-risk kinds are spend, external message, merge, run command, network and use tool. A self-hosted person without two-step sign-in confirms the password or signs in again instead.

Without a fresh code the answer is 403 mfa_required. If the server has no readable key it is 403 mfa_unavailable here (not the 503 of enrolling), and on a hosted deployment a person who has not enrolled gets 403 mfa_enrollment_required.

The server seals each person’s authenticator secret with a key from a file. The operator makes the file as the server’s OS user, then sets the variable it prints:

Terminal window
nuramesh auth factor-key init --file /path/to/auth-key --team my-team
  • NURAMESH_AUTH_KEY_FILE names the key file. Without a readable key, enrolling and signing in with a code answer 503 mfa_unavailable.
  • NURAMESH_MFA_ISSUER (optional) is the name the authenticator app shows. The default is NuraMesh; it must be printable text of at most 64 characters.
  • NURAMESH_MFA_CHALLENGE_SECONDS (optional) is how long the second step stays open after the password: a whole number from 30 to 900.
  • nuramesh auth factor-key rotate re-seals the factors under a new key (NURAMESH_AUTH_KEY_FILE_PREVIOUS holds the old one while it runs). nuramesh auth factor-key destroy deletes every factor and turns the owner policy off. Both are operator commands that need NURAMESH_OPERATOR=1.

You must be signed in as a person. An API token or an agent credential gets 403 human_required. Every answer that carries a secret is sent with Cache-Control: no-store.

  1. POST /v1/auth/mfa/enroll with {"password": "..."} starts enrolment. The answer holds factor_id, secret (base32) and otpauth_uri. Add the secret to your authenticator app, or draw the otpauth_uri as a QR code.
  2. POST /v1/auth/mfa/enroll/confirm with {"factor_id": "...", "code": "123456"} finishes it with the first code from the app. The answer is {"recovery_codes": [...]}: 10 codes, shown once. Your other sessions end; the current one stays.

Check where you stand with GET /v1/auth/mfa: it shows available, enrolled, confirmed_at, recovery_codes_remaining and required.

Errors: 409 mfa_already_enrolled if it is already on, 409 no_pending_factor if the pending factor is gone (start again), 409 reauth_required if the password must be entered again, 401 mfa_invalid for a wrong code. A code that was already used cannot be used again.

When the password is right and the person has a factor, POST /v1/auth/login answers with status mfa_required, a challenge, methods (totp and recovery_code) and expires_in. Send the challenge back to POST /v1/auth/login/mfa:

POST /v1/auth/login/mfa body: {"challenge": "...", "code": "123456"}
POST /v1/auth/login/mfa body: {"challenge": "...", "recovery_code": "obviously-fake-example"}

Send exactly one of code and recovery_code, or the request is refused as invalid. A challenge allows 5 wrong codes. A right answer starts the session like a normal sign-in.

If the organization requires two-step sign-in and the person has not enrolled, the login answers mfa_enroll_required. Enrol inside the same challenge:

  • POST /v1/auth/login/mfa/enroll with {"challenge": "..."} returns factor_id, secret and otpauth_uri.
  • POST /v1/auth/login/mfa/enroll/confirm with {"challenge": "...", "factor_id": "...", "code": "123456"} returns the session and the 10 recovery_codes.

Use a recovery code at sign-in in place of a code from the app. Each works once. POST /v1/auth/mfa/recovery-codes with {"password": "...", "code": "123456"} makes 10 new ones; every old one stops working. Keep them somewhere other than your authenticator app.

POST /v1/auth/mfa/disable with {"password": "...", "code": "123456"} removes your factor and ends your other sessions. An owner cannot do this while the organization requires it: 409 mfa_required_by_policy. Without a factor, 409 mfa_not_enrolled.

  • GET /v1/auth/settings shows mfa_required_for_owners.
  • PUT /v1/auth/settings/mfa with {"required": true} requires it for owners. The owner who sets it must be enrolled first (409 mfa_not_enrolled), and the server needs its key.
  • POST /v1/auth/users/{user_id}/mfa/reset removes another person’s factor and ends all of their sessions. It does nothing to yourself (409 use_self_service). Every change is in the ledger and the person gets a fixed notice mail.

The operator can see and reset factors from the server’s shell. There is no HTTP route for this reset. It needs NURAMESH_OPERATOR=1, an interactive terminal and an operator recovery code (nuramesh auth recovery-code issue), which is spent first:

Terminal window
nuramesh auth recovery-code issue --team my-team
nuramesh auth mfa status --team my-team
nuramesh auth mfa reset --user human:u_example --team my-team

status prints the owner policy and one line per person: id, role, enrolled or not-enrolled. No secret is printed. See the CLI reference and the API reference.

Errors on this page are listed in the error reference.

GET /v1/auth/mfa shows enrolled: true, a confirmed_at time and recovery_codes_remaining: 10. The next POST /v1/auth/login with your password answers with status mfa_required instead of a session. The operator sees the same from the server’s shell:

Terminal window
nuramesh auth mfa status --team my-team
You see Do this
503 mfa_unavailable when enrolling The server has no readable key file. The operator runs nuramesh auth factor-key init and sets NURAMESH_AUTH_KEY_FILE
401 mfa_invalid The code is wrong or was already used. Wait for the next code; check the clock of the phone
409 no_pending_factor The pending factor is gone. Start enrolment again
409 reauth_required Enter the password again, then repeat the request
403 human_required An API token or an agent credential cannot enrol. Sign in as a person
The phone is lost Sign in with a recovery code, then make new ones. An owner who has neither: When the owner is locked out

Was this page helpful?