TOTP MFA Code AWS: Authentication Code for Device is not Valid
Symptom
After on-boarding AWS root account along with MFA on to CyberArk.
Having followed the documentation you are able to generate MFA code using CyberArk, but when activating MFA in AWS by providing MFA code 1 and MFA code 2, you get an error in AWS console (Authentication code for device is not valid).
In the Dispatcher error logs for the relevant session you may see the following relevant data;
[02/02/2023 | 16:15:44] | :: | PSMDU001I PSM Dispatcher Utils exception occurred. PSMDU032E Session property [LogonAccount_WebApplicationID] is not present (Codes: -1, -1)
[02/02/2023 | 16:15:44] | :: | PSMDU014E Error performing dispatcher's request [GetSessionPropertyBufferLength]. Reason: PSMDU032E Session property [LogonAccount_WebApplicationID] is not present
Environment
11;12.0;12.1;12.2;12.4;12.3;12.5;12.6;12.7;13.0;14.6 Privileged Access Manager (PAM, self-hosted) PSM
PSM 12.2
Cause
By default, the TOTP Token Connection Component is designed to be associated with Target Account platforms.
Accounts on those platforms have MFA secrets as Logon Accounts, and the TOTP Token connection component reads the MFA secret from that account.
Resolution
To associate the TOTP Token Connection Component directly with an MFA Device platform, override the UseLogonAccountToProduceToken client-specific target setting on the TOTP Token component and set it to No.
# PVWA > Administration > Configuration Options > Options > Connection Components > PSM-TOPT > Target Settings > Client Specific > UseLogonAccountToProduceToken > Value: No
# Save the config.
# Further Explanation:
The "UseLogonAccountToProduceToken" connection component parameter is intended for just this use case, and set it to 'No' so that it uses the target account secret for generating the TOTP token rather than the linked logon account (if you have used a Linked logon account).
The prevalent use case is for the connection component to be launched via the 'Connect' button on the account that is being used to initialize a session (which is why UseLogonAccountToProduceToken is set to 'Yes' by default).