|
| 1 | +# Configuring MFTF for Two-Factor Authentication (2FA) |
| 2 | + |
| 3 | +Using two-factor authentication (2FA) with MFTF is possible with some configurations settings in Magento. |
| 4 | +In this document, we will use Google as the authentication provider. |
| 5 | + |
| 6 | +## Configure Magento {#config-magento-2fa} |
| 7 | + |
| 8 | +To prepare Magento for MFTF testing when 2FA is enabled, set the following configurations through the Magento CLI. |
| 9 | + |
| 10 | +First, select `Google Authenticator` as Magento's 2FA provider: |
| 11 | + |
| 12 | +```bash |
| 13 | +bin/magento config:set twofactorauth/general/force_providers google |
| 14 | +``` |
| 15 | + |
| 16 | +Now set the OTP window to `60` seconds: |
| 17 | + |
| 18 | +```bash |
| 19 | +bin/magento config:set twofactorauth/google/otp_window 60 |
| 20 | +``` |
| 21 | + |
| 22 | +Set a base32-encoded `secret` for `Google Authenticator` to generate a OTP for the default admin user that you set for `MAGENTO_ADMIN_USERNAME` in `.env`: |
| 23 | + |
| 24 | +```bash |
| 25 | +bin/magento security:tfa:google:set-secret <MAGENTO_ADMIN_USERNAME> <OTP_SHARED_SECRET> |
| 26 | +``` |
| 27 | + |
| 28 | +## Configure the MFTF {#config-mftf-2fa} |
| 29 | + |
| 30 | +Save the same base32-encoded `secret` in a MFTF credential storage, e.g. `.credentials` file, `HashiCorp Vault` or `AWS Secrets Manager`. |
| 31 | +More details are [here](./credentials.md). |
| 32 | + |
| 33 | +The path of the `secret` should be: |
| 34 | + |
| 35 | +```conf |
| 36 | +magento/tfa/OTP_SHARED_SECRET |
| 37 | +``` |
| 38 | + |
| 39 | +## GetOTP {#getOTP} |
| 40 | + |
| 41 | +A one-time password (OTP) is required when an admin user logs into the Magento admin. |
| 42 | +Use the action `getOTP` [Reference](./test/actions.md#getotp) to generate the code and use it for the `Authenticator code` text field in 2FA - Google Auth page. |
| 43 | + |
| 44 | +Note: |
| 45 | +You will need to set the `secret` for any non-default admin users first, before using `getOTP`. For example: |
| 46 | + |
| 47 | +```xml |
| 48 | +<magentoCLI command="security:tfa:google:set-secret admin2 {{_CREDS.magento/tfa/OTP_SHARED_SECRET}}" stepKey="setSecret"/> |
| 49 | +``` |
0 commit comments