--- authors: Sasha Klizhentas (sasha@goteleport.com) state: draft --- # RFD 29 - Account Life-cycle: Recovery and Cancellation ## What Introduces cloud account recovery and cancellation flow. ## Why Having a secure self-management account recovery and cancellation flow improves user experience and reduces support load on teams. ## Details The recovery flow focuses on local accounts. SSO account recovery is covered by "All is lost" scenario. The flow will work for cloud and non-cloud accounts. For cloud it should be impossible to turn off second factor. For self-hosted, if second factor is off, the account recovery should not be possible. Each local user will receive 3 account recovery tokens on sign up. Each token is a crypto-randomly generated passphrase string that could be used only once. We will use the vendored EFF long list via diceware library https://github.com/sethvargo/go-diceware The token is 8 word token resulting in roughly [~100 bits of entropy](https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases). Once signed up or invited, users will register with their username, password and second factor. Then users will be presented with the recovery tokens displayed on the screen with a message: ``` Recovery tokens generated on January 15th, 2020. Please save these account recovery tokens for example.teleport.sh in a safe offline place. You can use each token once if you loose your second factor or a password. * tele-cosponsor-happening-moocher-undrilled-royal-depravity-frustrate-starting * tele-factoid-shorten-koala-explore-retinal-lazy-coauthor-brethren * tele-thinness-suspect-shrink-dwindle-awning-engulf-thrift-spoiling ``` The user interface should present an option to download and print the tokens on the same screen to make it more convenient for a user to print the tokens. Teleport cloud scanners can look for `tele-` prefix and alert customers with domain names in the prefix about leaked tokens. * [ ] All 3 tokens are regenerated in batch every time account recovery is successful. * [ ] Each token can only be used one time successfully or unsuccessfully. * [ ] Teleport should store tokens hashed with `crypto/bcrypt` and compare using constant-time compare. Teleport should store the time when the tokens were generated alongside the hashed tokens. * [ ] Trying a wrong token 3 times in a row should lead to a temporary account lock following the same failed account login rate-limiting that exists for local users right now. * [ ] The reset endpoints should be rate-limited by account and IP to prevent brute-force scans. * [ ] UI should make it clear that these tokens are important and if lost, the account can not be recovered. * [ ] Set the following headers on the web page presenting the tokens: ``` Set: Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Mon, 01 Jan 1990 00:00:00 GMT ``` * [ ] Account lock should result in email notification to account owners and the user who is locked. A locked user should get an email: ``` An account with email user@example.com has tried to recover the account unsuccessfully and was locked. This account can not be recovered. Please request the system administrator to re-create the account. ``` Account owners should receive the email: ``` An account with email user@example.com has tried to recover the account unsuccessfully and was locked. This account can not be recovered. Verify that the user initiated the account recovery, delete the account and invite the user again. ``` ### Recovery scenarios The first two recovery scenarios work for every system user, reducing the load on Teleport system administrators as well. **Emails and usernames** Teleport Cloud assumes that username is a user email. When sending emails, Teleport cloud will send an email to the username if it contains @ sign. Self hosted Teleport will not send any emails. **Account owners** Account owner is any user who can request access to account editor role and review such requests. Review [Access requests with dual authorization](https://goteleport.com/docs/access-controls/guides/dual-authz/) for more details on access requests to understand this RFD better. Teleport will create `account-owner` and `account-editor` role presets. A sample `account-owner` role preset: ```yaml allow: request: roles: ['account-editor'] review_requests: roles: ['account-editor'] ``` Teleport's access requests by do not allow any user to review their own requests, so the role above is secure. Sample `account-editor` role preset: ```yaml allow: rules: - resources: ['account'] verbs: ['update', 'delete'] ``` We will recommend to have several account owners, users who do not have system administration privileges and can't modify roles, or users. Any other users are referred to as simply users. **Locksmiths** Locksmith is any user who can request access to lock-editor role and review such requests. This feature relies on not-implemented yet [session and user locks](https://github.com/gravitational/teleport/issues/3360). We will assume that `lock` is a new resource that can place a lock on account or a set of users. Teleport cloud will create a `locksmith` and and `lock-editor` role presets. A sample `locksmith` role: ```yaml allow: request: roles: ['lock-editor'] review_requests: roles: ['lock-editor'] ``` Teleport's access requests by do not allow any user to review their own requests, so the role above is secure. Sample `lock-editor` role: ```yaml allow: rules: - resources: ['lock'] verbs: ['create', 'list', 'read', 'update', 'delete'] ``` We will recommend to have several `locksmiths`, users who do not have system administration privileges and can't modify roles, or users. Any other users are referred to as simply users. **User lost a second factor** If any user lost a second factor, but not password, they can add a new second factor using a recovery token. * Request second factor recovery on the login form. * Teleport Cloud generates a recovery link and emails this link to the user's email. ``` This is Teleport cloud account recovery link initiated from and . If this activity was not imitated by you, please contact your system administrator. Otherwise, follow the to proceed with account recovery. ``` * The link uses a crypto-random 32 byte hex that activates account recovery flow. * User has to login with a username and password. * Instead of pressing second factor, enter a one-time recovery token. * Enroll new second factor. * All recovery tokens are no longer valid. The new set of recovery tokens are printed to the user. * User has to confirm that they have copied recovery tokens. * The session is not initiated. A user is redirected to a login form with UI displaying a message to login using new credentials. * If the operation is aborted after user enters the token, but fails to complete recovery, the used token is no longer valid, but remaining tokens can be used. * If a user tries to reuse the token, it is rejected. * All second factors set up prior to the reset are removed from the system. This flow ensures two factors are verified: the valid password and a recovery token. Teleport cloud sends a recovery link to an email address to protect from a physical compromise - someone stealing the laptop and the printed tokens. Recovery triggers an email notification to a user: ``` Your Teleport Cloud account has been successfully recovered on from and . If this activity was not imitated by you, please contact your system administrator. Otherwise, no further action is necessary. ``` Account owners should get an email: ``` Teleport Cloud account for user@example has been successfully recovered on from and . No further action is necessary. ``` **User lost a password** If user lost a password, but not a second factor, they could recover using a second factor and a recovery token to reset it: * Request second factor recovery on the login form. * Teleport Cloud generates a recovery link and emails this link to the user's email. * The link uses a crypto-random 32 byte hex that activates account recovery flow. * User enters their username and clicks forgot password. * User has to present a valid second factor and a recovery token, after that they will be able to reset their password. * All recovery tokens are no longer valid. The new set of recovery tokens are printed to the user. * User has to confirm that they have copied recovery tokens. * The session is not initiated. A user is redirected to a login form with UI displaying a message to login using new credentials. This flow ensure that two factors are verified: * Second factor TOTP token or U2F device. * A valid account recovery token. * Email step protects from a physical compromise and bad actor stealing the recovery tokens and a computer. Recovery triggers an email notification to a user: ``` Your Teleport Cloud account has been successfully recovered on from and . If this activity was not imitated by you, please contact your system administrator. Otherwise, no further action is necessary. ``` Account owners should get an email: ``` Teleport Cloud account for user@example has been successfully recovered on from and . No further action is necessary. ``` **Authorizing privileged operations** To confirm some privileged operations like account cancellation or recovery tokens regeneration Teleport has to confirm that user is near their computer and actively authorizes the action. If a user has logged in the last 5 minutes, Teleport asks for any valid second factor token authorization. If the login hasn't been done in the last 5 mins, Teleport asks Alice to re-login completely - by asking for password and second factor. This is done to step up the verification on a period of inactivity before executing privileged operation. We will refer to this flow as *Authorizing privileged operations* flow. **User has lost recovery tokens** If any user is logged into Teleport UI, they can regenerate new password recovery tokens: * Alice goes to her account settings and chooses to generate a new set of recovery tokens. * Teleport asks for a second factor using *Authorizing privileged operations flow* before generating tokens and makes it clear that once selected, old sets of tokens will not be valid, they will be printed once and Alice should be prepared to store them in offline place. * A new set of tokens is printed for Alice. The message makes it clear that once closed, the tokens are no longer going to be revealed and that any previous tokens are invalid. **Internal request for canceling the account** Let's say Bob would like to cancel the account. Bob should first * Have a role that allows to request `account: delete` permission. * Log into Teleport UI. * Navigate to account details page and request account cancellation. * Teleport asks Bob prove the ownership of a valid second factor using *Authorizing privileged operations* flow. * All users who have `locksmith` role except Bob, who initiated the lock request receive an email or chat bot notification: ``` User has initiated account cancellation on