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

Bugfix for powershell-yaml 0.4.8 - 0.4.10 #43

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

[![PSGallery Version](https://img.shields.io/powershellgallery/v/SentinelARConverter.svg?style=flat&logo=powershell&label=PSGallery%20Version)](https://www.powershellgallery.com/packages/SentinelARConverter) [![PSGallery Downloads](https://img.shields.io/powershellgallery/dt/SentinelARConverter.svg?style=flat&logo=powershell&label=PSGallery%20Downloads)](https://www.powershellgallery.com/packages/SentinelARConverter)

> [!WARNING]
> The [powershell-yaml](https://github.com/cloudbase/powershell-yaml) module which is used by the Sentinel Analytics Rule converter had some breaking changes starting in version 0.4.8.
> It is recommended to update to at least v0.4.11 of powershell-yaml or to update to the latest SentinelARConverter (>=2.4.3) which contains workarounds for known bugs.
> Avoid using powershell-yaml in the version 0.4.8 and 0.4.9 as there are other bugs.

## Installation

```PowerShell
Expand Down
2 changes: 1 addition & 1 deletion src/SentinelARConverter.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'SentinelARConverter.psm1'

# Version number of this module.
ModuleVersion = '2.4.2'
ModuleVersion = '2.4.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
9 changes: 9 additions & 0 deletions src/public/Convert-SentinelARArmToYaml.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ function Convert-SentinelARArmToYaml {

#region common

$PowerShellYAMLModuleVersion = Get-Module -Name powershell-yaml | Select-Object -ExpandProperty Version
if ( $PowerShellYAMLModuleVersion -ge [version]"0.4.8" -and $PowerShellYAMLModuleVersion -le [version]"0.4.9" ) {
Write-Warning "The powershell-yaml module version $($PowerShellYAMLModuleVersion) has known issues. Please update to the latest version of the module."
}

if ($PsCmdlet.ParameterSetName -ne "Pipeline" ) {
try {
if (-not (Test-Path $Filename)) {
Expand Down Expand Up @@ -368,6 +373,10 @@ function Convert-SentinelARArmToYaml {
}
}

# Bugfix for broken powershell-yaml - https://github.com/cloudbase/powershell-yaml/issues/177
if ( $PowerShellYAMLModuleVersion -ge [version]"0.4.8" -and $PowerShellYAMLModuleVersion -le [version]"0.4.10" ) {
$AnalyticsRuleCleaned = $AnalyticsRuleCleaned | ConvertTo-Json -Depth 99 | ConvertFrom-Json
}
# Convert the PowerShell object to YAML
$AnalyticsRuleYAML = $AnalyticsRuleCleaned | ConvertTo-Yaml

Expand Down
5 changes: 5 additions & 0 deletions src/public/Convert-SentinelARYamlToArm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ function Convert-SentinelARYamlToArm {

end {

$PowerShellYAMLModuleVersion = Get-Module -Name powershell-yaml | Select-Object -ExpandProperty Version
if ( $PowerShellYAMLModuleVersion -ge [version]"0.4.8" -and $PowerShellYAMLModuleVersion -le [version]"0.4.9" ) {
Write-Warning "The powershell-yaml module version $($PowerShellYAMLModuleVersion) has known issues. Please update to the latest version of the module."
}

try {
# Use parsed pipeline data if no file was specified (default)
if ($PsCmdlet.ParameterSetName -eq "Pipeline") {
Expand Down
8 changes: 8 additions & 0 deletions tests/Convert-SentinelARArmToYaml.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,14 @@ Describe "Simple example tests" {
$converted.subTechniques | Should -Be $null
$converted.relevantTechniques -join ", " | Should -Be "T1078.003, T1078.004"
}
It "Converts eventGroupingSettings correctly" {
$converted = Convert-SentinelARArmToYaml -Filename "TestDrive:/Content/Scheduled.json" | ConvertFrom-Yaml
$converted.eventGroupingSettings.aggregationKind | Should -Be "SingleAlert"
}
It "Converts incidentConfiguration correctly" {
$converted = Convert-SentinelARArmToYaml -Filename "TestDrive:/Content/Scheduled.json" | ConvertFrom-Yaml
$converted.incidentConfiguration.createIncident | Should -Be $true
}
}
}

Expand Down
Loading