Skip to content

Commit

Permalink
Merge pull request KelvinTegelaar#560 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
Dev to hotfix
  • Loading branch information
KelvinTegelaar authored Jan 8, 2024
2 parents e65d369 + 5295bc8 commit e0dc369
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ function Push-CIPPAlertAppSecretExpiry {
)
$LastRunTable = Get-CIPPTable -Table AlertLastRun


Write-Host "Checking app expire for $($QueueItem.tenant)"
try {
$Filter = "RowKey eq 'AppSecretExpiry' and PartitionKey eq '{0}'" -f $QueueItem.tenantid
$LastRun = Get-CIPPAzDataTableEntity @LastRunTable -Filter $Filter
$Yesterday = (Get-Date).AddDays(-1)
if (-not $LastRun.Timestamp.DateTime -or ($LastRun.Timestamp.DateTime -le $Yesterday)) {
New-GraphGetRequest -uri "https://graph.microsoft.com/beta/applications?`$select=appId,displayName,passwordCredentials" -tenantid $QueueItem.tenant | ForEach-Object {
foreach ($App in $_) {
Write-Host "checking $($App.displayName)"
if ($App.passwordCredentials) {
foreach ($Credential in $App.passwordCredentials) {
if ($Credential.endDateTime -lt (Get-Date).AddDays(30) -and $Credential.endDateTime -gt (Get-Date).AddDays(-7)) {
("Application '{0}' has secrets expiring on {1}" -f $App.displayName, $Credential.endDateTime)
Write-Host ("Application '{0}' has secrets expiring on {1}" -f $App.displayName, $Credential.endDateTime)
Write-AlertMessage -tenant $($QueueItem.tenant) -message ("Application '{0}' has secrets expiring on {1}" -f $App.displayName, $Credential.endDateTime)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ function Push-CIPPAlertDepTokenExpiry {
)
$LastRunTable = Get-CIPPTable -Table AlertLastRun



try {
$Filter = "RowKey eq 'DepTokenExpiry' and PartitionKey eq '{0}'" -f $QueueItem.tenantid
$LastRun = Get-CIPPAzDataTableEntity @LastRunTable -Filter $Filter
Expand Down
55 changes: 33 additions & 22 deletions Modules/CIPPCore/Public/Entrypoints/Push-CIPPAlertMFAAdmins.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,45 @@ function Push-CIPPAlertMFAAdmins {
$TriggerMetadata
)
try {
$StrongMFAMethods = '#microsoft.graph.fido2AuthenticationMethod', '#microsoft.graph.phoneAuthenticationMethod', '#microsoft.graph.passwordlessmicrosoftauthenticatorauthenticationmethod', '#microsoft.graph.softwareOathAuthenticationMethod', '#microsoft.graph.microsoftAuthenticatorAuthenticationMethod'
$AdminList = (New-GraphGETRequest -uri "https://graph.microsoft.com/beta/directoryRoles?`$expand=members" -tenantid $($QueueItem.tenant) | Where-Object -Property roleTemplateId -NE 'd29b2b05-8046-44ba-8758-1e26182fcf32').members | Where-Object { $_.userPrincipalName -ne $null -and $_.Usertype -eq 'Member' -and $_.accountEnabled -eq $true } | Sort-Object UserPrincipalName -Unique
$CAPolicies = (New-GraphGetRequest -Uri 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies' -tenantid $QueueItem.tenant -ErrorAction Stop)
foreach ($Policy in $CAPolicies) {
if ($policy.grantControls.customAuthenticationFactors -eq 'RequireDuoMfa') {
$DuoActive = $true
}
}
if (!$DuoActive) {
$AdminList | ForEach-Object {
$CARegistered = $null
try {
New-GraphGETRequest -uri "https://graph.microsoft.com/beta/users/$($_.ID)/authentication/Methods" -tenantid $($QueueItem.tenant) | ForEach-Object {
if ($_.'@odata.type' -in $StrongMFAMethods) {
$CARegistered = $true
$LastRunTable = Get-CIPPTable -Table AlertLastRun
$Filter = "RowKey eq 'MFAAllAdmins' and PartitionKey eq '{0}'" -f $QueueItem.tenantid
$LastRun = Get-CIPPAzDataTableEntity @LastRunTable -Filter $Filter
$Yesterday = (Get-Date).AddDays(-1)
if (-not $LastRun.Timestamp.DateTime -or ($LastRun.Timestamp.DateTime -le $Yesterday)) {
$StrongMFAMethods = '#microsoft.graph.fido2AuthenticationMethod', '#microsoft.graph.phoneAuthenticationMethod', '#microsoft.graph.passwordlessmicrosoftauthenticatorauthenticationmethod', '#microsoft.graph.softwareOathAuthenticationMethod', '#microsoft.graph.microsoftAuthenticatorAuthenticationMethod'
$AdminList = (New-GraphGETRequest -uri "https://graph.microsoft.com/beta/directoryRoles?`$expand=members" -tenantid $($QueueItem.tenant) | Where-Object -Property roleTemplateId -NE 'd29b2b05-8046-44ba-8758-1e26182fcf32').members | Where-Object { $_.userPrincipalName -ne $null -and $_.Usertype -eq 'Member' -and $_.accountEnabled -eq $true } | Sort-Object UserPrincipalName -Unique
$CAPolicies = (New-GraphGetRequest -Uri 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies' -tenantid $QueueItem.tenant -ErrorAction Stop)
foreach ($Policy in $CAPolicies) {
if ($policy.grantControls.customAuthenticationFactors -eq 'RequireDuoMfa') {
$DuoActive = $true
}
}
if (!$DuoActive) {
$AdminList | ForEach-Object {
$CARegistered = $null
try {
New-GraphGETRequest -uri "https://graph.microsoft.com/beta/users/$($_.ID)/authentication/Methods" -tenantid $($QueueItem.tenant) | ForEach-Object {
if ($_.'@odata.type' -in $StrongMFAMethods) {
$CARegistered = $true
}
}
if ($CARegistered -ne $true) {
Write-AlertMessage -tenant $($QueueItem.tenant) -message "Admin $($_.UserPrincipalName) is enabled but does not have any form of MFA configured."
}
} catch {
# Error handling here if needed
}
if ($CARegistered -ne $true) {
Write-AlertMessage -tenant $($QueueItem.tenant) -message "Admin $($_.UserPrincipalName) is enabled but does not have any form of MFA configured."
}
} catch {
# Error handling here if needed
}
} else {
Write-LogMessage -message 'Potentially using Duo for MFA, could not check MFA status for Admins with 100% accuracy' -API 'MFA Alerts - Informational' -tenant $QueueItem.tenant -sev Info
}
} else {
Write-LogMessage -message 'Potentially using Duo for MFA, could not check MFA status for Admins with 100% accuracy' -API 'MFA Alerts - Informational' -tenant $QueueItem.tenant -sev Info
}
} catch {
Write-AlertMessage -tenant $($QueueItem.tenant) -message "Could not get MFA status for admins for $($QueueItem.tenant): $(Get-NormalizedError -message $_.Exception.message)"
}
$LastRun = @{
RowKey = 'MFAAllAdmins'
PartitionKey = $QueueItem.tenantid
}
Add-CIPPAzDataTableEntity @LastRunTable -Entity $LastRun -Force
}
80 changes: 47 additions & 33 deletions Modules/CIPPCore/Public/Entrypoints/Push-CIPPAlertMFAAlertUsers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,60 @@ function Push-CIPPAlertMFAAlertUsers {
$TriggerMetadata
)
try {
$users = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/users?`$select=userPrincipalName,id,accountEnabled,userType&`$filter=userType eq 'Member' and accountEnabled eq true" -tenantid $($QueueItem.tenant)
Write-Host "found $($users.count) users"
$StrongMFAMethods = '#microsoft.graph.fido2AuthenticationMethod', '#microsoft.graph.phoneAuthenticationMethod', '#microsoft.graph.passwordlessmicrosoftauthenticatorauthenticationmethod', '#microsoft.graph.softwareOathAuthenticationMethod', '#microsoft.graph.microsoftAuthenticatorAuthenticationMethod'
$LastRunTable = Get-CIPPTable -Table AlertLastRun
$Filter = "RowKey eq 'MFAAllUsers' and PartitionKey eq '{0}'" -f $QueueItem.tenantid
$LastRun = Get-CIPPAzDataTableEntity @LastRunTable -Filter $Filter
$Yesterday = (Get-Date).AddDays(-1)
if (-not $LastRun.Timestamp.DateTime -or ($LastRun.Timestamp.DateTime -le $Yesterday)) {
$users = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/users?`$select=userPrincipalName,id,accountEnabled,userType&`$filter=userType eq 'Member' and accountEnabled eq true" -tenantid $($QueueItem.tenant)
Write-Host "found $($users.count) users for $($QueueItem.tenant)"
$StrongMFAMethods = '#microsoft.graph.fido2AuthenticationMethod', '#microsoft.graph.phoneAuthenticationMethod', '#microsoft.graph.passwordlessmicrosoftauthenticatorauthenticationmethod', '#microsoft.graph.softwareOathAuthenticationMethod', '#microsoft.graph.microsoftAuthenticatorAuthenticationMethod'

$UserBatches = [System.Collections.Generic.List[Object]]@()
for ($i = 0; $i -lt $users.count; $i += 20) {
$UserBatches.Add($users[$i..($i + 19)])
}

$UserBatches | ForEach-Object -Parallel {
Import-Module CippCore
Import-Module AzBobbyTables
$UserBatch = $_
Write-Host "processing batch of $($UserBatch.count) users"
$BatchRequests = $UserBatch | ForEach-Object {
@{
id = $_.id
method = 'GET'
url = "users/$($_.ID)/authentication/Methods"
}
$UserBatches = [System.Collections.Generic.List[Object]]@()
for ($i = 0; $i -lt $users.count; $i += 20) {
$UserBatches.Add($users[$i..($i + 19)])
}
$BatchResponses = New-GraphBulkRequest -tenantid $using:QueueItem.tenant -Requests $BatchRequests
foreach ($response in $BatchResponses) {
$UPN = ($UserBatch | Where-Object { $_.id -eq $response.id }).UserPrincipalName
$CARegistered = $false

foreach ($method in $response.body.value) {
if ($method.'@odata.type' -in $using:StrongMFAMethods) {
$CARegistered = $true
break
$UserBatches | ForEach-Object -Parallel {
try {
Write-Host "processing batch of $($_.count) users for $($using:QueueItem.tenant)"
Import-Module CippCore
Import-Module AzBobbyTables
$UserBatch = $_
Write-Host "processing batch of $($UserBatch.count) users"
$BatchRequests = $UserBatch | ForEach-Object {
@{
id = $_.id
method = 'GET'
url = "users/$($_.ID)/authentication/Methods"
}
}
}
$BatchResponses = New-GraphBulkRequest -tenantid $using:QueueItem.tenant -Requests $BatchRequests
foreach ($response in $BatchResponses) {
$UPN = ($UserBatch | Where-Object { $_.id -eq $response.id }).UserPrincipalName
$CARegistered = $false

if (-not $CARegistered) {
Write-AlertMessage -tenant $using:QueueItem.tenant -message "User $UPN is enabled but does not have any form of MFA configured."
}
}
} -ThrottleLimit 25
foreach ($method in $response.body.value) {
if ($method.'@odata.type' -in $using:StrongMFAMethods) {
$CARegistered = $true
break
}
}

if (-not $CARegistered) {
Write-AlertMessage -tenant $using:QueueItem.tenant -message "User $UPN is enabled but does not have any form of MFA configured."
}
}
} catch {
}
} -ThrottleLimit 25
}
} catch {
Write-AlertMessage -tenant $($QueueItem.tenant) -message "Could not get MFA status for users for $($QueueItem.tenant): $(Get-NormalizedError -message $_.Exception.message)"
}
$LastRun = @{
RowKey = 'MFAAllUsers'
PartitionKey = $QueueItem.tenantid
}
Add-CIPPAzDataTableEntity @LastRunTable -Entity $LastRun -Force
}
6 changes: 3 additions & 3 deletions Modules/CIPPCore/Public/Set-CIPPAuthenticationPolicy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function Set-CIPPAuthenticationPolicy {
'softwareOath' {
# Nothing special to do here
}

# Voice call
'Voice' {
# Disallow enabling voice
Expand All @@ -103,8 +103,8 @@ function Set-CIPPAuthenticationPolicy {
# Nothing special to do here
}
Default {
Write-LogMessage -user $ExecutingUser -API $APIName -tenant $Tenant -message 'Somehow you hit the default case. You probably made a typo in the input for AuthenticationMethodId. It''s case sensitive' -sev Error
return 'Somehow you hit the default case. You probably made a typo in the input for AuthenticationMethodId. It''s case sensitive.'
Write-LogMessage -user $ExecutingUser -API $APIName -tenant $Tenant -message "Somehow you hit the default case with an input of $AuthenticationMethodId . You probably made a typo in the input for AuthenticationMethodId. It`'s case sensitive." -sev Error
return "Somehow you hit the default case with an input of $AuthenticationMethodId . You probably made a typo in the input for AuthenticationMethodId. It`'s case sensitive."
}
}
# Set state of the authentication method
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function Invoke-CIPPStandardDisableExternalCalendarSharing {
<#
.FUNCTIONALITY
Internal
#>
param($Tenant, $Settings)

if ($Settings.remediate) {
New-ExoRequest -tenantid $Tenant -cmdlet 'Get-SharingPolicy' | Where-Object { $_.Default -eq $true } | ForEach-Object {
New-ExoRequest -tenantid $Tenant -cmdlet 'Set-SharingPolicy' -cmdParams @{ Identity = $_.Id ; Enabled = $false } -UseSystemMailbox $true
}
}

# This is ugly but done to avoid a second call to the Graph API
if ($Settings.alert -or $Settings.report) {
$CurrentInfo = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-SharingPolicy' | Where-Object { $_.Default -eq $true }

if ($Settings.alert) {
if ($CurrentInfo.Enabled) {
Write-LogMessage -API 'Standards' -tenant $tenant -message 'External calendar sharing is enabled' -sev Alert
} else {
Write-LogMessage -API 'Standards' -tenant $tenant -message 'External calendar sharing is not enabled' -sev Info
}
}
if ($Settings.report) {
Add-CIPPBPAField -FieldName 'ExternalCalendarSharingDisabled' -FieldValue [bool]$CurrentInfo.Enabled -StoreAs bool -Tenant $tenant
}
}


}
2 changes: 1 addition & 1 deletion Scheduler_Alert/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ try {
$CurrentAlerts = (Get-CIPPAzDataTableEntity @AlertsTable -Filter $Filter)
$CurrentAlerts | ForEach-Object {
if ($_.Message -notin $currentlog.Message) { Write-LogMessage -message $_.Message -API 'Alerts' -tenant $tenant.tenant -sev Alert -tenantid $Tenant.tenantid }
Remove-AzDataTableEntity @AlertsTable -Entity $_
Remove-AzDataTableEntity @AlertsTable -Entity $_ | Out-Null
}

[PSCustomObject]@{
Expand Down
2 changes: 1 addition & 1 deletion version_latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.9.1
4.9.3

0 comments on commit e0dc369

Please sign in to comment.