Add reproducible LAN-only RDP access on Helium

This commit is contained in:
cabbage committed 2026-10-08 14:26:52 +00:00
1 parent 90d6b05f4d
commit 34274f0f62
9 files changed
+452 -1

No files matched your search

+76
View File
@@ -2,6 +2,7 @@ package windowsnative
import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
@@ -84,6 +85,81 @@ func TestNativeFixtureAssets_HP_HARNESS_20(t *testing.T) {
}
}
func TestLANRelayAssets_HP_HARNESS_22(t *testing.T) {
t.Parallel()
root := filepath.Clean(filepath.Join("..", ".."))
read := func(relative string) string {
t.Helper()
data, err := os.ReadFile(filepath.Join(root, relative))
if err != nil {
t.Fatal(err)
}
return string(data)
}
helper := read("test/rdp-access/lan-access")
for _, required := range []string{"assert_owned", "requested backend port does not belong to this VM", "VM UUID mismatch", "saved VM UUID mismatch", "interface subnet extends outside private", "ip -4 route get", "unrelated listener", "compose down --remove-orphans", "rmdir \"$dir\"", "attempt\" -le 4", "one console slot"} {
if !strings.Contains(helper, required) {
t.Fatalf("LAN helper is missing safety/lifecycle contract %q", required)
}
}
for _, prohibited := range []string{"controlvm", "modifyvm", "docker system prune", "rm -rf", "--privileged", "sudo "} {
if strings.Contains(helper, prohibited) {
t.Fatalf("LAN helper unexpectedly contains %q", prohibited)
}
}
compose := read("test/rdp-access/compose-lan.yaml")
for _, required := range []string{"alpine/socat@sha256:", "network_mode: host", "bind=${LAN_BIND},range=${LAN_CIDR}", "TCP4:127.0.0.1:${VRDE_PORT}", "read_only: true", "cap_drop: [ALL]", "65534:65534", "mem_limit: 32m", "rvbox.rdp.lan.vm_uuid"} {
if !strings.Contains(compose, required) {
t.Fatalf("LAN relay Compose asset is missing %q", required)
}
}
entrypoint := read("test/rdp-access/rdp-access")
if !strings.Contains(entrypoint, "lan-up|lan-status|lan-down|lan-clean") || !strings.Contains(entrypoint, "--lan) expose_lan=true") {
t.Fatal("LAN lifecycle is not exposed through the existing RDP helper")
}
}
func TestLANRelayRejectsUnsafeOptions_BH_HARNESS_22(t *testing.T) {
t.Parallel()
root := filepath.Clean(filepath.Join("..", ".."))
// Any accidental attempt to reach SSH must fail locally and be detectable.
fakeBin := t.TempDir()
if err := os.WriteFile(filepath.Join(fakeBin, "ssh"), []byte("#!/bin/sh\necho UNEXPECTED_SSH_ATTEMPT >&2\nexit 99\n"), 0700); err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
name string
args []string
}{
{"wildcard", []string{"--lan-bind", "0.0.0.0"}},
{"loopback", []string{"--lan-bind", "127.0.0.1"}},
{"public", []string{"--lan-bind", "8.8.8.8"}},
{"invalid_octet", []string{"--lan-bind", "192.168.50.999"}},
{"shell_injection", []string{"--lan-bind", "192.168.50.1;id"}},
{"high_port", []string{"--lan-port", "65536"}},
{"privileged_port", []string{"--lan-port", "22"}},
{"wide_192_subnet", []string{"--lan-cidr", "192.168.50.0/8"}},
{"wide_172_subnet", []string{"--lan-cidr", "172.20.0.0/8"}},
{"public_subnet", []string{"--lan-cidr", "0.0.0.0/0"}},
{"profile_traversal", []string{"--profile", "../other"}},
{"remote_root_traversal", nil},
{"images_on_up", []string{"--images"}},
} {
t.Run(tc.name, func(t *testing.T) {
args := append([]string{filepath.Join(root, "test/rdp-access/rdp-access"), "lan-up"}, tc.args...)
cmd := exec.Command("sh", args...)
cmd.Env = append(os.Environ(), "PATH="+fakeBin+":"+os.Getenv("PATH"), "RDP_ACCESS_PROFILE=default", "RDP_ACCESS_LAN_BIND=auto", "RDP_ACCESS_LAN_CIDR=auto", "RDP_ACCESS_LAN_PORT=3389")
if tc.name == "remote_root_traversal" {
cmd.Env = append(cmd.Env, "RDP_ACCESS_LAN_REMOTE_ROOT=/home/cabbage/.local/state/../other")
}
output, err := cmd.CombinedOutput()
if err == nil || !strings.Contains(string(output), "lan-access:") || strings.Contains(string(output), "UNEXPECTED_SSH_ATTEMPT") {
t.Fatalf("unsafe input was not rejected before SSH: error=%v output=%s", err, output)
}
})
}
}
// Static safety contracts complement the live Windows device/GUI checks.
func TestMouseFilterRecoveryAssets_HP_HARNESS_21(t *testing.T) {
t.Parallel()