Skip to content

Commit 3e93d5d

Browse files
authored
Merge pull request #1465 from KelvinTegelaar/dev
Dev to hotfix
2 parents b9c3159 + 3ec1ead commit 3e93d5d

File tree

153 files changed

+1409
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+1409
-260
lines changed

ConversionTable.csv

Lines changed: 122 additions & 1 deletion
Large diffs are not rendered by default.

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertHuntressRogueApps.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ function Get-CIPPAlertHuntressRogueApps {
1414
[Parameter(Mandatory = $false)]
1515
[Alias('input')]
1616
$InputValue,
17-
$TenantFilter
17+
$TenantFilter,
18+
[Parameter(Mandatory = $false)]
19+
[bool]$IgnoreDisabledApps = $false
1820
)
1921

2022
try {
2123
$RogueApps = Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/huntresslabs/rogueapps/main/public/rogueapps.json'
2224
$RogueAppFilter = $RogueApps.appId -join "','"
2325
$ServicePrincipals = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$filter=appId in ('$RogueAppFilter')" -tenantid $TenantFilter
26+
# If IgnoreDisabledApps is true, filter out disabled service principals
27+
if ($IgnoreDisabledApps) {
28+
$ServicePrincipals = $ServicePrincipals | Where-Object { $_.accountEnabled -eq $true }
29+
}
2430

2531
if (($ServicePrincipals | Measure-Object).Count -gt 0) {
2632
$AlertData = foreach ($ServicePrincipal in $ServicePrincipals) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function Get-CIPPAlertTERRL {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
#>
6+
[CmdletBinding()]
7+
Param (
8+
[Parameter(Mandatory = $false)]
9+
[Alias('input')]
10+
$InputValue,
11+
$TenantFilter
12+
)
13+
14+
try {
15+
# Set threshold with fallback to 80%
16+
$Threshold = if ([string]::IsNullOrWhiteSpace($InputValue)) { 80 } else { [int]$InputValue }
17+
18+
# Get TERRL status
19+
$TerrlStatus = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-LimitsEnforcementStatus'
20+
21+
if ($TerrlStatus) {
22+
$UsagePercentage = [math]::Round(($TerrlStatus.ObservedValue / $TerrlStatus.Threshold) * 100, 2)
23+
24+
if ($UsagePercentage -gt $Threshold) {
25+
$AlertData = [PSCustomObject]@{
26+
UsagePercentage = $UsagePercentage
27+
CurrentVolume = $TerrlStatus.ObservedValue
28+
ThresholdLimit = $TerrlStatus.Threshold
29+
EnforcementEnabled = $TerrlStatus.EnforcementEnabled
30+
Verdict = $TerrlStatus.Verdict
31+
Message = 'Tenant is at {0}% of their TERRL limit (using {1} of {2} messages). Tenant Enforcement Status: {3}' -f $UsagePercentage, $TerrlStatus.ObservedValue, $TerrlStatus.Threshold, $TerrlStatus.Verdict
32+
}
33+
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
34+
}
35+
}
36+
} catch {
37+
Write-AlertMessage -tenant $($TenantFilter) -message "Could not get TERRL status for $($TenantFilter): $(Get-NormalizedError -message $_.Exception.message)"
38+
}
39+
}

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,34 @@ function Get-CIPPAccessRole {
1616
Internal
1717
#>
1818
[CmdletBinding()]
19-
param($Request)
19+
param($Request, $Headers)
2020

21-
$CacheAccessUserRoleTable = Get-CIPPTable -tablename 'cacheAccessUserRole'
22-
$CachedRoles = Get-CIPPAzDataTableEntity @CacheAccessUserRoleTable -Filter "PartitionKey eq 'AccessUser' and RowKey eq '$($Request.Headers.'x-ms-client-principal-name')'" | Select-Object -ExpandProperty Role | ConvertFrom-Json
21+
$Headers = $Request.Headers ?? $Headers
2322

24-
$SwaCreds = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($request.headers.'x-ms-client-principal')) | ConvertFrom-Json)
23+
$CacheAccessUserRoleTable = Get-CIPPTable -tablename 'cacheAccessUserRoles'
24+
25+
$SwaCreds = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Headers.'x-ms-client-principal')) | ConvertFrom-Json)
2526
$SwaRoles = $SwaCreds.userRoles
27+
$Username = $SwaCreds.userDetails
28+
29+
$CachedRoles = Get-CIPPAzDataTableEntity @CacheAccessUserRoleTable -Filter "PartitionKey eq 'AccessUser' and RowKey eq '$Username'" | Select-Object -ExpandProperty Role | ConvertFrom-Json
30+
31+
Write-Information "SWA Roles: $($SwaRoles -join ', ')"
32+
Write-Information "Cached Roles: $($CachedRoles -join ', ')"
2633

2734
# Combine SWA roles and cached roles into a single deduplicated list
2835
$AllRoles = [System.Collections.Generic.List[string]]::new()
29-
if ($null -ne $SwaRoles) {
30-
$AllRoles.AddRange($SwaRoles)
36+
37+
foreach ($Role in $SwaRoles) {
38+
if (-not $AllRoles.Contains($Role)) {
39+
$AllRoles.Add($Role)
40+
}
3141
}
32-
if ($null -ne $CachedRoles) {
33-
$AllRoles.AddRange($CachedRoles)
42+
foreach ($Role in $CachedRoles) {
43+
if (-not $AllRoles.Contains($Role)) {
44+
$AllRoles.Add($Role)
45+
}
3446
}
35-
36-
# Remove duplicates and ensure we have a clean array
3747
$CombinedRoles = $AllRoles | Select-Object -Unique
3848

3949
# For debugging

0 commit comments

Comments
 (0)