Configure upload during Ninja bootstrap
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$ManifestUrl = "https://gitea.officecom.cloud/officecom/oc-sentinel/raw/main/release/stable/version.json",
|
||||
[string]$WebhookUrl = "",
|
||||
[string]$SecretValue = "",
|
||||
[switch]$RunInitialStatusScan
|
||||
)
|
||||
|
||||
@@ -12,6 +14,9 @@ $installRoot = Join-Path $env:ProgramFiles "OCSentinel"
|
||||
$updaterPath = Join-Path $installRoot "scripts\update-ocsentinel.ps1"
|
||||
$monitorPath = Join-Path $installRoot "scripts\run-ocsentinel-monitor.ps1"
|
||||
$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 {
|
||||
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."
|
||||
}
|
||||
|
||||
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 (-not (Test-Path -LiteralPath $monitorPath)) {
|
||||
throw "OCSentinel was installed, but the monitor script is missing."
|
||||
}
|
||||
|
||||
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) {
|
||||
throw "Initial OCSentinel status scan exited with code $LASTEXITCODE"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user