Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add privileged service principals table to AAD report #1467

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

dagarwal-mitre
Copy link
Collaborator

@dagarwal-mitre dagarwal-mitre commented Dec 10, 2024

🗣 Description

Wanted to add privileged service principals to the report to make users aware of these high privileged principals within their tenants

💭 Motivation and context

#934

🧪 Testing

Test with different tenants and ensure the Privileged Service Principals table is produced as expected for the AAD report and verify the verify privileged_service_principals is added in ScubaResults.json.

✅ Pre-approval checklist

  • This PR has an informative and human-readable title.
  • PR targets the correct parent branch (e.g., main or release-name) for merge.
  • Changes are limited to a single goal - eschew scope creep!
  • Changes are sized such that they do not touch excessive number of files.
  • All future TODOs are captured in issues, which are referenced in code comments.
  • These code changes follow the ScubaGear content style guide.
  • Related issues these changes resolve are linked preferably via closing keywords.
  • All relevant type-of-change labels added.
  • All relevant project fields are set.
  • All relevant repo and/or project documentation updated to reflect these changes.
  • Unit tests added/updated to cover PowerShell and Rego changes.
  • Functional tests added/updated to cover PowerShell and Rego changes.
  • All relevant functional tests passed.
  • All automated checks (e.g., linting, static analysis, unit/smoke tests) passed.

✅ Pre-merge checklist

  • PR passed smoke test check.

  • Feature branch has been rebased against changes from parent branch, as needed

    Use Rebase branch button below or use this reference to rebase from the command line.

  • Resolved all merge conflicts on branch

  • Notified merge coordinator that PR is ready for merge via comment mention

  • Demonstrate changes to the team for questions and comments.
    (Note: Only required for issues of size Medium or larger)

✅ Post-merge checklist

  • Feature branch deleted after merge to clean up repository.
  • Verified that all checks pass on parent branch (e.g., main or release-name) after merge.

@dagarwal-mitre dagarwal-mitre added the enhancement This issue or pull request will add new or improve existing functionality label Dec 10, 2024
@dagarwal-mitre dagarwal-mitre added this to the Kraken milestone Dec 10, 2024
@dagarwal-mitre dagarwal-mitre self-assigned this Dec 10, 2024
@dagarwal-mitre dagarwal-mitre linked an issue Dec 10, 2024 that may be closed by this pull request
5 tasks
Copy link
Collaborator

@mitchelbaker-cisa mitchelbaker-cisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan on doing two reviews, the first being a pass through of the new code submitted in this PR. I will do another review after testing steps are added.

$PrivilegedServicePrincipals = @{}

#PrivilegedObjects is an array because of the tracker.trycommand, and so the first index is the hashtable
foreach ($key in $PrivilegedObjects[0].Keys) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we certain that $PrivilegedObjects will always contain at least one entry? Otherwise accessing the 0th index may throw an error if an entry does not exist.

Either way, I also think it would help to see some error handling to check if $PrivilegedObjects[0].Keys is not null prior to entering the loop.

@@ -270,13 +270,33 @@ function New-Report {
# Create a section header for the licensing information
$LicensingHTML = "<h2>Tenant Licensing Information</h2>" + $LicenseTable

# Create a section for privileged service principals
$privilegedServicePrincipalsTable = $SettingsExport.privileged_service_principals.psobject.properties | ForEach-Object {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic in AADProvider:

If $PrivilegedServicePrincipals is $null, then it equals {}. Otherwise, set equal to $PrivilegedServicePrincipals
Then in the AADProvider json set "privileged_service_principals" equal to $PrivilegedServicePrincipals

If "privileged_service_principals" = {}, then $principal.DisplayName, $principal.ServicePrincipalId, etc. are nonexistent properties. Can we add some error handling here?

We could check $SettingsExport.privileged_service_principals.PSObject.Count > 0 or some other condition.

@@ -274,6 +291,9 @@ function Get-PrivilegedUser {
if ($Objecttype -eq "user") {
LoadObjectDataIntoPrivilegedUserHashtable -RoleName $Role.DisplayName -PrivilegedUsers $PrivilegedUsers -ObjectId $User.Id -TenantHasPremiumLicense $TenantHasPremiumLicense -M365Environment $M365Environment -Objecttype "user"
}
elseif ($Objecttype -eq "servicePrincipal") {
LoadObjectDataIntoPrivilegedUserHashtable -RoleName $Role.DisplayName -PrivilegedUsers $PrivilegedUsers -ObjectId $User.Id -TenantHasPremiumLicense $TenantHasPremiumLicense -M365Environment $M365Environment -Objecttype "serviceprincipal"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a new unit test to handle $Objecttype="serviceprincipal" in LoadObjectDataIntoPrivilegedUserHashTable.Tests.ps1?

@@ -1,5 +1,5 @@
Import-Module -Name $PSScriptRoot/../ExportEXOProvider.psm1 -Function Get-ScubaSpfRecord, Get-ScubaDkimRecord, Get-ScubaDmarcRecord
Import-Module -Name $PSScriptRoot/../ExportAADProvider.psm1 -Function Get-PrivilegedRole, Get-PrivilegedUser
Import-Module -Name $PSScriptRoot/../ExportAADProvider.psm1 -Function Get-PrivilegedRole, Get-PrivilegedUser, Get-PrivilegedServicePrincipal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see Get-PrivilegedServicePrincipal as a function in your branch's ExportAADProvider.psm1.

@@ -437,7 +474,107 @@ function LoadObjectDataIntoPrivilegedUserHashtable {
}

}

# function LoadObjectDataIntoPrivilegedUserHashtable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment blocks

@dagarwal-mitre dagarwal-mitre force-pushed the 934_service_principals_to_aad_report branch from 74932fa to 62dafde Compare December 16, 2024 17:19
@dagarwal-mitre dagarwal-mitre force-pushed the 934_service_principals_to_aad_report branch from 62dafde to 7200154 Compare December 16, 2024 18:11
@schrolla schrolla modified the milestones: Kraken, Lionfish Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue or pull request will add new or improve existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add service principal assigned roles to the AAD report
4 participants