forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request KelvinTegelaar#911 from KelvinTegelaar/dev
Dev to release
- Loading branch information
Showing
115 changed files
with
1,754 additions
and
993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action | ||
# More GitHub Actions for Azure: https://github.com/Azure/actions | ||
|
||
name: Build and deploy Powershell project to Azure Function App - cippacnqv | ||
|
||
on: | ||
push: | ||
branches: | ||
- dev | ||
workflow_dispatch: | ||
|
||
env: | ||
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root | ||
|
||
jobs: | ||
deploy: | ||
runs-on: windows-latest | ||
permissions: | ||
id-token: write #This is required for requesting the JWT | ||
|
||
steps: | ||
- name: 'Checkout GitHub Action' | ||
uses: actions/checkout@v4 | ||
|
||
- name: Login to Azure | ||
uses: azure/login@v1 | ||
with: | ||
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_6085081ED1124B799258E9FF743FF4B9 }} | ||
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_9BDB2DDBFAFA4BC19C20A58B204BFAF3 }} | ||
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_02B5224812794971B05EDD557AF2B867 }} | ||
|
||
- name: 'Run Azure Functions Action' | ||
uses: Azure/functions-action@v1 | ||
id: fa | ||
with: | ||
app-name: 'cippacnqv' | ||
slot-name: 'Production' | ||
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
.../CIPPCore/Public/Entrypoints/Activity Triggers/Webhooks/Push-AuditLogBundleProcessing.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
function Push-AuditLogBundleProcessing { | ||
Param($Item) | ||
|
||
try { | ||
$AuditBundleTable = Get-CippTable -tablename 'AuditLogBundles' | ||
$AuditLogBundle = Get-CIPPAzDataTableEntity @AuditBundleTable -Filter "PartitionKey eq '$($Item.TenantFilter)' and RowKey eq '$($Item.ContentId)'" | ||
if ($AuditLogBundle.ProcessingStatus -ne 'Pending') { | ||
Write-Information 'Audit log bundle already processed' | ||
return | ||
} | ||
try { | ||
$AuditLogTest = Test-CIPPAuditLogRules -TenantFilter $Item.TenantFilter -LogType $AuditLogBundle.ContentType -ContentUri $AuditLogBundle.ContentUri | ||
$AuditLogBundle.ProcessingStatus = 'Completed' | ||
$AuditLogBundle.MatchedRules = [string](ConvertTo-Json -Compress -Depth 10 -InputObject $AuditLogTest.MatchedRules) | ||
$AuditLogBundle.MatchedLogs = $AuditLogTest.MatchedLogs | ||
} catch { | ||
$AuditLogBundle.ProcessingStatus = 'Failed' | ||
$AuditLogBundle | Add-Member -NotePropertyName Error -NotePropertyValue $_.InvocationInfo.PositionMessage -TypeName string | ||
} | ||
try { | ||
Add-CIPPAzDataTableEntity @AuditBundleTable -Entity $AuditLogBundle -Force | ||
} catch { | ||
Write-Host ( 'Error logging audit bundle: {0} line {1} - {2}' -f $_.InvocationInfo.ScriptName, $_.InvocationInfo.ScriptLineNumber, $_.Exception.Message) | ||
} | ||
|
||
$DataToProcess = ($AuditLogTest).DataToProcess | ||
Write-Information "Webhook: Data to process found: $($DataToProcess.count) items" | ||
foreach ($AuditLog in $DataToProcess) { | ||
Write-Information "Processing $($AuditLog.operation)" | ||
$Webhook = @{ | ||
Data = $AuditLog | ||
CIPPURL = [string]$AuditLogBundle.CIPPURL | ||
TenantFilter = $Item.TenantFilter | ||
} | ||
Invoke-CippWebhookProcessing @Webhook | ||
} | ||
} catch { | ||
Write-Host ( 'Audit log error {0} line {1} - {2}' -f $_.InvocationInfo.ScriptName, $_.InvocationInfo.ScriptLineNumber, $_.Exception.Message) | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Webhooks/Push-AuditLogTenant.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
function Push-AuditLogTenant { | ||
Param($Item) | ||
|
||
$AuditBundleTable = Get-CippTable -tablename 'AuditLogBundles' | ||
$SchedulerConfig = Get-CIPPTable -TableName 'SchedulerConfig' | ||
$CIPPURL = Get-CIPPAzDataTableEntity @SchedulerConfig -Filter "PartitionKey eq 'webhookcreation'" | Select-Object -First 1 -ExpandProperty CIPPURL | ||
$WebhookTable = Get-CippTable -tablename 'webhookTable' | ||
$Webhooks = Get-CIPPAzDataTableEntity @WebhookTable -Filter "PartitionKey eq '$($Item.TenantFilter)' and Version eq '3'" | Where-Object { $_.Resource -match '^Audit' } | ||
$ExistingBundles = Get-CIPPAzDataTableEntity @AuditBundleTable -Filter "PartitionKey eq '$($Item.TenantFilter)' and ContentType eq '$ContentType'" | ||
|
||
$NewBundles = [System.Collections.Generic.List[object]]::new() | ||
foreach ($Webhook in $Webhooks) { | ||
$TenantFilter = $Webhook.PartitionKey | ||
$LogType = $Webhook.Resource | ||
Write-Information "Querying for $LogType on $TenantFilter" | ||
$ContentBundleQuery = @{ | ||
TenantFilter = $TenantFilter | ||
ContentType = $LogType | ||
StartTime = $Item.StartTime | ||
EndTime = $Item.EndTime | ||
} | ||
$LogBundles = Get-CIPPAuditLogContentBundles @ContentBundleQuery | ||
|
||
foreach ($Bundle in $LogBundles) { | ||
if ($ExistingBundles.RowKey -notcontains $Bundle.contentId) { | ||
$NewBundles.Add([PSCustomObject]@{ | ||
PartitionKey = $TenantFilter | ||
RowKey = $Bundle.contentId | ||
DefaultDomainName = $TenantFilter | ||
ContentType = $Bundle.contentType | ||
ContentUri = $Bundle.contentUri | ||
ContentCreated = $Bundle.contentCreated | ||
ContentExpiration = $Bundle.contentExpiration | ||
CIPPURL = [string]$CIPPURL | ||
ProcessingStatus = 'Pending' | ||
MatchedRules = '' | ||
MatchedLogs = 0 | ||
}) | ||
} | ||
} | ||
} | ||
|
||
if (($NewBundles | Measure-Object).Count -gt 0) { | ||
Add-CIPPAzDataTableEntity @AuditBundleTable -Entity $NewBundles | ||
Write-Information ($NewBundles | ConvertTo-Json -Depth 5 -Compress) | ||
|
||
$Batch = $NewBundles | Select-Object @{Name = 'ContentId'; Expression = { $_.RowKey } }, @{Name = 'TenantFilter'; Expression = { $_.PartitionKey } }, @{Name = 'FunctionName'; Expression = { 'AuditLogBundleProcessing' } } | ||
$InputObject = [PSCustomObject]@{ | ||
OrchestratorName = 'AuditLogs' | ||
Batch = @($Batch) | ||
SkipLog = $true | ||
} | ||
$InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress) | ||
Write-Host "Started orchestration with ID = '$InstanceId'" | ||
} | ||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.