-
Notifications
You must be signed in to change notification settings - Fork 27
/
Export-EntraOpsClassificationDirectoryRoles.ps1
97 lines (82 loc) · 5.05 KB
/
Export-EntraOpsClassificationDirectoryRoles.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function Export-EntraOpsClassificationDirectoryRoles {
[cmdletbinding()]
param
(
[Parameter(Mandatory = $false)]
$SingleClassification = $True
,
[Parameter(Mandatory = $false)]
$FilteredConditions = @('$ResourceIsSelf', '$SubjectIsOwner')
,
[Parameter(Mandatory = $false)]
$IncludeCustomRoles = $False
)
# Define sensitive role definitions without actions to classify
$ControlPlaneRolesWithoutRoleActions = @(
'd29b2b05-8046-44ba-8758-1e26182fcf32', # Directory Synchronization Accounts
'a92aed5d-d78a-4d16-b381-09adb37eb3b0', # On Premises Directory Sync Account
'9f06204d-73c1-4d4c-880a-6edb90606fd8' # Azure AD Joined Device Local Administrator
)
# Get EntraOps Classification
$Classification = Get-Content -Path ./EntraOps_Classification/Classification_AadResources.json | ConvertFrom-Json -Depth 10
# Single classifcation (highest tier level only)
Write-Output "Query directory role templates for mapping ID to name and further details"
$DirectoryRoleDefinitions = (Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/beta/roleManagement/directory/roleDefinitions").value | select-object displayName, templateId, isBuiltin, isPrivileged, rolePermissions, categories, richDescription
if ($IncludeCustomRoles -eq $False) {
$DirectoryRoleDefinitions = $DirectoryRoleDefinitions | where-object { $_.isBuiltin -eq "True" }
}
$DirectoryRoles = $DirectoryRoleDefinitions | foreach-object {
$DirectoryRolePermissions = ($_.RolePermissions | Where-Object { $_.condition -notin $FilteredConditions }).allowedResourceActions
$ClassifiedDirectoryRolePermissions = foreach ($RolePermission in $DirectoryRolePermissions) {
# Apply Classification
$EntraRolePermissionTierLevelClassification = $Classification | where-object { $_.TierLevelDefinition.RoleDefinitionActions -contains $($RolePermission) } | select-object EAMTierLevelName, EAMTierLevelTagValue
$EntraRolePermissionServiceClassification = $Classification | select-object -ExpandProperty TierLevelDefinition | where-object { $_.RoleDefinitionActions -contains $($RolePermission) } | select-object Service
if ($EntraRolePermissionTierLevelClassification.Count -gt 1 -and $EntraRolePermissionServiceClassification.Count -gt 1) {
Write-Warning "Multiple Tier Level Classification found for $($RolePermission)"
}
if ($null -eq $EntraRolePermissionTierLevelClassification) {
$EntraRolePermissionTierLevelClassification = [PSCustomObject]@{
"EAMTierLevelName" = "Unclassified"
"EAMTierLevelTagValue" = "Unclassified"
}
}
if ($null -eq $EntraRolePermissionServiceClassification) {
$EntraRolePermissionServiceClassification = [PSCustomObject]@{
"Service" = "Unclassified"
}
}
[PSCustomObject]@{
"AuthorizedResourceAction" = $RolePermission
"Category" = $EntraRolePermissionServiceClassification.Service
"EAMTierLevelName" = $EntraRolePermissionTierLevelClassification.EAMTierLevelName
"EAMTierLevelTagValue" = $EntraRolePermissionTierLevelClassification.EAMTierLevelTagValue
}
}
$ClassifiedDirectoryRolePermissions = $ClassifiedDirectoryRolePermissions | sort-object EAMTierLevelTagValue, Category, AuthorizedResourceAction
if ($SingleClassification -eq $True) {
$RoleDefinitionClassification = ($ClassifiedDirectoryRolePermissions | select-object -ExcludeProperty AuthorizedResourceAction, Category -Unique | Sort-Object EAMTierLevelTagValue | select-object -First 1)
}
else {
$FilteredRoleClassifications = ($ClassifiedDirectoryRolePermissions | select-object -ExcludeProperty AuthorizedResourceAction -Unique | Sort-Object EAMTierLevelTagValue )
$RoleDefinitionClassification = [System.Collections.Generic.List[object]]::new()
$RoleDefinitionClassification.Add($FilteredRoleClassifications)
}
if ($ControlPlaneRolesWithoutRoleActions -contains $_.templateId) {
$RoleDefinitionClassification = [PSCustomObject]@{
"EAMTierLevelName" = "ControlPlane"
"EAMTierLevelTagValue" = "0"
}
}
[PSCustomObject]@{
"RoleId" = $_.templateId
"RoleName" = $_.displayName
"isPrivileged" = $_.isPrivileged
"Categories" = $_.categories
"RichDescription" = $_.richDescription
"RolePermissions" = $ClassifiedDirectoryRolePermissions
"Classification" = $RoleDefinitionClassification
}
}
$DirectoryRoles = $DirectoryRoles | sort-object RoleName
$DirectoryRoles | ConvertTo-Json -Depth 10 | Out-File .\Classification\Classification_EntraIdDirectoryRoles.json -Force
}