Skip to content

Commit 8f52d44

Browse files
authored
Merge pull request #449 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents bb62dfe + 86b2b69 commit 8f52d44

File tree

5 files changed

+113
-14
lines changed

5 files changed

+113
-14
lines changed

Modules/CIPPCore/Public/Authentication/Get-CIPPRolePermissions.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ function Get-CIPPRolePermissions {
2020
$Permissions = $Role.Permissions | ConvertFrom-Json
2121
$AllowedTenants = if ($Role.AllowedTenants) { $Role.AllowedTenants | ConvertFrom-Json } else { @() }
2222
$BlockedTenants = if ($Role.BlockedTenants) { $Role.BlockedTenants | ConvertFrom-Json } else { @() }
23+
$BlockedEndpoints = if ($Role.BlockedEndpoints) { $Role.BlockedEndpoints | ConvertFrom-Json } else { @() }
2324
[PSCustomObject]@{
24-
Role = $Role.RowKey
25-
Permissions = $Permissions.PSObject.Properties.Value
26-
AllowedTenants = @($AllowedTenants)
27-
BlockedTenants = @($BlockedTenants)
25+
Role = $Role.RowKey
26+
Permissions = $Permissions.PSObject.Properties.Value
27+
AllowedTenants = @($AllowedTenants)
28+
BlockedTenants = @($BlockedTenants)
29+
BlockedEndpoints = @($BlockedEndpoints)
2830
}
2931
} else {
3032
throw "Role $RoleName not found."

Modules/CIPPCore/Public/Authentication/Test-CIPPAccess.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ function Test-CIPPAccess {
199199
continue
200200
}
201201
}
202+
202203
if ($PermissionsFound) {
203204
if ($TenantList.IsPresent) {
204205
$LimitedTenantList = foreach ($Permission in $PermissionSet) {
@@ -248,6 +249,9 @@ function Test-CIPPAccess {
248249
foreach ($Role in $PermissionSet) {
249250
foreach ($Perm in $Role.Permissions) {
250251
if ($Perm -match $APIRole) {
252+
if ($Role.BlockedEndpoints -contains $Request.Params.CIPPEndpoint) {
253+
throw "Access to this CIPP API endpoint is not allowed, the custom role '$($Role.Role)' has blocked this endpoint: $($Request.Params.CIPPEndpoint)"
254+
}
251255
$APIAllowed = $true
252256
break
253257
}

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ function Invoke-ExecCustomRole {
2626
Write-LogMessage -headers $Request.Headers -API 'ExecCustomRole' -message "Saved custom role $($Request.Body.RoleName)" -Sev 'Info'
2727
if ($Request.Body.RoleName -notin $DefaultRoles) {
2828
$Role = @{
29-
'PartitionKey' = 'CustomRoles'
30-
'RowKey' = "$($Request.Body.RoleName.ToLower())"
31-
'Permissions' = "$($Request.Body.Permissions | ConvertTo-Json -Compress)"
32-
'AllowedTenants' = "$($Request.Body.AllowedTenants | ConvertTo-Json -Compress)"
33-
'BlockedTenants' = "$($Request.Body.BlockedTenants | ConvertTo-Json -Compress)"
29+
'PartitionKey' = 'CustomRoles'
30+
'RowKey' = "$($Request.Body.RoleName.ToLower())"
31+
'Permissions' = "$($Request.Body.Permissions | ConvertTo-Json -Compress)"
32+
'AllowedTenants' = "$($Request.Body.AllowedTenants | ConvertTo-Json -Compress)"
33+
'BlockedTenants' = "$($Request.Body.BlockedTenants | ConvertTo-Json -Compress)"
34+
'BlockedEndpoints' = "$($Request.Body.BlockedEndpoints | ConvertTo-Json -Compress)"
3435
}
3536
Add-CIPPAzDataTableEntity @Table -Entity $Role -Force | Out-Null
3637
$Results.Add("Custom role $($Request.Body.RoleName) saved")
@@ -110,6 +111,15 @@ function Invoke-ExecCustomRole {
110111
} else {
111112
$Role | Add-Member -NotePropertyName BlockedTenants -NotePropertyValue @() -Force
112113
}
114+
if ($Role.BlockedEndpoints) {
115+
try {
116+
$Role.BlockedEndpoints = @($Role.BlockedEndpoints | ConvertFrom-Json)
117+
} catch {
118+
$Role.BlockedEndpoints = ''
119+
}
120+
} else {
121+
$Role | Add-Member -NotePropertyName BlockedEndpoints -NotePropertyValue @() -Force
122+
}
113123
$EntraRoleGroup = $EntraRoleGroups | Where-Object -Property RowKey -EQ $Role.RowKey
114124
if ($EntraRoleGroup) {
115125
$EntraGroup = $EntraRoleGroups | Where-Object -Property RowKey -EQ $Role.RowKey | Select-Object @{Name = 'label'; Expression = { $_.GroupName } }, @{Name = 'value'; Expression = { $_.GroupId } }
@@ -120,10 +130,11 @@ function Invoke-ExecCustomRole {
120130
}
121131
$DefaultRoles = foreach ($DefaultRole in $DefaultRoles) {
122132
$Role = @{
123-
RowKey = $DefaultRole
124-
Permissions = ''
125-
AllowedTenants = @('AllTenants')
126-
BlockedTenants = @('')
133+
RowKey = $DefaultRole
134+
Permissions = ''
135+
AllowedTenants = @('AllTenants')
136+
BlockedTenants = @('')
137+
BlockedEndpoints = @('')
127138
}
128139
$EntraRoleGroup = $EntraRoleGroups | Where-Object -Property RowKey -EQ $Role.RowKey
129140
if ($EntraRoleGroup) {

Modules/CIPPCore/Public/Functions/Get-CIPPTenantAlignment.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ function Get-CIPPTenantAlignment {
158158
ReportingEnabled = $IntuneReportingEnabled
159159
}
160160
}
161+
if ($IntuneTemplate.'TemplateList-Tags') {
162+
foreach ($Tag in $IntuneTemplate.'TemplateList-Tags') {
163+
Write-Host "Processing Intune Tag: $($Tag.value)"
164+
$IntuneActions = if ($IntuneTemplate.action) { $IntuneTemplate.action } else { @() }
165+
$IntuneReportingEnabled = ($IntuneActions | Where-Object { $_.value -and ($_.value.ToLower() -eq 'report' -or $_.value.ToLower() -eq 'remediate') }).Count -gt 0
166+
$TemplatesList = Get-CIPPAzDataTableEntity @TemplateTable -Filter $Filter | Where-Object -Property package -EQ $Tag.value
167+
$TemplatesList | ForEach-Object {
168+
$TagStandardId = "standards.IntuneTemplate.$($_.GUID)"
169+
[PSCustomObject]@{
170+
StandardId = $TagStandardId
171+
ReportingEnabled = $IntuneReportingEnabled
172+
}
173+
}
174+
175+
}
176+
}
161177
}
162178
}
163179
# Handle Conditional Access templates specially
@@ -224,7 +240,7 @@ function Get-CIPPTenantAlignment {
224240
[PSCustomObject]@{
225241
StandardName = $StandardKey
226242
Compliant = $IsCompliant
227-
StandardValue = ($Value | ConvertTo-Json -Compress)
243+
StandardValue = ($Value | ConvertTo-Json -Depth 100 -Compress)
228244
ComplianceStatus = $ComplianceStatus
229245
ReportingDisabled = $IsReportingDisabled
230246
}

Modules/CIPPCore/Public/Standards/Get-CIPPStandards.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,72 @@ function Get-CIPPStandards {
3131
$_.GUID -like $TemplateId -and $_.runManually -eq $runManually
3232
}
3333

34+
# 1.5. Expand templates that contain TemplateList-Tags into multiple standards
35+
$ExpandedTemplates = foreach ($Template in $Templates) {
36+
$NewTemplate = $Template.PSObject.Copy()
37+
$ExpandedStandards = [ordered]@{}
38+
$HasExpansions = $false
39+
40+
foreach ($StandardName in $Template.standards.PSObject.Properties.Name) {
41+
$StandardValue = $Template.standards.$StandardName
42+
$IsArray = $StandardValue -is [System.Collections.IEnumerable] -and -not ($StandardValue -is [string])
43+
44+
if ($IsArray) {
45+
$NewArray = @()
46+
foreach ($Item in $StandardValue) {
47+
if ($Item.'TemplateList-Tags'.value) {
48+
$HasExpansions = $true
49+
$Table = Get-CippTable -tablename 'templates'
50+
$Filter = "PartitionKey eq 'IntuneTemplate'"
51+
$TemplatesList = Get-CIPPAzDataTableEntity @Table -Filter $Filter | Where-Object -Property package -EQ $Item.'TemplateList-Tags'.value
52+
53+
foreach ($TemplateItem in $TemplatesList) {
54+
$NewItem = $Item.PSObject.Copy()
55+
$NewItem.PSObject.Properties.Remove('TemplateList-Tags')
56+
$NewItem | Add-Member -NotePropertyName TemplateList -NotePropertyValue ([pscustomobject]@{
57+
label = "$($TemplateItem.RowKey)"
58+
value = "$($TemplateItem.RowKey)"
59+
}) -Force
60+
$NewArray = $NewArray + $NewItem
61+
}
62+
} else {
63+
$NewArray = $NewArray + $Item
64+
}
65+
}
66+
$ExpandedStandards[$StandardName] = $NewArray
67+
} else {
68+
if ($StandardValue.'TemplateList-Tags'.value) {
69+
$HasExpansions = $true
70+
$Table = Get-CippTable -tablename 'templates'
71+
$Filter = "PartitionKey eq 'IntuneTemplate'"
72+
$TemplatesList = Get-CIPPAzDataTableEntity @Table -Filter $Filter | Where-Object -Property package -EQ $StandardValue.'TemplateList-Tags'.value
73+
74+
$NewArray = @()
75+
foreach ($TemplateItem in $TemplatesList) {
76+
$NewItem = $StandardValue.PSObject.Copy()
77+
$NewItem.PSObject.Properties.Remove('TemplateList-Tags')
78+
$NewItem | Add-Member -NotePropertyName TemplateList -NotePropertyValue ([pscustomobject]@{
79+
label = "$($TemplateItem.RowKey)"
80+
value = "$($TemplateItem.RowKey)"
81+
}) -Force
82+
$NewArray = $NewArray + $NewItem
83+
}
84+
$ExpandedStandards[$StandardName] = $NewArray
85+
} else {
86+
$ExpandedStandards[$StandardName] = $StandardValue
87+
}
88+
}
89+
}
90+
91+
if ($HasExpansions) {
92+
$NewTemplate.standards = [pscustomobject]$ExpandedStandards
93+
}
94+
95+
$NewTemplate
96+
}
97+
98+
$Templates = $ExpandedTemplates
99+
34100
# 2. Get tenant list, filter if needed
35101
$AllTenantsList = Get-Tenants
36102
if ($TenantFilter -ne 'allTenants') {

0 commit comments

Comments
 (0)