Skip to content

Commit 86b2b69

Browse files
Merge branch 'dev' of https://github.com/KelvinTegelaar/CIPP-API into dev
2 parents de99211 + cf3a355 commit 86b2b69

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
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) {

0 commit comments

Comments
 (0)