Home > OS >  Is there any way to check the value of aws:MultiFactorAuthPresent
Is there any way to check the value of aws:MultiFactorAuthPresent

Time:02-19

I have a policy that denies operations except if aws global context key aws:MultiFactorAuthPresent is true. Meaning that the operation requires that you are authenticated via MFA.

The policy is working ok, and I can see that when I use my aws profile without mfa the operations are denied and when I use the profile with MFA they work.

Now, is there any command / api operation that tells me if my credentials used MFA (aws:MultiFactorAuthPresent)?

I need it for troubleshooting purpose mainly when other people complain that they are getting Operation Denied? Something like aws sts get-caller-identity but that also print out if the credentials used an MFA code.

CodePudding user response:

If I understand correctly, you would want to check if certain users did authenticate themselves with MFA before doing some operations in your account.

I'm not aware of any kind of CLI command for this. What would be helpful for you is to take a look a the CloudTrail Event History. This should log all the operations done by other users. If you download this list of events as a JSON, you should be able find a section with sessionContext for every event.

"sessionContext": {
    "sessionIssuer": {
        "type": "Role",
        "principalId": "...",
        "arn": "...",
        "accountId": "...",
        "userName": "..."
    },
    "webIdFederationData": {},
    "attributes": {
        "creationDate": "2022-02-18T14:08:57Z",
        "mfaAuthenticated": "false"
    }
}

We can notice that every it is logged that session used by the user/role is MFA authenticated or not.

If you are willing to search for operations done by certain users, you should be able to detect if they were using MFA or not. Just as warning, this JSON file can be huge and could be really painful to go through it.

CodePudding user response:

If you simply want to make sure that users are using MFA when working with AWS CLI you can also enforce MFA usage with aws sts get-session-token (see also https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sts/get-session-token.html). Therefore users start creating a temporary session with explicit MFA usage (see parameter --serial-numer and --token-code). All commands execute with these temporary session credentials are MFA enforced.

  • Related