Skip to content

Commit 4720827

Browse files
authored
Merge pull request #1141 from JohnDuprey/dev
Bugfixes
2 parents c911fe9 + cae37e3 commit 4720827

File tree

8 files changed

+31
-22
lines changed

8 files changed

+31
-22
lines changed

Modules/CIPPCore/Public/Add-CIPPDelegatedPermission.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,31 @@ function Add-CIPPDelegatedPermission {
3434
$RequiredResourceAccess.Add($Resource)
3535
}
3636

37-
if ($Tenantfilter -eq $env:TenantID) {
37+
if ($Tenantfilter -eq $env:TenantID -or $Tenantfilter -eq 'PartnerTenant') {
3838
$RequiredResourceAccess = $RequiredResourceAccess + ($AdditionalPermissions | Where-Object { $RequiredResourceAccess.resourceAppId -notcontains $_.resourceAppId })
3939
} else {
4040
# remove the partner center permission if not pushing to partner tenant
4141
$RequiredResourceAccess = $RequiredResourceAccess | Where-Object { $_.resourceAppId -ne 'fa3d9a0c-3fb0-42cc-9193-47c7ecd2edbd' }
4242
}
4343
}
4444
$Translator = Get-Content '.\PermissionsTranslator.json' | ConvertFrom-Json
45-
$ServicePrincipalList = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$select=AppId,id,displayName&`$top=999" -tenantid $Tenantfilter -skipTokenCache $true -NoAuthCheck $true
45+
$ServicePrincipalList = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$select=appId,id,displayName&`$top=999" -tenantid $Tenantfilter -skipTokenCache $true -NoAuthCheck $true
4646
$ourSVCPrincipal = $ServicePrincipalList | Where-Object -Property appId -EQ $ApplicationId
4747
$Results = [System.Collections.Generic.List[string]]::new()
4848

4949
$CurrentDelegatedScopes = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals/$($ourSVCPrincipal.id)/oauth2PermissionGrants" -skipTokenCache $true -tenantid $Tenantfilter -NoAuthCheck $true
5050

