Skip to content

Commit

Permalink
Merge pull request #3290 from NikCharlebois/AADConditionalAccessPolic…
Browse files Browse the repository at this point in the history
…y-Auth-Strength

AADConditionalAccessPolicy added Auth Strength
  • Loading branch information
NikCharlebois authored May 10, 2023
2 parents f9a9689 + 0777911 commit 3db959f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* AADAuthenticationStrengthPolicy
* Initial release
* AADConditionalAccessPolicy
* Added support for the AuthenticationStrength parameter.
* AADCrossTenantAccessPolicy
* Initial release
FIXES [#3251](https://github.com/microsoft/Microsoft365DSC/issues/3251)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ function Get-TargetResource
[System.String[]]
$CustomAuthenticationFactors,

[Parameter()]
[System.String]
$AuthenticationStrength,

#generic
[Parameter()]
[ValidateSet('Present', 'Absent')]
Expand Down Expand Up @@ -554,6 +558,17 @@ function Get-TargetResource
}
}

$AuthenticationStrengthValue = $null
if ($null -ne $Policy.GrantControls -and $null -ne $Policy.GrantControls.AuthenticationStrength -and `
$null -ne $Policy.GrantControls.AuthenticationStrength.Id)
{
$strengthPolicy = Get-MgPolicyAuthenticationStrengthPolicy -AuthenticationStrengthPolicyId $Policy.GrantControls.AuthenticationStrength.Id
if ($null -ne $strengthPolicy)
{
$AuthenticationStrengthValue = $strengthPolicy.DisplayName
}
}

$result = @{
DisplayName = $Policy.DisplayName
Id = $Policy.Id
Expand Down Expand Up @@ -617,6 +632,7 @@ function Get-TargetResource
#make false if undefined, true if true
PersistentBrowserMode = [System.String]$Policy.SessionControls.PersistentBrowser.Mode
#no translation needed
AuthenticationStrength = $AuthenticationStrengthValue
#Standard part
TermsOfUse = $termOfUseName
Ensure = 'Present'
Expand Down Expand Up @@ -809,6 +825,10 @@ function Set-TargetResource
[System.String[]]
$CustomAuthenticationFactors,

[Parameter()]
[System.String]
$AuthenticationStrength,

#generic
[Parameter()]
[ValidateSet('Present', 'Absent')]
Expand Down Expand Up @@ -1331,7 +1351,7 @@ function Set-TargetResource
#create and provision Grant Control object
Write-Verbose -Message 'Set-Targetresource: create and provision Grant Control object'

if ($GrantControlOperator -and ($BuiltInControls -or $TermsOfUse -or $CustomAuthenticationFactors))
if ($GrantControlOperator -and ($BuiltInControls -or $TermsOfUse -or $CustomAuthenticationFactors -or $AuthenticationStrength))
{
$GrantControls = @{
Operator = $GrantControlOperator
Expand All @@ -1345,6 +1365,18 @@ function Set-TargetResource
{
$GrantControls.Add('customAuthenticationFactors', $CustomAuthenticationFactors)
}
if ($AuthenticationStrength)
{
$strengthPolicy = Get-MgPolicyAuthenticationStrengthPolicy | Where-Object -FilterScript {$_.DisplayName -eq $AuthenticationStrength} -ErrorAction SilentlyContinue
if ($null -ne $strengthPolicy)
{
$authenticationStrengthInstance = @{
id = $strengthPolicy.Id
"@odata.type" = "#microsoft.graph.authenticationStrengthPolicy"
}
$GrantControls.Add('authenticationStrength', $authenticationStrengthInstance)
}
}

if ($TermsOfUse)
{
Expand Down Expand Up @@ -1656,6 +1688,10 @@ function Test-TargetResource
[System.String[]]
$CustomAuthenticationFactors,

[Parameter()]
[System.String]
$AuthenticationStrength,

#generic
[Parameter()]
[ValidateSet('Present', 'Absent')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MSFT_AADConditionalAccessPolicy : OMI_BaseResource
[Write, Description("Specifies, whether sign-in frequency is enforced by the Policy.")] Boolean SignInFrequencyIsEnabled;
[Write, Description("Specifies, whether Browser Persistence is controlled by the Policy.")] Boolean PersistentBrowserIsEnabled;
[Write, Description("Specifies, what Browser Persistence control is enforced by the Policy."), ValueMap{"Always","Never",""}, Values{"Always","Never",""}] String PersistentBrowserMode;
[Write, Description("Name of the associated authentication strength policy.")] String AuthenticationStrength;
[Write, Description("Specify if the Azure AD CA Policy should exist or not."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Write, Description("Credentials for the Microsoft Graph delegated permissions."), EmbeddedInstance("MSFT_Credential")] string Credential;
[Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Context -Name "When Conditional Access Policy doesn't exist but should" -Fixture {
BeforeAll {
$testParams = @{
AuthenticationStrength = "Phishing-resistant MFA"
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
ClientAppTypes = @('Browser', 'MobileAppsAndDesktopClients')
CloudAppSecurityIsEnabled = $True
Expand Down Expand Up @@ -138,6 +139,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
BeforeAll {
$testParams = @{
ApplicationEnforcedRestrictionsIsEnabled = $True
AuthenticationStrength = "Phishing-resistant MFA"
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
ClientAppTypes = @('Browser', 'MobileAppsAndDesktopClients')
CloudAppSecurityIsEnabled = $True
Expand Down Expand Up @@ -178,6 +180,13 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
DeviceFilterRule = 'device.isCompliant -eq True -or device.trustType -eq "ServerAD"'
}

Mock -CommandName Get-MgPolicyAuthenticationStrengthPolicy -MockWith {
return @{
Id = "00000000-0000-0000-0000-000000000004"
DisplayName = "Phishing-resistant MFA"
}
}

Mock -CommandName Get-MgIdentityConditionalAccessPolicy -MockWith {
return @{
Id = 'bcc0cf19-ee89-46f0-8e12-4b89123ee6f9'
Expand Down Expand Up @@ -216,6 +225,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
GrantControls = @{
_Operator = 'AND'
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
AuthenticationStrength = @{
Id = "00000000-0000-0000-0000-000000000004"
}
}
SessionControls = @{
ApplicationEnforcedRestrictions = @{
Expand Down Expand Up @@ -281,6 +293,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
BeforeAll {
$testParams = @{
ApplicationEnforcedRestrictionsIsEnabled = $True
AuthenticationStrength = "Phishing-resistant MFA"
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
ClientAppTypes = @('Browser', 'MobileAppsAndDesktopClients')
CloudAppSecurityIsEnabled = $True
Expand Down Expand Up @@ -321,6 +334,13 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
DeviceFilterRule = 'device.isCompliant -eq True -or device.trustType -eq "ServerAD"'
}

Mock -CommandName Get-MgPolicyAuthenticationStrengthPolicy -MockWith {
return @{
Id = "00000000-0000-0000-0000-000000000004"
DisplayName = "Phishing-resistant MFA"
}
}

Mock -CommandName Get-MgIdentityConditionalAccessPolicy -MockWith {
return @{
Id = 'bcc0cf19-ee89-46f0-8e12-4b89123ee6f9'
Expand Down Expand Up @@ -379,8 +399,11 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
UserRiskLevels = @('High')
}
GrantControls = @{
Operator = 'AND'
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
Operator = 'AND'
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
AuthenticationStrength = @{
Id = "00000000-0000-0000-0000-000000000004"
}
}
SessionControls = @{
ApplicationEnforcedRestrictions = @{
Expand Down Expand Up @@ -441,6 +464,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
BeforeAll {
$testParams = @{
ApplicationEnforcedRestrictionsIsEnabled = $True
AuthenticationStrength = "Phishing-resistant MFA"
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
ClientAppTypes = @('Browser', 'MobileAppsAndDesktopClients')
CloudAppSecurityIsEnabled = $True
Expand Down Expand Up @@ -475,6 +499,13 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
DeviceFilterRule = 'device.isCompliant -eq True -or device.trustType -eq "ServerAD"'
}

Mock -CommandName Get-MgPolicyAuthenticationStrengthPolicy -MockWith {
return @{
Id = "00000000-0000-0000-0000-000000000004"
DisplayName = "Phishing-resistant MFA"
}
}

Mock -CommandName Get-MgIdentityConditionalAccessPolicy -MockWith {
return @{
Id = 'bcc0cf19-ee89-46f0-8e12-4b89123ee6f9'
Expand Down Expand Up @@ -511,8 +542,11 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
UserRiskLevels = @('High')
}
GrantControls = @{
Operator = 'AND'
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
Operator = 'AND'
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
AuthenticationStrength = @{
Id = "00000000-0000-0000-0000-000000000004"
}
}
SessionControls = @{
ApplicationEnforcedRestrictions = @{
Expand Down Expand Up @@ -582,6 +616,13 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Credential = $Credential
}

Mock -CommandName Get-MgPolicyAuthenticationStrengthPolicy -MockWith {
return @{
Id = "00000000-0000-0000-0000-000000000004"
DisplayName = "Phishing-resistant MFA"
}
}

Mock -CommandName Get-MgIdentityConditionalAccessPolicy -MockWith {
return @{
Id = 'bcc0cf19-ee89-46f0-8e12-4b89123ee6f9'
Expand Down Expand Up @@ -618,8 +659,11 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
UserRiskLevels = @('High')
}
GrantControls = @{
_Operator = 'AND'
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
_Operator = 'AND'
BuiltInControls = @('Mfa', 'CompliantDevice', 'DomainJoinedDevice', 'ApprovedApplication', 'CompliantApplication')
AuthenticationStrength = @{
Id = "00000000-0000-0000-0000-000000000004"
}
}
SessionControls = @{
ApplicationEnforcedRestrictions = @{
Expand Down

0 comments on commit 3db959f

Please sign in to comment.