Skip to content

Commit 3304b6a

Browse files
committed
Make sure the initial eth0 IP is pinned
1 parent f7c05a3 commit 3304b6a

File tree

8 files changed

+279
-50
lines changed

8 files changed

+279
-50
lines changed

flake.lock

+36-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
"nix.enableLanguageServer" = true;
3939
"nix.formatterPath" = pkgs.nixpkgs-fmt + "/bin/nixpkgs-fmt";
4040
"nix.serverPath" = pkgs.rnix-lsp + "/bin/rnix-lsp";
41+
"powershell.powerShellAdditionalExePaths" = {
42+
"PowerShell Core" = "${pkgs.powershell}/bin/pwsh";
43+
};
4144
};
4245
};
4346
jetski = pkgs.callPackage hotPot.lib.denoAppBuild
@@ -61,6 +64,7 @@
6164
inherit deno;
6265
inherit (pkgs)
6366
kubectl
67+
powershell
6468
;
6569
};
6670
in

scripts/restart_multipassd.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restart-Service -Name "Multipass"

scripts/setup_multipassd.ps1

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Set-StrictMode -Version 2
2+
$ErrorActionPreference = 'Stop'
3+
4+
try {
5+
New-VMSwitch -name MultipassSwitch -NetAdapterName Ethernet -AllowManagementOS $true
6+
}
7+
catch {
8+
if ($_.Exception.Message -notmatch "already bound") {
9+
Write-Output $_
10+
exit 1
11+
}
12+
}
13+
14+
$hostname = $env:COMPUTERNAME.ToLower()
15+
$multipassdPort = 51000
16+
$env:MULTIPASS_SERVER_ADDRESS = "$($hostname):$($multipassdPort)"
17+
Write-Output "Set MULTIPASS_SERVER_ADDRESS=$($env:MULTIPASS_SERVER_ADDRESS)"
18+
19+
$binPathValue = "C:\Program Files\Multipass\bin\multipassd.exe /svc --verbosity debug --logger stderr --address $($env:MULTIPASS_SERVER_ADDRESS)"
20+
Write-Output "Reconfiguring multipassd to binPath=$binPathValue"
21+
& 'C:\Windows\System32\sc.exe' config "Multipass" binPath= $binPathValue start= delayed-auto
22+
23+
Write-Output "Restarting multipassd"
24+
Restart-Service -Name "Multipass"
25+
26+
function Wait-ForCommand {
27+
param (
28+
[ScriptBlock]$commandScriptBlock,
29+
[int]$timeoutSeconds = 2,
30+
[int]$maxAttempts = 10
31+
)
32+
33+
$attempts = 0
34+
35+
while ($true) {
36+
$job = Start-Job -ScriptBlock $commandScriptBlock
37+
Wait-Job $job -Timeout $timeoutSeconds > $null 2>&1
38+
$result = Receive-Job $job
39+
Remove-Job -Force $job
40+
41+
if ($null -eq $result) {
42+
Write-Output "Command timed out after $timeoutSeconds seconds"
43+
}
44+
else {
45+
if ([string]$result -eq "0") {
46+
return
47+
}
48+
}
49+
50+
if ($attempts -gt $maxAttempts) {
51+
throw "Command failed to execute properly"
52+
}
53+
else {
54+
Write-Host "Still waiting for command to complete..."
55+
Start-Sleep -s 1
56+
$attempts += 1
57+
}
58+
}
59+
}
60+
61+
function Wait-ForMultipassd {
62+
param (
63+
[int]$timeoutSeconds = 2,
64+
[int]$maxAttempts = 10
65+
)
66+
Write-Output "Waiting for multipassd to start"
67+
$scriptBlock = {
68+
$version = (multipass.exe version)
69+
if ($LASTEXITCODE -eq 0 -and $version -notmatch "multipassd") {
70+
return 0
71+
}
72+
return 1
73+
}
74+
Wait-ForCommand -commandScriptBlock $scriptBlock -timeoutSeconds $timeoutSeconds -maxAttempts $maxAttempts
75+
}
76+
77+
Wait-ForMultipassd
78+
79+
# Write-Output "Setting local.passphrase"
80+
# multipass.exe set local.passphrase=foo
81+
# if ($LASTEXITCODE -ne 0) {
82+
# Write-Output "Failed to set local.passphrase"
83+
# exit $LASTEXITCODE
84+
# }
85+
86+
# Wait-ForMultipassd
87+
# Write-Output "Setting local.bridged-network"
88+
# multipass.exe set local.bridged-network=MultipassSwitch
89+
# if ($LASTEXITCODE -ne 0) {
90+
# Write-Output "Failed to set local.bridged-network"
91+
# exit $LASTEXITCODE
92+
# }
93+
94+
# # # Wait-ForMultipassd
95+
# Write-Output "Getting ethernet IP"
96+
# try {
97+
# $ethIp = (Get-NetIPAddress -InterfaceAlias "vEthernet (MultipassSwitch)" -AddressFamily IPv4).IPAddress
98+
# }
99+
# catch {
100+
# Write-Output "Failed to get ethernet IP"
101+
# Write-Output $_
102+
# exit 1
103+
# }
104+
105+
# Write-Output "Found ethernet IP: $ethIp"
106+
107+
# Write-Output "Going to add portproxy rule for $($ethIp):$($multipassdPort)"
108+
# netsh interface portproxy add v4tov4 listenport=$multipassdPort listenaddress=$ethIp connectport=$multipassdPort connectaddress=127.0.0.1
109+
# if ($LASTEXITCODE -ne 0) {
110+
# exit $LASTEXITCODE
111+
# }
112+
113+
# Write-Output "Going to add firewall rule for $($ethIp):$($multipassdPort)"
114+
# New-NetFirewallRule -DisplayName "multipassd_51000" -Direction Inbound -Protocol TCP -LocalPort $multipassdPort -Action Allow -PolicyStore PersistentStore
115+
# if ($LASTEXITCODE -ne 0) {
116+
# exit $LASTEXITCODE
117+
# }