5151
foreach ($App in $RequiredResourceAccess) {
52+
if (!$App) {
53+
continue
54+
}
5255
$svcPrincipalId = $ServicePrincipalList | Where-Object -Property appId -EQ $App.resourceAppId
5356
if (!$svcPrincipalId) {
5457
try {
5558
$Body = @{
5659
appId = $App.resourceAppId
5760
} | ConvertTo-Json -Compress
58-
$svcPrincipalId = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/v1.0/servicePrincipals' -tenantid $Tenantfilter -body $Body -type POST
61+
$svcPrincipalId = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/v1.0/servicePrincipals' -tenantid $Tenantfilter -body $Body -type POST -NoAuthCheck $true
5962
} catch {
6063
$Results.add("Failed to create service principal for $($App.resourceAppId): $(Get-NormalizedError -message $_.Exception.Message)")
6164
continue

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ function Push-DomainAnalyserDomain {
124124
} catch {
125125
$Message = 'SPF Error'
126126
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
127-
return $Message
128127
}
129128

130129
# Check SPF Record
@@ -187,7 +186,7 @@ function Push-DomainAnalyserDomain {
187186
} catch {
188187
$Message = 'DMARC Error'
189188
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
190-
return $Message
189+
#return $Message
191190
}
192191

193192
# DNS Sec Check
@@ -205,7 +204,7 @@ function Push-DomainAnalyserDomain {
205204
} catch {
206205
$Message = 'DNSSEC Error'
207206
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
208-
return $Message
207+
#return $Message
209208
}
210209

211210
# DKIM Check
@@ -240,7 +239,7 @@ function Push-DomainAnalyserDomain {
240239
} catch {
241240
$Message = 'DKIM Exception'
242241
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
243-
return $Message
242+
#return $Message
244243
}
245244

246245
# Get Microsoft DKIM CNAME selector Records
@@ -303,7 +302,6 @@ function Push-DomainAnalyserDomain {
303302
} catch {
304303
$ErrorMessage = Get-CippException -Exception $_
305304
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "MS CNAME DKIM error: $($ErrorMessage.NormalizedError)" -LogData $ErrorMessage -sev Error
306-
return $ErrorMessage.NormalizedError
307305
}
308306
}
309307

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function Push-DomainAnalyserTenant {
2020
return
2121
} else {
2222
try {
23-
$Domains = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/domains' -tenantid $Tenant.customerId | Where-Object { ($_.id -notlike '*.microsoftonline.com' -and $_.id -NotLike '*.exclaimer.cloud' -and $_.id -Notlike '*.excl.cloud' -and $_.id -NotLike '*.codetwo.online' -and $_.id -NotLike '*.call2teams.com' -and $_.isVerified) }
23+
$Domains = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/domains' -tenantid $Tenant.customerId | Where-Object { ($_.id -notlike '*.microsoftonline.com' -and $_.id -NotLike '*.exclaimer.cloud' -and $_.id -Notlike '*.excl.cloud' -and $_.id -NotLike '*.codetwo.online' -and $_.id -NotLike '*.call2teams.com' -and $_.id -notlike '*signature365.net' -and $_.isVerified) }
2424

2525
$TenantDomains = foreach ($d in $Domains) {
2626
[PSCustomObject]@{

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecCPVPermissions.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ Function Invoke-ExecCPVPermissions {
2828
}
2929

3030
$GraphRequest = try {
31-
if ($TenantFilter -ne 'PartnerTenant') {
31+
if ($TenantFilter -notin @('PartnerTenant', $env:TenantId)) {
3232
Set-CIPPCPVConsent @CPVConsentParams
3333
} else {
3434
$TenantFilter = $env:TenantID
35+
$Tenant = [PSCustomObject]@{
36+
displayName = '*Partner Tenant'
37+
defaultDomainName = $env:TenantID
38+
}
3539
}
3640
Add-CIPPApplicationPermission -RequiredResourceAccess 'CIPPDefaults' -ApplicationId $ENV:ApplicationID -tenantfilter $TenantFilter
3741
Add-CIPPDelegatedPermission -RequiredResourceAccess 'CIPPDefaults' -ApplicationId $ENV:ApplicationID -tenantfilter $TenantFilter
38-
Set-CIPPSAMAdminRoles -TenantFilter $TenantFilter
42+
if ($TenantFilter -notin @('PartnerTenant', $env:TenantId)) {
43+
Set-CIPPSAMAdminRoles -TenantFilter $TenantFilter
44+
}
3945
$Success = $true
4046
} catch {
4147
"Failed to update permissions for $($Tenant.displayName): $($_.Exception.Message)"

Modules/CIPPCore/Public/Entrypoints/Invoke-ListMailboxes.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Function Invoke-ListMailboxes {
3838
@{Parameter = 'SoftDeletedMailbox'; Type = 'Bool' }
3939
)
4040

41-
foreach ($Param in $Request.Query.Keys) {
41+
foreach ($Param in $Request.Query.PSObject.Properties.Name) {
4242
$CmdParam = $AllowedParameters | Where-Object { $_.Parameter -eq $Param }
4343
if ($CmdParam) {
4444
switch ($CmdParam.Type) {
@@ -48,7 +48,9 @@ Function Invoke-ListMailboxes {
4848
}
4949
}
5050
'Bool' {
51-
if ([bool]$Request.Query.$Param -eq $true) {
51+
$ParamIsTrue = $false
52+
[bool]::TryParse($Request.Query.$Param, [ref]$ParamIsTrue) | Out-Null
53+
if ($ParamIsTrue -eq $true) {
5254
$ExoRequest.cmdParams.$Param = $true
5355
}
5456
}

Modules/CIPPCore/Public/GraphHelper/Get-AuthorisedRequest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function Get-AuthorisedRequest {
1212
if (!$TenantID) {
1313
$TenantID = $env:TenantID
1414
}
15-
if ($Uri -like 'https://graph.microsoft.com/beta/contracts*' -or $Uri -like '*/customers/*' -or $Uri -eq 'https://graph.microsoft.com/v1.0/me/sendMail' -or $Uri -like '*/tenantRelationships/*') {
15+
if ($Uri -like 'https://graph.microsoft.com/beta/contracts*' -or $Uri -like '*/customers/*' -or $Uri -eq 'https://graph.microsoft.com/v1.0/me/sendMail' -or $Uri -like '*/tenantRelationships/*' -or $Uri -like '*/security/partner/*') {
1616
return $true
1717
}
1818
$Tenants = Get-Tenants -IncludeErrors

Modules/CIPPCore/Public/Set-CIPPCAExclusion.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function Set-CIPPCAExclusion {
99
$executingUser
1010
)
1111
try {
12-
$CheckExististing = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/identity/conditionalAccess/policies/$($PolicyId)" -tenantid $TenantFilter
12+
$CheckExististing = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/identity/conditionalAccess/policies/$($PolicyId)" -tenantid $TenantFilter -AsApp $true
1313
if ($ExclusionType -eq 'add') {
1414
$NewExclusions = [pscustomobject]@{
1515
conditions = [pscustomobject]@{ users = [pscustomobject]@{
@@ -19,7 +19,7 @@ function Set-CIPPCAExclusion {
1919
}
2020
$RawJson = ConvertTo-Json -Depth 10 -InputObject $NewExclusions
2121
if ($PSCmdlet.ShouldProcess($PolicyId, "Add exclusion for $UserID")) {
22-
New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/identity/conditionalAccess/policies/$($CheckExististing.id)" -tenantid $tenantfilter -type PATCH -body $RawJSON
22+
New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/identity/conditionalAccess/policies/$($CheckExististing.id)" -tenantid $tenantfilter -type PATCH -body $RawJSON -AsApp $true
2323
}
2424
}
2525

@@ -32,7 +32,7 @@ function Set-CIPPCAExclusion {
3232
}
3333
$RawJson = ConvertTo-Json -Depth 10 -InputObject $NewExclusions
3434
if ($PSCmdlet.ShouldProcess($PolicyId, "Remove exclusion for $UserID")) {
35-
New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/identity/conditionalAccess/policies/$($CheckExististing.id)" -tenantid $tenantfilter -type PATCH -body $RawJSON
35+
New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/identity/conditionalAccess/policies/$($CheckExististing.id)" -tenantid $tenantfilter -type PATCH -body $RawJSON -AsApp $true
3636
}
3737
}
3838
"Successfully performed $($ExclusionType) exclusion for $username from policy $($PolicyId)"
@@ -41,4 +41,4 @@ function Set-CIPPCAExclusion {
4141
"Failed to $($ExclusionType) user exclusion for $username from policy $($PolicyId): $($_.Exception.Message)"
4242
Write-LogMessage -user $executingUser -API 'Set-CIPPConditionalAccessExclusion' -message "Failed to $($ExclusionType) user exclusion for $username from policy $($PolicyId): $_" -Sev 'Error' -tenant $TenantFilter -LogData (Get-CippException -Exception $_)
4343
}
44-
}
44+
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAntiPhishPolicy.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ function Invoke-CIPPStandardAntiPhishPolicy {
5151
param($Tenant, $Settings)
5252
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'AntiPhishPolicy'
5353

54-
$PolicyName = @('Default Anti-Phishing Policy', 'Office365 AntiPhish Default (Default)')
55-
56-
$CurrentState = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-AntiPhishPolicy' |
57-
Where-Object -Property Name -In $PolicyName |
54+
$PolicyList = @('Default Anti-Phishing Policy', 'Office365 AntiPhish Default (Default)')
55+
$ExistingPolicy = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-AntiPhishPolicy' | Where-Object -Property Name -In $PolicyList
56+
$PolicyName = $ExistingPolicy.Name
57+
$CurrentState = $ExistingPolicy |
5858
Select-Object Name, Enabled, PhishThresholdLevel, EnableMailboxIntelligence, EnableMailboxIntelligenceProtection, EnableSpoofIntelligence, EnableFirstContactSafetyTips, EnableSimilarUsersSafetyTips, EnableSimilarDomainsSafetyTips, EnableUnusualCharactersSafetyTips, EnableUnauthenticatedSender, EnableViaTag, AuthenticationFailAction, SpoofQuarantineTag, MailboxIntelligenceProtectionAction, MailboxIntelligenceQuarantineTag, TargetedUserProtectionAction, TargetedUserQuarantineTag, TargetedDomainProtectionAction, TargetedDomainQuarantineTag, EnableOrganizationDomainsProtection
5959

6060
$StateIsCorrect = ($CurrentState.Name -eq $PolicyName) -and

0 commit comments

Comments
 (0)