Some time ago I realized that the provided Azure Runbook for deploying Sentinel One works great, but does not do a great job of reporting if there was an error. Because S1 needs to be deployed after imaging (not as part of the image itself) in a typical shared user pool that is image driven, this has the potential for the S1 agent to NOT be installed, and noone knows there was a failure in the deployment. Ultimately - inside Nerdio, no check and balance to ensure every device is protected.
I recently came upon a scenario where there was a bad API token value in the install script, and the S1 deploy failed. Because of the nature of the runbook, it still reports a successful azure runbook execution. I made some tweaks (you might be able to do better) - but wanted to share for 1 - any partners who use this and recognize the concern, and 2 - maybe we can get NMM to update their provided script to better capture this failure?
Old execution statement:
Set-AzVMExtension -ResourceGroupName $AzureResourceGroupName -Location $AzureRegionName -VMName $AzureVMName -Name "SentinelOne.WindowsExtension" -Publisher "SentinelOne.WindowsExtension" -Type "WindowsExtension" -TypeHandlerVersion "1.0" -Settings $Settings -ProtectedSettings $ProtectedSettings
My execution statement:
try {
Write-Output "Installing SentinelOne agent on VM $AzureVMName..."
$installResult = Set-AzVMExtension `
-ResourceGroupName $AzureResourceGroupName `
-Location $AzureRegionName `
-VMName $AzureVMName `
-Name "SentinelOne.WindowsExtension" `
-Publisher "SentinelOne.WindowsExtension" `
-Type "WindowsExtension" `
-TypeHandlerVersion "1.0" `
-Settings $Settings `
-ProtectedSettings $ProtectedSettings `
-ErrorAction Stop
Write-Output "SentinelOne extension installation initiated successfully."
}
catch {
$errMsg = "Failed to install SentinelOne agent on VM $AzureVMName. Error: $($_.Exception.Message)"
Write-Error $errMsg
throw $errMsg
}
Ultimately - when the Azure Runbook executes and it is not successful in setting the Agent Extension, we get an error condition that can be associated to a notification action, that can be escalated to appropriate places during reimaging. I am sure there are simpler/cleaner ways to do this in less lines, but the end result is the same.
Comments (5 comments)