scripts/ssh_pwsh.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
SCRIPT_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
4+
5+
NODE_ADDRESS=${1:?"The remote node address is required"}
6+
PS_SCRIPT=${2:?"The the powershell script name is required"}
7+
8+
ssh -o LogLevel=error "${NODE_ADDRESS}" powershell.exe -NoLogo -NonInteractive -Command - < "${SCRIPT_DIR}/${PS_SCRIPT}.ps1"

scripts/sshd.ps1

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Get-Service sshd | Set-Service -StartupType Automatic
2+
3+
$authorizedKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILmxihXDTbdPX7rVLKzZt6r/Qt9eZnrXCAWxCrmTOpZ6 [email protected]"
4+
Set-Content `
5+
-Force -Path $env:ProgramData\ssh\administrators_authorized_keys `
6+
-Value "$authorizedKey"
7+
8+
icacls.exe ""$env:ProgramData\ssh\administrators_authorized_keys"" /inheritance:r /grant ""Administrators:F"" /grant ""SYSTEM:F""
9+
10+
Start-Service sshd

src/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const ServerInstanceConfigSchema = Type.Object({
4040
nodeTaints: Type.Optional(Type.Record(NonEmptyString(), NonEmptyString())),
4141
sshDirectoryPath: NonEmptyString(),
4242
joinMetadataPath: Type.Optional(NonEmptyString()),
43+
userName: Type.Optional(NonEmptyString()),
44+
userPassword: Type.Optional(NonEmptyString()),
4345
});
4446

4547
export const AgentInstanceConfigSchema = Type.Object({
@@ -61,6 +63,8 @@ export const AgentInstanceConfigSchema = Type.Object({
6163
nodeTaints: Type.Optional(Type.Record(NonEmptyString(), NonEmptyString())),
6264
sshDirectoryPath: NonEmptyString(),
6365
joinMetadataPath: NonEmptyString(),
66+
userName: Type.Optional(NonEmptyString()),
67+
userPassword: Type.Optional(NonEmptyString()),
6468
});
6569

6670
export const InstanceConfigSchema = Type.Union([

0 commit comments

Comments
 (0)