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.
Prerequisites
Section titled “Prerequisites”- 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.
- The operator makes the key file and sets
NURAMESH_AUTH_KEY_FILE: What the server needs. - Enrol and confirm with the first code: Turn it on for yourself.
- Store the 10 recovery codes somewhere other than the authenticator app.
- Sign out and in again: Sign in with a code.
What is not there yet
Section titled “What is not there yet”- 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 mfacommands are for the operator only:statusandreset. - 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.
When a fresh code is asked for
Section titled “When a fresh code is asked for”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:
PUTandDELETEon/v1/models/connections/{provider}/key. - A solo approval of a high-risk action:
POST /v1/approvals/{approval_id}/approve(and the olderdecisionroute) 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.
What the server needs
Section titled “What the server needs”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:
nuramesh auth factor-key init --file /path/to/auth-key --team my-teamNURAMESH_AUTH_KEY_FILEnames the key file. Without a readable key, enrolling and signing in with a code answer 503mfa_unavailable.NURAMESH_MFA_ISSUER(optional) is the name the authenticator app shows. The default isNuraMesh; 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 rotatere-seals the factors under a new key (NURAMESH_AUTH_KEY_FILE_PREVIOUSholds the old one while it runs).nuramesh auth factor-key destroydeletes every factor and turns the owner policy off. Both are operator commands that needNURAMESH_OPERATOR=1.
Turn it on for yourself
Section titled “Turn it on for yourself”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.
POST /v1/auth/mfa/enrollwith{"password": "..."}starts enrolment. The answer holdsfactor_id,secret(base32) andotpauth_uri. Add the secret to your authenticator app, or draw theotpauth_urias a QR code.POST /v1/auth/mfa/enroll/confirmwith{"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.
Sign in with a code
Section titled “Sign in with a code”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/enrollwith{"challenge": "..."}returnsfactor_id,secretandotpauth_uri.POST /v1/auth/login/mfa/enroll/confirmwith{"challenge": "...", "factor_id": "...", "code": "123456"}returns the session and the 10recovery_codes.
Recovery codes
Section titled “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.
Turn it off
Section titled “Turn it off”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.
The owner
Section titled “The owner”GET /v1/auth/settingsshowsmfa_required_for_owners.PUT /v1/auth/settings/mfawith{"required": true}requires it for owners. The owner who sets it must be enrolled first (409mfa_not_enrolled), and the server needs its key.POST /v1/auth/users/{user_id}/mfa/resetremoves another person’s factor and ends all of their sessions. It does nothing to yourself (409use_self_service). Every change is in the ledger and the person gets a fixed notice mail.
When the owner is locked out
Section titled “When the owner is locked out”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:
nuramesh auth recovery-code issue --team my-teamnuramesh auth mfa status --team my-teamnuramesh auth mfa reset --user human:u_example --team my-teamstatus 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.
Check it worked
Section titled “Check it worked”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:
nuramesh auth mfa status --team my-teamTroubleshooting
Section titled “Troubleshooting”| 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 |
Next steps
Section titled “Next steps”- Accounts and roles: who may do what once signed in.
- Require a human approval: the solo approval that asks for a fresh code.
- Errors: every code on this page.
Was this page helpful?