Skip to content

Commit 671853f

Browse files
Merge pull request KelvinTegelaar#1726 from Zacgoose/fix-audit-log-rules-search
Improve tenant filtering in audit log rules
2 parents e142a97 + 41d606b commit 671853f

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Modules/CIPPCore/Public/Webhooks/Test-CIPPAuditLogRules.ps1

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,25 @@ function Test-CIPPAuditLogRules {
126126
$TrustedIPTable = Get-CIPPTable -TableName 'trustedIps'
127127
$ConfigTable = Get-CIPPTable -TableName 'WebhookRules'
128128
$ConfigEntries = Get-CIPPAzDataTableEntity @ConfigTable
129-
$Configuration = $ConfigEntries | Where-Object { ($_.Tenants -match $TenantFilter -or $_.Tenants -match 'AllTenants') } | ForEach-Object {
130-
[pscustomobject]@{
131-
Tenants = ($_.Tenants | ConvertFrom-Json)
132-
Excluded = ($_.excludedTenants | ConvertFrom-Json -ErrorAction SilentlyContinue)
133-
Conditions = $_.Conditions
134-
Actions = $_.Actions
135-
LogType = $_.Type
129+
$Configuration = foreach ($ConfigEntry in $ConfigEntries) {
130+
if ([string]::IsNullOrEmpty($ConfigEntry.Tenants)) {
131+
continue
132+
}
133+
$Tenants = $ConfigEntry.Tenants | ConvertFrom-Json -ErrorAction SilentlyContinue
134+
if ($null -eq $Tenants) {
135+
continue
136+
}
137+
# Expand tenant groups to get actual tenant list
138+
$ExpandedTenants = Expand-CIPPTenantGroups -TenantFilter $Tenants
139+
# Check if the TenantFilter matches any tenant in the expanded list or AllTenants
140+
if ($ExpandedTenants.value -contains $TenantFilter -or $ExpandedTenants.value -contains 'AllTenants') {
141+
[pscustomobject]@{
142+
Tenants = $Tenants
143+
Excluded = ($ConfigEntry.excludedTenants | ConvertFrom-Json -ErrorAction SilentlyContinue)
144+
Conditions = $ConfigEntry.Conditions
145+
Actions = $ConfigEntry.Actions
146+
LogType = $ConfigEntry.Type
147+
}
136148
}
137149
}
138150

0 commit comments

Comments
 (0)