Configure upload during Ninja bootstrap
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[string]$ManifestUrl = "https://gitea.officecom.cloud/officecom/oc-sentinel/raw/main/release/stable/version.json",
|
[string]$ManifestUrl = "https://gitea.officecom.cloud/officecom/oc-sentinel/raw/main/release/stable/version.json",
|
||||||
|
[string]$WebhookUrl = "",
|
||||||
|
[string]$SecretValue = "",
|
||||||
[switch]$RunInitialStatusScan
|
[switch]$RunInitialStatusScan
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,6 +14,9 @@ $installRoot = Join-Path $env:ProgramFiles "OCSentinel"
|
|||||||
$updaterPath = Join-Path $installRoot "scripts\update-ocsentinel.ps1"
|
$updaterPath = Join-Path $installRoot "scripts\update-ocsentinel.ps1"
|
||||||
$monitorPath = Join-Path $installRoot "scripts\run-ocsentinel-monitor.ps1"
|
$monitorPath = Join-Path $installRoot "scripts\run-ocsentinel-monitor.ps1"
|
||||||
$appPath = Join-Path $installRoot "app\OCSentinelCli.exe"
|
$appPath = Join-Path $installRoot "app\OCSentinelCli.exe"
|
||||||
|
$clientConfigPath = Join-Path $installRoot "config\ocsentinel-client.json"
|
||||||
|
$secretScriptPath = Join-Path $installRoot "scripts\protect-ocsentinel-secret.ps1"
|
||||||
|
$secretPath = "C:\ProgramData\OCSentinel\secrets\ocsentinel-upload-secret.dat"
|
||||||
|
|
||||||
function Assert-ArtifactSignature {
|
function Assert-ArtifactSignature {
|
||||||
param([Parameter(Mandatory)][string]$ExecutablePath)
|
param([Parameter(Mandatory)][string]$ExecutablePath)
|
||||||
@@ -80,13 +85,41 @@ if (-not (Test-Path -LiteralPath $appPath)) {
|
|||||||
throw "OCSentinel installation completed, but the client executable was not found."
|
throw "OCSentinel installation completed, but the client executable was not found."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($WebhookUrl)) {
|
||||||
|
if (-not (Test-Path -LiteralPath $clientConfigPath)) {
|
||||||
|
throw "OCSentinel client configuration was not found: $clientConfigPath"
|
||||||
|
}
|
||||||
|
|
||||||
|
$clientConfig = Get-Content -LiteralPath $clientConfigPath -Raw | ConvertFrom-Json
|
||||||
|
$clientConfig.n8nWebhookUrl = $WebhookUrl
|
||||||
|
$clientConfig.environment = "production"
|
||||||
|
$clientConfig | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $clientConfigPath -Encoding UTF8
|
||||||
|
Write-Host "Configured OCSentinel upload endpoint."
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($SecretValue)) {
|
||||||
|
if (-not (Test-Path -LiteralPath $secretScriptPath)) {
|
||||||
|
throw "OCSentinel secret bootstrap script was not found: $secretScriptPath"
|
||||||
|
}
|
||||||
|
|
||||||
|
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $secretScriptPath -SecretValue $SecretValue
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "OCSentinel secret bootstrap failed with code $LASTEXITCODE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($RunInitialStatusScan) {
|
if ($RunInitialStatusScan) {
|
||||||
if (-not (Test-Path -LiteralPath $monitorPath)) {
|
if (-not (Test-Path -LiteralPath $monitorPath)) {
|
||||||
throw "OCSentinel was installed, but the monitor script is missing."
|
throw "OCSentinel was installed, but the monitor script is missing."
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Running initial OCSentinel status scan."
|
Write-Host "Running initial OCSentinel status scan."
|
||||||
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $monitorPath -Mode status -OutputPath "..\\reports\\ocsentinel-summary.json"
|
$scanArguments = @("-NoProfile", "-ExecutionPolicy", "Bypass", "-File", $monitorPath, "-Mode", "status", "-OutputPath", "..\\reports\\ocsentinel-summary.json")
|
||||||
|
if ((Test-Path -LiteralPath $clientConfigPath) -and (Test-Path -LiteralPath $secretPath)) {
|
||||||
|
$scanArguments += @("-ClientConfigPath", $clientConfigPath, "-SecretPath", $secretPath, "-UploadMode", "required")
|
||||||
|
}
|
||||||
|
|
||||||
|
& powershell.exe @scanArguments
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
throw "Initial OCSentinel status scan exited with code $LASTEXITCODE"
|
throw "Initial OCSentinel status scan exited with code $LASTEXITCODE"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ param(
|
|||||||
[int]$TopCount = 10,
|
[int]$TopCount = 10,
|
||||||
[string]$OutputPath = ".\reports\ocsentinel-summary.json",
|
[string]$OutputPath = ".\reports\ocsentinel-summary.json",
|
||||||
[string]$ConfigPath = ".\config\ocsentinel-settings.example.json",
|
[string]$ConfigPath = ".\config\ocsentinel-settings.example.json",
|
||||||
|
[string]$ClientConfigPath = ".\config\ocsentinel-client.json",
|
||||||
|
[string]$SecretPath = "",
|
||||||
|
[ValidateSet("disabled", "auto", "required")]
|
||||||
|
[string]$UploadMode = "auto",
|
||||||
[string]$VulnerabilityCsvPath = "",
|
[string]$VulnerabilityCsvPath = "",
|
||||||
[string]$MirrorRoot = "",
|
[string]$MirrorRoot = "",
|
||||||
[ValidateSet("status", "attack-only", "cve-critical", "attack-plus-cve")]
|
[ValidateSet("status", "attack-only", "cve-critical", "attack-plus-cve")]
|
||||||
@@ -142,9 +146,15 @@ $runnerArgs = @(
|
|||||||
"-LookbackDays", $LookbackDays,
|
"-LookbackDays", $LookbackDays,
|
||||||
"-TopCount", $TopCount,
|
"-TopCount", $TopCount,
|
||||||
"-OutputPath", $OutputPath,
|
"-OutputPath", $OutputPath,
|
||||||
"-ConfigPath", $ConfigPath
|
"-ConfigPath", $ConfigPath,
|
||||||
|
"-ClientConfigPath", $ClientConfigPath,
|
||||||
|
"-UploadMode", $UploadMode
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($SecretPath)) {
|
||||||
|
$runnerArgs += @("-SecretPath", $SecretPath)
|
||||||
|
}
|
||||||
|
|
||||||
if (-not [string]::IsNullOrWhiteSpace($VulnerabilityCsvPath)) {
|
if (-not [string]::IsNullOrWhiteSpace($VulnerabilityCsvPath)) {
|
||||||
$runnerArgs += @("-VulnerabilityCsvPath", $VulnerabilityCsvPath)
|
$runnerArgs += @("-VulnerabilityCsvPath", $VulnerabilityCsvPath)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user