feat(windows): WireGuard client, auto-VPN, IAM, tray enrichment, installer, CI

Second milestone of the Windows parity work (DESIGN-WINDOWS.md §13).

WireGuard mesh client (signed, WSS-delivered):
- wireguard_apply / wireguard_remove commands: Ed25519-verified, gated on a new
  wireguard capability. Linux applies via wg-quick up/down; Windows installs the
  peer config as a WireGuardTunnel service via wireguard.exe
  (/installtunnelservice, /uninstalltunnelservice)
- state polling in the home monitor drives the blue tray icon and auto-VPN:
  connect when away from home + auto_vpn, disconnect on return (2m cooldown)
- tray VPN toggle and the auto-VPN checkbox are now live; the preference
  persists to agent.yml (PersistAutoVPN)

IAM on Windows (iam_windows.go):
- allowed_login_groups -> net localgroup; ssh_keys -> per-profile
  authorized_keys + %ProgramData%\ssh\administrators_authorized_keys;
  revoke_users -> helper logs off all of the user's WTS sessions;
  sudo_rules logged as no direct equivalent

Tray enrichment:
- Open Config (opens agent.yml), Clear enrollment (re-enroll) menu items
- set_auto_vpn persists; vpn_connect/vpn_disconnect/reinit/open_config commands
  handled by the daemon (tray_server.go)

Packaging & release:
- installer/windows/installer.iss: fully-offline Inno Setup bundle (agent,
  tray, helper, vendor-signed WireGuard MSI, OpenCredential CP, VC++ redist),
  /SILENT /SERVER_URL /JOIN_KEY parameters, SYSTEM service + HKLM Run tray
  autostart, Users-writable %ProgramData%\Theta42 for the IPC socket
- .github/workflows/build-windows.yml: build + test, pinned vendor downloads,
  ISCC compile, Azure Trusted Signing (OIDC), SHA256SUMS, GH release attach,
  optional SSO resource publish
- agent.yml.example documents auto_vpn, wireguard, service_name,
  desktop_helper, public_ip_detect

Tests:
- wireguard_apply/remove dispatch (allowed + capability-denied), PersistAutoVPN,
  ClearEnrollment; dispatch tests pin linuxPlatformOps with a temp WireGuard conf
- end-to-end verified against a local mock SSO on Windows: join-key enrollment
  (token persisted, join key blanked), discovery/telemetry pushed, signed
  arbitrary_bash verified + executed via powershell -EncodedCommand; tray IPC
  socket binds %ProgramData%\Theta42; LDAP byte-pump binds 127.0.0.1:389;
  helper update swap verified

Rebuilds all tracked dist binaries (v2.1.0).
This commit is contained in:
2026-08-09 17:49:40 -07:00
parent 4a619f7adc
commit e613874de5
29 changed files with 920 additions and 22 deletions
+109
View File
@@ -23,6 +23,7 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
"unicode/utf16"
@@ -34,6 +35,9 @@ type windowsPlatformOps struct {
exec Executor
helperPath string // theta-agent-helper.exe (DESIGN-WINDOWS.md §8)
serviceName string // Windows service name (defaults to theta-agent)
tunnelName string // WireGuard tunnel/service name
confPath string // persisted peer config path
wgExe string // wireguard.exe client path ("" = PATH lookup)
}
func (p *windowsPlatformOps) Reboot() ([]byte, error) {
@@ -176,6 +180,111 @@ func (p *windowsPlatformOps) SelfRestart() {
stopAgent()
}
// wireGuardExe resolves the WireGuard client executable: explicit config path,
// PATH lookup, or the default install location.
func (p *windowsPlatformOps) wireGuardExe() string {
if p.wgExe != "" {
return p.wgExe
}
const defaultInstall = `C:\Program Files\WireGuard\wireguard.exe`
if _, err := os.Stat(defaultInstall); err == nil {
return defaultInstall
}
return "wireguard.exe"
}
// ApplyWireGuard persists the peer config and installs it as a WireGuard
// service via the official client (wireguard.exe /installtunnelservice).
func (p *windowsPlatformOps) ApplyWireGuard(conf string) error {
if err := os.MkdirAll(filepath.Dir(p.confPath), 0700); err != nil {
return fmt.Errorf("wireguard: create config dir: %w", err)
}
if err := os.WriteFile(p.confPath, []byte(conf), 0600); err != nil {
return fmt.Errorf("wireguard: persist config: %w", err)
}
out, err := p.exec.Execute(p.wireGuardExe(), "/installtunnelservice", p.tunnelName, p.confPath)
if err != nil {
return fmt.Errorf("wireguard: installtunnelservice %s: %v: %s", p.tunnelName, err, out)
}
return nil
}
func (p *windowsPlatformOps) RemoveWireGuard() error {
out, err := p.exec.Execute(p.wireGuardExe(), "/uninstalltunnelservice", p.tunnelName)
if err != nil {
return fmt.Errorf("wireguard: uninstalltunnelservice %s: %v: %s", p.tunnelName, err, out)
}
return nil
}
// WireGuardState reports whether the WireGuardTunnel$<name> service is running.
func (p *windowsPlatformOps) WireGuardState() bool {
out, err := p.exec.Execute("sc.exe", "query", "WireGuardTunnel$"+p.tunnelName)
if err != nil {
return false
}
return strings.Contains(strings.ToUpper(string(out)), "RUNNING")
}
// ConnectWireGuard brings the persisted config up unless already active.
func (p *windowsPlatformOps) ConnectWireGuard() error {
if p.WireGuardState() {
return nil
}
conf, err := os.ReadFile(p.confPath)
if err != nil {
return fmt.Errorf("wireguard: no persisted config at %s: %w", p.confPath, err)
}
return p.ApplyWireGuard(string(conf))
}
func (p *windowsPlatformOps) DisconnectWireGuard() error {
if !p.WireGuardState() {
return nil
}
return p.RemoveWireGuard()
}
// ApplyIAM maps node identity onto local Windows security (DESIGN-WINDOWS.md
// §4): local groups for allowed_login_groups, per-user authorized_keys for
// OpenSSH, and session logoff via the helper for revocation.
func (p *windowsPlatformOps) ApplyIAM(payload IAMPayload) error {
ac := payload.AccessControl
for _, g := range ac.AllowedLoginGroups {
if g == "" {
continue
}
if _, err := p.exec.Execute("net", "localgroup", g, "/add"); err != nil {
log.Printf("[iam] net localgroup %s /add: %v", g, err)
}
}
if len(ac.SSHKeys) > 0 {
if err := applyWindowsSSHKeys(ac.SSHKeys); err != nil {
log.Printf("[iam] ssh keys: %v", err)
}
}
for _, u := range ac.RevokeUsers {
if u == "" {
continue
}
if p.helperPath != "" {
if _, err := p.exec.Execute(p.helperPath, "logout", u); err != nil {
log.Printf("[iam] revoke %s: %v", u, err)
}
} else {
log.Printf("[iam] revoke %s: desktop_helper not configured; no sessions logged off", u)
}
}
if len(ac.SudoRules) > 0 {
log.Println("[iam] sudo_rules have no direct Windows equivalent; mapped to local group membership (UAC elevation policy)")
}
return nil
}
// spawnDetached launches exe as a background process that survives this one.
func spawnDetached(exe string, args ...string) error {
cmd := execCommand(exe, args...)