-
Notifications
You must be signed in to change notification settings - Fork 27
/
Export-EntraOpsClassificationAppRoles.ps1
78 lines (66 loc) · 3.9 KB
/
Export-EntraOpsClassificationAppRoles.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
function Export-EntraOpsClassificationAppRoles {
[cmdletbinding()]
param
(
[Parameter(Mandatory = $false)]
$IncludeAuthorizedApiCalls = $False
)
# Get EntraOps Classification
$Classification = Get-Content -Path ./EntraOps_Classification/Classification_AppRoles.json | ConvertFrom-Json -Depth 10
# Get Graph API actions
if ($IncludeAuthorizedApiCalls -eq $true) {
$AllAuthorizedApiCalls = Invoke-WebRequest -Method GET -Uri "https://raw.githubusercontent.com/merill/graphpermissions.github.io/main/permissions.csv" | ConvertFrom-Csv
}
# Get information about App Role Provider
$AppRoleProviderIds = @("00000003-0000-0000-c000-000000000000")
$AppRoleProviders = foreach ($AppRoleProviderId in $AppRoleProviderIds) {
(Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/beta/servicePrincipals?`$filter=appId eq '$AppRoleProviderId'" -OutputType PSObject).value | select-object appId, appRoles
}
$AppRoles = $AppRoleProviders | foreach-object {
foreach ($AppRole in $_.AppRoles) {
# Apply Classification
$AppRoleTierLevelClassification = $Classification | where-object {$_.TierLevelDefinition.RoleDefinitionActions -contains $($AppRole.value)} | select-object EAMTierLevelName, EAMTierLevelTagValue
$AppRoleServiceClassification = $Classification | select-object -ExpandProperty TierLevelDefinition | where-object {$_.RoleDefinitionActions -contains $($AppRole.value)} | select-object Service
if ($IncludeAuthorizedApiCalls -eq $True -and $_.appId -eq "00000003-0000-0000-c000-000000000000") {
# Apply Autorized Graph Calls if AppRoleProvider is Microsoft Graph
$AppRoleAuthorizedApiCalls = $AllAuthorizedApiCalls | where-object {$_.PermissionName -contains $($AppRole.value)} | select-object -ExpandProperty API
}
if ($AppRoleTierLevelClassification.Count -gt 1 -and $AppRoleServiceClassification.Count -gt 1) {
Write-Warning "Multiple Tier Level Classification found for $($AppRole.value)"
}
if ($null -eq $AppRoleTierLevelClassification) {
$AppRoleTierLevelClassification = [PSCustomObject]@{
"EAMTierLevelName" = "Unclassified"
"EAMTierLevelTagValue" = "Unclassified"
}
}
if ($null -eq $AppRoleServiceClassification) {
$AppRoleServiceClassification = [PSCustomObject]@{
"Service" = "Unclassified"
}
}
if ($IncludeAuthorizedApiCalls -eq $True) {
[PSCustomObject]@{
"AppId" = $_.appId
"AppRoleId" = $AppRole.id
"AppRoleDisplayName" = $AppRole.value
"AuthorizedApiCalls" = $AppRoleAuthorizedApiCalls
"Category" = $AppRoleServiceClassification.Service
"EAMTierLevelName" = $AppRoleTierLevelClassification.EAMTierLevelName
"EAMTierLevelTagValue" = $AppRoleTierLevelClassification.EAMTierLevelTagValue
}
} else {
[PSCustomObject]@{
"AppId" = $_.appId
"AppRoleId" = $AppRole.id
"AppRoleDisplayName" = $AppRole.value
"Category" = $AppRoleServiceClassification.Service
"EAMTierLevelName" = $AppRoleTierLevelClassification.EAMTierLevelName
"EAMTierLevelTagValue" = $AppRoleTierLevelClassification.EAMTierLevelTagValue
}
}
}
}
$AppRoles = $AppRoles | sort-object AppRoleDisplayName
$AppRoles | ConvertTo-Json -Depth 10 | Out-File .\Classification\Classification_AppRoles.json -Force
}