fix(agent99): bind host112 apply to immutable receipt

This commit is contained in:
ogt
2026-07-14 11:54:05 +08:00
parent 316605df87
commit d7a17e58b2
8 changed files with 766 additions and 61 deletions

View File

@@ -41,6 +41,46 @@ function Copy-AgentFile {
}
}
function Set-AgentBootstrapProperty {
param([object]$Object, [string]$Name, [object]$Value)
if ($Object.PSObject.Properties[$Name]) {
$Object.PSObject.Properties[$Name].Value = $Value
} else {
$Object | Add-Member -MemberType NoteProperty -Name $Name -Value $Value
}
}
function Ensure-AgentHost112CanonicalSshConfig {
param([string]$Path)
$config = Get-Content $Path -Raw | ConvertFrom-Json
if (-not $config.PSObject.Properties["sshIdentityFile"] -or -not $config.sshIdentityFile) {
Set-AgentBootstrapProperty $config "sshIdentityFile" (Join-Path $AgentRoot "keys\agent99_ed25519")
}
if (-not $config.PSObject.Properties["sshUsers"] -or $null -eq $config.sshUsers) {
Set-AgentBootstrapProperty $config "sshUsers" ([pscustomobject]@{})
}
Set-AgentBootstrapProperty $config.sshUsers "192.168.0.112" "kali"
if (-not $config.PSObject.Properties["k3s"] -or $null -eq $config.k3s) {
Set-AgentBootstrapProperty $config "k3s" ([pscustomobject]@{})
}
if (-not $config.k3s.PSObject.Properties["jumpHost"] -or -not $config.k3s.jumpHost) {
Set-AgentBootstrapProperty $config.k3s "jumpHost" "192.168.0.110"
}
if (-not $config.k3s.PSObject.Properties["preferJumpHost"]) {
Set-AgentBootstrapProperty $config.k3s "preferJumpHost" $true
}
$directHosts = if ($config.k3s.PSObject.Properties["directHosts"]) { @($config.k3s.directHosts | ForEach-Object { [string]$_ } | Where-Object { $_ }) } else { @() }
Set-AgentBootstrapProperty $config.k3s "directHosts" @($directHosts + @("192.168.0.110", "192.168.0.112") | Select-Object -Unique)
$config | ConvertTo-Json -Depth 20 | Set-Content -Encoding UTF8 $Path
$persisted = Get-Content $Path -Raw | ConvertFrom-Json
$persistedUser = if ($persisted.sshUsers -and $persisted.sshUsers.PSObject.Properties["192.168.0.112"]) { [string]$persisted.sshUsers.PSObject.Properties["192.168.0.112"].Value } else { "" }
$persistedDirectHosts = if ($persisted.k3s -and $persisted.k3s.PSObject.Properties["directHosts"]) { @($persisted.k3s.directHosts | ForEach-Object { [string]$_ }) } else { @() }
if ($persistedUser -ne "kali" -or "192.168.0.112" -notin $persistedDirectHosts) {
throw "Host112 canonical direct SSH config bootstrap verifier failed."
}
}
$agentFiles = @(
"agent99-bootstrap.ps1",
"agent99-contract-check.ps1",
@@ -122,10 +162,17 @@ if (-not (Test-Path $configPath)) {
"agentName": "Agent99",
"agentRoot": "$($AgentRoot.Replace('\', '\\'))",
"sshUser": "wooo",
"sshUsers": {},
"sshIdentityFile": "$($AgentRoot.Replace('\', '\\'))\\keys\\agent99_ed25519",
"sshUsers": { "192.168.0.112": "kali" },
"sshTransport": { "serialized": true, "lockTimeoutSeconds": 90, "lockPollMilliseconds": 200 },
"vmrunPath": "",
"hosts": ["192.168.0.110", "192.168.0.112", "192.168.0.120", "192.168.0.121", "192.168.0.188"],
"vms": [],
"k3s": {
"jumpHost": "192.168.0.110",
"preferJumpHost": true,
"directHosts": ["192.168.0.110", "192.168.0.112"]
},
"publicUrls": ["awoooi.wooo.work", "stock.wooo.work", "2026fifa.wooo.work", "gitea.wooo.work", "harbor.wooo.work"],
"sreAlertRelay": {
"enabled": true,
@@ -182,6 +229,8 @@ if (-not (Test-Path $configPath)) {
}
}
Ensure-AgentHost112CanonicalSshConfig $configPath
$launcher = Join-Path $AgentRoot "agent99-run.ps1"
@"
param(