Open a bounded Windows maintenance window from the operator console
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#requires -Version 5.1
|
||||
#requires -RunAsAdministrator
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)][DateTimeOffset]$PreviousExpiry,
|
||||
[Parameter(Mandatory)][DateTimeOffset]$Until
|
||||
)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$utcNow = [DateTimeOffset]::UtcNow
|
||||
if ($PreviousExpiry -ge $utcNow -or $Until -le $utcNow -or $Until -gt $utcNow.AddHours(4)) {
|
||||
throw 'Expected an expired previous window and a new deadline within four hours.'
|
||||
}
|
||||
$dir = 'C:\ProgramData\RmmDevAccess'
|
||||
$configPath = Join-Path $dir 'bootstrap-public.json'
|
||||
$raw = [IO.File]::ReadAllText($configPath)
|
||||
$cfg = $raw | ConvertFrom-Json
|
||||
$user = Get-LocalUser -Name 'rmm-dev'
|
||||
$task = Get-ScheduledTask -TaskPath '\' -TaskName 'RmmDevReverseTunnel'
|
||||
if ($task.State -ne 'Ready' -or !$user.Enabled -or !$user.AccountExpires -or
|
||||
$user.AccountExpires.ToUniversalTime() -ne $PreviousExpiry.UtcDateTime -or
|
||||
[DateTimeOffset]::Parse($cfg.expires_at) -ne $PreviousExpiry -or
|
||||
$cfg.server -cne 'discovery.ease-technologies.de' -or (Get-Service sshd).Status -ne 'Running') {
|
||||
throw 'Unexpected account, task, server or previous expiry.'
|
||||
}
|
||||
$pinned = (Get-Content -LiteralPath (Join-Path $dir 'known_hosts') -Raw).Trim()
|
||||
if ($pinned -cne ('discovery.ease-technologies.de ' + $cfg.server_host_key)) {
|
||||
throw 'Unexpected SSH host pin.'
|
||||
}
|
||||
$listeners = @(Get-NetTCPConnection -State Listen -LocalPort 22222)
|
||||
if ($listeners.Count -ne 1 -or $listeners[0].LocalAddress -ne '127.0.0.1') {
|
||||
throw 'Expected only the original loopback SSH listener.'
|
||||
}
|
||||
$backup = Join-Path $dir ('console-window-' + [guid]::NewGuid().ToString() + '.bak')
|
||||
$candidate = $backup + '.new'
|
||||
$cfg.expires_at = $Until.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:sszzz')
|
||||
[IO.File]::WriteAllText($candidate, ($cfg | ConvertTo-Json -Compress), (New-Object Text.UTF8Encoding($false)))
|
||||
$sshArgs = @('-F','NUL','-N','-T','-o','BatchMode=yes','-o','IdentitiesOnly=yes',
|
||||
'-o','ForwardAgent=no','-o','StrictHostKeyChecking=yes','-o','GlobalKnownHostsFile=NUL',
|
||||
'-o',('UserKnownHostsFile=' + $dir + '\known_hosts'),'-o','ExitOnForwardFailure=yes',
|
||||
'-o','ConnectTimeout=10','-o','ServerAliveInterval=15','-o','ServerAliveCountMax=2',
|
||||
'-i',($dir + '\tunnel_ed25519'),'-R','127.0.0.1:22240:127.0.0.1:22222',
|
||||
'rmm-win-tunnel@discovery.ease-technologies.de')
|
||||
$ssh = $null
|
||||
$disabled = $false
|
||||
$accountChanged = $false
|
||||
try {
|
||||
Disable-ScheduledTask -InputObject $task | Out-Null
|
||||
$disabled = $true
|
||||
if ((Get-ScheduledTask -TaskPath '\' -TaskName $task.TaskName).State -ne 'Disabled' -or
|
||||
[IO.File]::ReadAllText($configPath) -cne $raw) { throw 'Existing bootstrap changed.' }
|
||||
[IO.File]::Replace($candidate, $configPath, $backup)
|
||||
Set-LocalUser -SID $user.SID -AccountExpires $Until.LocalDateTime
|
||||
$accountChanged = $true
|
||||
if ((Get-LocalUser -SID $user.SID).AccountExpires.ToUniversalTime() -ne $Until.UtcDateTime) {
|
||||
throw 'Unexpected account expiry after renewal.'
|
||||
}
|
||||
$ssh = Start-Process -FilePath "$env:WINDIR\System32\OpenSSH\ssh.exe" -ArgumentList $sshArgs -PassThru -NoNewWindow
|
||||
if ($ssh.WaitForExit(1500)) { throw "SSH exited with code $($ssh.ExitCode)." }
|
||||
Write-Host "Tunnelfenster gestartet bis $($Until.LocalDateTime). Zum Beenden Strg+C druecken."
|
||||
while ([DateTimeOffset]::UtcNow -lt $Until) {
|
||||
if ($ssh.WaitForExit(500)) { throw "SSH exited with code $($ssh.ExitCode)." }
|
||||
}
|
||||
} finally {
|
||||
if ($null -ne $ssh) {
|
||||
try { if (!$ssh.HasExited) { $ssh.Kill(); $ssh.WaitForExit() } } finally { $ssh.Dispose() }
|
||||
}
|
||||
if ($accountChanged) { Set-LocalUser -SID $user.SID -AccountExpires $PreviousExpiry.LocalDateTime }
|
||||
if (Test-Path -LiteralPath $backup) { [IO.File]::Replace($backup, $configPath, ($backup + '.closed')) }
|
||||
if ($disabled -and [IO.File]::ReadAllText($configPath) -ceq $raw) { Enable-ScheduledTask -InputObject $task | Out-Null }
|
||||
if (Test-Path -LiteralPath $candidate) { Remove-Item -LiteralPath $candidate }
|
||||
}
|
||||
@@ -260,3 +260,23 @@ Ausgabe und expliziten Root-/SYSTEM-Ausführungsrechten gelegt. Paketabnahmen
|
||||
sind nachgeordnet. Der erneuerte SSH-Bootstrapzugang verleiht selbst keine
|
||||
RMM-Ausführungsrechte und ersetzt keine dieser noch separat nachzuweisenden
|
||||
Genehmigungs- und Ausführungsgrenzen.
|
||||
|
||||
## Manuelles Wartungsfenster am 15. November 2026
|
||||
|
||||
Der Server bestätigte die abgelaufene Freigabe vom 15. November um 13:05:58 UTC.
|
||||
Für die Windows-Entwicklung wurde die Frist desselben Forwarding-Schlüssels auf
|
||||
15:30:00 UTC (16:30 Uhr MEZ) gesetzt. Ein separater SSH-Lesezugriff bestätigte
|
||||
Frist, Hostpin, Schlüsselbindung, SSH-Profil und Konto. Der Port ist serverseitig
|
||||
an Loopback gebunden. Ein einmaliger, aktiver Servertimer für 15:30:00 UTC
|
||||
begrenzt auch eine noch offene Weiterleitung des dedizierten Tunnelkontos dieser
|
||||
Schlüsselgeneration. Das tatsächliche Auslösen des Timers steht noch aus.
|
||||
|
||||
Die Bedienperson öffnet das Fenster in der VM-Konsole mit
|
||||
`deploy/windows/Open-ConsoleMaintenanceWindow.ps1`; Parameter sind
|
||||
`-PreviousExpiry '2026-11-15T13:05:58+00:00' -Until '2026-11-15T15:30:00+00:00'`.
|
||||
Während der einmaligen SSH-Verbindung pausiert das Skript den vorhandenen
|
||||
Autostarttask. Bei normalem Ende oder Strg+C beendet es den Client und stellt die
|
||||
vorherigen Fristen und den Task wieder her. Bei hartem Abbruch oder VM-Ausfall
|
||||
den Zustand über die Konsole prüfen. Lokales PowerShell-Parsing bestanden.
|
||||
VM-Ausführung, SSH-Readback und Dienstwechsel stehen bei Veröffentlichung aus.
|
||||
Die WebUI-Freigabe für Agentjobs gilt weiterhin.
|
||||
|
||||
Reference in New Issue
Block a user