Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Fix] GR1 & Gr3 - list the UPNs having non-enabled MFA #89

Closed
wants to merge 4 commits into from

Conversation

dutt0
Copy link
Contributor

@dutt0 dutt0 commented Jan 31, 2024

Overview/Summary

This pull request fixes the reporting bug in 163gccspm for GR1 & Gr3 GA MFA UPN list feature.

This PR fixes/adds/changes/removes

In total, there should be 4 types of authentication methods to consider:

  1. #microsoft.graph.microsoftAuthenticatorAuthenticationMethod
  2. #microsoft.graph.phoneAuthenticationMethod
  3. #microsoft.graph.passwordAuthenticationMethod
  4. #microsoft.graph.emailAuthenticationMethod

This PR has the fix for the MFA authentication by including two more authentication methods that users may have. Since dev tenant users did not have password and email authentication methods, this issue was not prominent in that tenant. However, the users in Test tenant carries these MFA. This pull request has the fix for this use case.

Testing Evidence

image

As part of this Pull Request I have

  • Checked for duplicate Pull Requests
  • Associated it with relevant GitHub Issues
  • Ensured my code/branch is up-to-date with the latest changes in the main branch
  • Performed testing and provided evidence.
  • Updated relevant and associated documentation.
  • Ensure PowerShell module versions have been updated (manually or with the ./tools/Update-ModuleVersions.ps1 script)

@dutt0 dutt0 linked an issue Jan 31, 2024 that may be closed by this pull request
Copy link
Contributor

@alalvi00 alalvi00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The methods that you are checking for in your new code

#microsoft.graph.passwordAuthenticationMethod - This is users password and doesnt qualify as a second auth method for MFA
#microsoft.graph.emailAuthenticationMethod - This is users email used to reset user password and doesnt qualify as second auth method for MFA

The two methods above should not be checked for MFA as they don't represent the multi-factor that we are looking for hence why the old code didn't include them. We should check for authenticator app or phone authentication since theyre used as second auth method

If we use the new logic in the pr, then any user without authenticator app and phone number will be able to pass the compliancy test if they have a password and email used to reset

@dutt0
Copy link
Contributor Author

dutt0 commented Jan 31, 2024

@alalvi00 As you mentioned yesterday, you have #microsoft.graph.passwordAuthenticationMethod and #microsoft.graph.AuthenticatorAuthenticationMethod and both are enabled for MFA. This logic goes by that perspective.

@alalvi00
Copy link
Contributor

@alalvi00 As you mentioned yesterday, you have #microsoft.graph.passwordAuthenticationMethod and #microsoft.graph.AuthenticatorAuthenticationMethod and both are enabled for MFA. This logic goes by that perspective.

Thats fine but a user will also pass if they only have password and email and I have tested this in the test tenant

@dutt0
Copy link
Contributor Author

dutt0 commented Jan 31, 2024

⁠Just for the reference in localexecution this is what I see for $comments and the ComplianceStatus is also false. Thanks for your testing and giving reviews. I will discuss the logic in tomorrow's meeting and thereafter finalize the PR

Testcase 1 :
-<testuser's upn>@xxxxxxxxx.onmicrosoft.com
-< ila's upn>@xxxxxxxxx.onmicrosoft.com

Testcase 2 :
-<testuser's upn>@xxxxxxxxx.onmicrosoft.com
-<Ali's upn>@xxxxxxxxx.onmicrosoft.com

image

$GAUPNsMFA += $GAUPNtemplate
}
}
# Condition: when user's authentication methods > 1
Copy link
Contributor

@singhgss singhgss Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dutt0

We can make this code a little bit cleaner

$targetAuthMethodTypes = @(
    "#microsoft.graph.phoneAuthenticationMethod",
    "#microsoft.graph.microsoftAuthenticatorAuthenticationMethod",
    "#microsoft.graph.passwordAuthenticationMethod",
    "#microsoft.graph.emailAuthenticationMethod"
)

$GAUPNtemplate = [PSCustomObject]@{
    UPN        = $globalAdminAccount
    MFAStatus  = $false
    MFAComments = $hiddenUPN
}

foreach ($authmeth in $authenticationmethods) {
    if ($targetAuthMethodTypes -contains $($authmeth.'@odata.type')) {
        $mfaCounter += 1
        break
    } else {
        # Clone the template and add to the list
        $GAUPNsMFA += $GAUPNtemplate.psobject.Copy()
    }
}

I think this introduces a bug what happens if first authMeth that comes in the loop iteration is none of the 4 auth methods, wouldn't this go to else block and create a GAUPNTemplate list and then in the next iteration it finds the one of the 4 auth methods and it also increases mfacounter

So we end up posting message of mfa not enabled as well as showing message that it is enabled for that UPN

@dutt0 dutt0 closed this Jan 31, 2024
@dutt0
Copy link
Contributor Author

dutt0 commented Jan 31, 2024

Thanks for your reviews @alalvi00 @singhgss. I am refactoring this function. Cancelling this PR. I will raise another PR later

@dutt0 dutt0 deleted the idutta/GR1_GR3_fix_list_upn_wo_mfa branch February 1, 2024 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants