Skip to content

Commit 0378ec9

Browse files
committed
test(mxc): verify direct host localhost connectivity
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 9c8ffd4 commit 0378ec9

7 files changed

Lines changed: 60 additions & 128 deletions

File tree

‎.agents/skills/build-openshell-mxc-windows/SKILL.md‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -454,17 +454,14 @@ fixture permits unavailable CRL information using best-effort Schannel revocatio
454454
for the ephemeral private CA; this is not revocation qualification. This
455455
scenario is not part of the default seven offline-capable E2E scenarios.
456456

457-
The default `host-service` scenario runs the HTTP fixture on an active host LAN
458-
IPv4 address and a dynamic port, then checks two nonce-bound replies from curl
459-
inside MXC through the authenticated proxy. Its `/32` allowlist and explicit
460-
GET paths permit only the intended service; a denied path must yield HTTP 403
461-
(curl exit 22) and never reach the host request log. Host-side readiness and
462-
request proofs stay outside the workload's writable directory. The service is
463-
stopped even after failed runs. Use `-Scenario host-service` for focused checks.
464-
No Internet access or firewall modification is required; an absent usable host
465-
IPv4 address or failed host health check is a failure, not a successful denial.
466-
Loopback remains blocked by the shared proxy, so do not broaden SSRF controls
467-
to run this test.
457+
The default `host-service` scenario runs the HTTP fixture on host `127.0.0.1`
458+
and a dynamic port, then checks two nonce-bound replies from direct curl requests
459+
inside MXC. Host-side readiness and request proofs stay outside the workload's
460+
writable directory. The service is stopped even after failed runs. Use
461+
`-Scenario host-service` for focused checks. No Internet access, LAN address, or
462+
firewall modification is required. A failed host health check or workload
463+
request fails the test. This verifies direct localhost connectivity; retain
464+
the existing shared proxy SSRF controls.
468465

469466
When reporting `windows:ci`, distinguish these categories:
470467

‎crates/openshell-driver-mxc/README.md‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,12 @@ unique GET responses through gateway host-based routing. It deletes the endpoint
287287
and requires HTTP 404 afterward. Requests connect only to the gateway with the
288288
exposed URL's Host header, so no wildcard DNS setup is required.
289289

290-
The default `host-service` scenario runs an HTTP fixture on the Windows host's
291-
active LAN IPv4 address and a dynamic port. A real MXC workload uses curl through
292-
the authenticated supervisor proxy, with that exact address allowed by a `/32`
293-
policy. Two GETs must return the fixture's nonce; a disallowed path must return
294-
HTTP 403 with curl exit 22 and never appear in the host-side request log. The
295-
host service is checked before launch and stopped after testing. Missing host
296-
IPv4 connectivity fails the scenario. This uses the host's LAN address because
297-
the shared proxy always rejects loopback destinations. Select it with
298-
`-Scenario host-service`; no Internet access or firewall changes are required.
290+
The default `host-service` scenario runs an HTTP fixture on host `127.0.0.1`
291+
and a dynamic port. A real MXC workload makes two direct curl requests; both
292+
must return the fixture's nonce and appear in its host-side request log. The
293+
host service is checked before launch and stopped after testing. Select it with
294+
`-Scenario host-service`; no Internet access, LAN address, or firewall changes
295+
are required. This verifies direct localhost connectivity.
299296

300297
The `ws-agent.yaml` and `openclaw-gateway.yaml` policies preserve the Windows
301298
branch's workload grants. `inference.yaml` is a template: replace its filesystem,

‎crates/openshell-driver-mxc/examples/e2e-policies/host-service.yaml‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ network_policies:
1010
host_service:
1111
name: host-service
1212
endpoints:
13-
- host: '__HOST_SERVICE_IP__'
13+
- host: 127.0.0.1
1414
port: __HOST_SERVICE_PORT__
15-
allowed_ips: ['__HOST_SERVICE_IP__/32']
16-
protocol: rest
17-
enforcement: enforce
18-
rules:
19-
- allow:
20-
method: GET
21-
path: /allowed/*
2215
binaries:
2316
- path: '__CURL_EXE__'

‎crates/openshell-driver-mxc/examples/mxc-forwarding-agent.rs‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,18 @@ use std::time::Duration;
99

1010
fn main() -> std::io::Result<()> {
1111
let arguments: Vec<String> = std::env::args().collect();
12-
if !(arguments.len() == 3 || (matches!(arguments.len(), 4 | 6) && arguments[3] == "http")) {
12+
if !(arguments.len() == 3 || (matches!(arguments.len(), 4 | 5) && arguments[3] == "http")) {
1313
return Err(std::io::Error::new(
1414
std::io::ErrorKind::InvalidInput,
15-
"usage: mxc-forwarding-agent READY_FILE NONCE [http [BIND_IPV4 REQUEST_LOG]]",
15+
"usage: mxc-forwarding-agent READY_FILE NONCE [http [REQUEST_LOG]]",
1616
));
1717
}
1818
let http_mode = arguments.len() >= 4;
19-
let bind_ip = if arguments.len() == 6 {
20-
arguments[4]
21-
.parse::<std::net::Ipv4Addr>()
22-
.map_err(|error| std::io::Error::new(std::io::ErrorKind::InvalidInput, error))?
23-
} else {
24-
std::net::Ipv4Addr::LOCALHOST
25-
};
26-
let request_log = arguments.get(5);
19+
let request_log = arguments.get(4);
2720
if let Some(path) = request_log {
2821
std::fs::write(path, "")?;
2922
}
30-
let listener = TcpListener::bind((bind_ip, 0))?;
23+
let listener = TcpListener::bind((std::net::Ipv4Addr::LOCALHOST, 0))?;
3124
let ready_file = std::path::Path::new(&arguments[1]);
3225
let staged_ready = ready_file.with_extension("tmp");
3326
std::fs::write(&staged_ready, listener.local_addr()?.port().to_string())?;

‎crates/openshell-driver-mxc/examples/run-mxc-e2e.ps1‎

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
# network-policy - supervisor-owned network policy permits admission.
3737
# forwarding - two TCP request/reply exchanges through OpenShell ingress.
3838
# service-forwarding - named HTTP service routing and endpoint deletion.
39-
# host-service - workload reaches a host HTTP service; denied path never arrives.
39+
# host-service - workload reaches an HTTP service on host 127.0.0.1.
4040
# https-ca - opt-in outbound HTTPS using the injected proxy CA.
4141

4242
[CmdletBinding()]
@@ -385,19 +385,17 @@ function Wait-File([string]$path, [int]$seconds) {
385385
return (Test-Path $path)
386386
}
387387

388-
function Get-HostServiceAddress {
389-
foreach ($adapter in [Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()) {
390-
if ($adapter.OperationalStatus -ne [Net.NetworkInformation.OperationalStatus]::Up) { continue }
391-
foreach ($unicast in $adapter.GetIPProperties().UnicastAddresses) {
392-
$ip = $unicast.Address
393-
if ($ip.AddressFamily -eq [Net.Sockets.AddressFamily]::InterNetwork -and
394-
-not [Net.IPAddress]::IsLoopback($ip) -and
395-
-not $ip.ToString().StartsWith('169.254.') -and $ip.ToString() -ne '0.0.0.0') {
396-
return $ip.ToString()
397-
}
398-
}
388+
function Write-HostServiceBatch([string]$batch, [string]$curlExe, [string]$hostUrl, [string]$work, [string]$nonce) {
389+
$lines = @('@echo off')
390+
foreach ($name in @('one', 'two')) {
391+
$lines += '"{0}" --disable --proxy "" --noproxy "*" --fail --silent --show-error --max-time 15 --output "{1}" "{2}/{3}"' -f $curlExe, (Join-Path $work "host-service.$name.body"), $hostUrl, $name
392+
# A space before > prevents echo 0>file from redirecting stdin instead
393+
# of recording curl's success code. Scoring trims the trailing space.
394+
$lines += 'echo %errorlevel% > "{0}"' -f (Join-Path $work "host-service.$name.exit")
399395
}
400-
throw 'host-service requires an active host IPv4 address outside loopback and link-local ranges'
396+
$lines += 'echo {0}> "{1}"' -f $nonce, (Join-Path $work 'host-service.done')
397+
$lines += 'exit /b 0'
398+
Set-Content -LiteralPath $batch -Value ($lines -join "`r`n") -Encoding ASCII
401399
}
402400

403401
function Test-HostServiceResult([string]$work, [string]$nonce, [string]$requestLog) {
@@ -408,21 +406,16 @@ function Test-HostServiceResult([string]$work, [string]$nonce, [string]$requestL
408406
foreach ($name in @('one', 'two')) {
409407
$body = Get-Content -LiteralPath (Join-Path $work "host-service.$name.body") -Raw
410408
$exitCode = (Get-Content -LiteralPath (Join-Path $work "host-service.$name.exit") -Raw).Trim()
411-
if ($exitCode -ne '0' -or $body -ne "${nonce}:/allowed/$name") {
412-
throw "host-service allowed request $name did not return the exact host response"
409+
if ($exitCode -ne '0' -or $body -ne "${nonce}:/$name") {
410+
throw "host-service request $name did not return the exact host response"
413411
}
414412
}
415-
$deniedExit = (Get-Content -LiteralPath (Join-Path $work 'host-service.denied.exit') -Raw).Trim()
416-
$deniedStatus = (Get-Content -LiteralPath (Join-Path $work 'host-service.denied.status') -Raw).Trim()
417-
if ($deniedExit -ne '22' -or $deniedStatus -ne '403') {
418-
throw "host-service denied request must receive policy HTTP 403 (curl exit 22), got $deniedStatus / $deniedExit"
419-
}
420413
$requests = @(Get-Content -LiteralPath $requestLog)
421414
if ($requests.Count -ne 3 -or $requests[0] -ne '/health' -or
422-
$requests[1] -ne '/allowed/one' -or $requests[2] -ne '/allowed/two') {
415+
$requests[1] -ne '/one' -or $requests[2] -ne '/two') {
423416
throw "host-service received unexpected requests: $($requests -join ', ')"
424417
}
425-
return 'two exact host responses; denied request returned HTTP 403 and never reached the service'
418+
return 'two exact responses from the host service on 127.0.0.1'
426419
}
427420

428421
# Exercise the public gRPC forward path, never dial the workload port directly.
@@ -796,7 +789,7 @@ try {
796789
@{
797790
Name = 'host-service'; PolicyFile = Join-Path $policyDir 'host-service.yaml'
798791
SandboxId = 'host'; Backends = 'process_container'; Kind = 'host-service'
799-
Description = 'workload HTTP egress reaches a host service only for explicitly allowed paths'
792+
Description = 'workload connects directly to an HTTP service on host 127.0.0.1'
800793
}
801794
)
802795

@@ -874,15 +867,15 @@ try {
874867
)
875868
$curlExe = [IO.Path]::Combine([IO.Path]::GetDirectoryName($cmdExe), 'curl.exe')
876869
if ($sc.Kind -eq 'host-service') {
877-
$hostIp = Get-HostServiceAddress
870+
$hostIp = '127.0.0.1'
878871
$hostNonce = [guid]::NewGuid().ToString('N')
879872
# The workload has write access only to DemoDir, not these host-side proofs.
880873
$hostReady = Join-Path $resultDir 'host-service.port'
881874
$hostRequests = Join-Path $resultDir 'host-service.requests'
882875
$fixture = Join-Path $BinaryDir 'mxc-forwarding-agent.exe'
883876
if (-not (Test-Path -LiteralPath $fixture)) { $fixture = Join-Path $BinaryDir 'examples/mxc-forwarding-agent.exe' }
884877
if (-not (Test-Path -LiteralPath $fixture)) { throw 'Missing host-service fixture; run windows:build:mxc-fixtures' }
885-
$hostArguments = @($hostReady, $hostNonce, 'http', $hostIp, $hostRequests)
878+
$hostArguments = @($hostReady, $hostNonce, 'http', $hostRequests)
886879
$hostService = Start-Process -FilePath $fixture -PassThru -WindowStyle Hidden `
887880
-ArgumentList (($hostArguments | ForEach-Object { Quote-NativeArgument $_ }) -join ' ') `
888881
-RedirectStandardOutput (Join-Path $resultDir 'host-service.stdout.log') `
@@ -895,7 +888,7 @@ try {
895888
if ($health.ExitCode -ne 0 -or ($health.Output -join '').Trim() -ne "${hostNonce}:/health") {
896889
throw 'host-service health check failed before sandbox launch'
897890
}
898-
$policyText = $policyText.Replace('__HOST_SERVICE_IP__', $hostIp).Replace('__HOST_SERVICE_PORT__', "$hostPort")
891+
$policyText = $policyText.Replace('__HOST_SERVICE_PORT__', "$hostPort")
899892
}
900893
# Preserve the exact Windows executable path used in the launch;
901894
# network binary identities are compared as strings, not FS paths.
@@ -926,16 +919,7 @@ try {
926919
} elseif ($sc.Kind -eq 'host-service') {
927920
Remove-Item -Path (Join-Path $DemoDir 'host-service.*') -Force -ErrorAction SilentlyContinue
928921
$batch = Join-Path $DemoDir 'host-service.cmd'
929-
$lines = @('@echo off')
930-
foreach ($name in @('one', 'two')) {
931-
$lines += '"{0}" --disable --proxy "%HTTP_PROXY%" --noproxy "" --fail --silent --show-error --max-time 15 --output "{1}" "{2}/allowed/{3}"' -f $curlExe, (Join-Path $DemoDir "host-service.$name.body"), $hostUrl, $name
932-
$lines += 'echo %errorlevel%> "{0}"' -f (Join-Path $DemoDir "host-service.$name.exit")
933-
}
934-
$lines += '"{0}" --disable --proxy "%HTTP_PROXY%" --noproxy "" --fail --silent --show-error --max-time 15 --output "{1}" --write-out "%%{{http_code}}" "{2}/denied" > "{3}"' -f $curlExe, (Join-Path $DemoDir 'host-service.denied.body'), $hostUrl, (Join-Path $DemoDir 'host-service.denied.status')
935-
$lines += 'echo %errorlevel%> "{0}"' -f (Join-Path $DemoDir 'host-service.denied.exit')
936-
$lines += 'echo {0}> "{1}"' -f $hostNonce, (Join-Path $DemoDir 'host-service.done')
937-
$lines += 'exit /b 0'
938-
Set-Content -LiteralPath $batch -Value ($lines -join "`r`n") -Encoding ASCII
922+
Write-HostServiceBatch $batch $curlExe $hostUrl $DemoDir $hostNonce
939923
$command = @($cmdExe, '/d', '/c', $batch)
940924
} elseif ($sc.Kind -eq 'socket-owner') {
941925
Remove-Item -LiteralPath $sc.PosTarget, $sc.ControlTarget, $sc.ErrorTarget -Force -ErrorAction SilentlyContinue
@@ -1222,8 +1206,8 @@ through OpenShell. Service forwarding verifies two HTTP replies and HTTP 404
12221206
after endpoint deletion. Missing coverage exits non-zero; network-policy proves
12231207
admission and execution, not network enforcement. Forwarding proves managed
12241208
ingress works, not that direct host ingress is blocked.
1225-
Host-service verifies two exact workload-to-host HTTP replies and HTTP 403 for
1226-
a denied path, with a host-side request log proving that denied request never arrived.
1209+
Host-service verifies two exact direct HTTP replies from a service bound to
1210+
host 127.0.0.1, with host-side request evidence. It checks localhost connectivity.
12271211
"@
12281212
Set-Content -Path (Join-Path $resultDir "summary.txt") -Value $summary -Encoding UTF8
12291213
Write-Host $summary -ForegroundColor ($(if ($verdict -eq "PASS") { "Green" } else { "Red" }))

‎crates/openshell-driver-mxc/tests/windows_demo_examples.rs‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn https_fixture_authorizes_direct_curl_with_read_only_https() {
6767
}
6868

6969
#[test]
70-
fn host_service_scoring_rejects_transport_failures_and_unenforced_requests() {
70+
fn host_service_scoring_records_success_and_rejects_false_responses() {
7171
let root = tempfile::tempdir().unwrap();
7272
let script = r#"
7373
$ErrorActionPreference = 'Stop'
@@ -76,7 +76,7 @@ $tokens = $null; $errors = $null
7676
$ast = [System.Management.Automation.Language.Parser]::ParseFile(
7777
$env:OPENSHELL_MXC_RUNNER, [ref]$tokens, [ref]$errors)
7878
if ($errors.Count) { throw "runner parse errors: $($errors.Message -join '; ')" }
79-
foreach ($name in @('Wait-File', 'Test-HostServiceResult')) {
79+
foreach ($name in @('Quote-NativeArgument', 'Invoke-NativeCaptured', 'Wait-File', 'Write-HostServiceBatch', 'Test-HostServiceResult')) {
8080
$helper = $ast.Find({ param($node)
8181
$node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -eq $name
8282
}, $true)
@@ -87,26 +87,34 @@ $work = Join-Path $env:OPENSHELL_MXC_SCORE_ROOT 'work with spaces'
8787
New-Item -ItemType Directory $work | Out-Null
8888
$requestLog = Join-Path $env:OPENSHELL_MXC_SCORE_ROOT 'host.requests'
8989
$nonce = 'unique-host-service-response'
90+
$batch = Join-Path $work 'host-service.cmd'
91+
Write-HostServiceBatch $batch 'C:/Windows/System32/curl.exe' 'http://127.0.0.1:49152' $work $nonce
92+
$recordLine = @(Get-Content -LiteralPath $batch | Where-Object { $_.StartsWith('echo %errorlevel%') })[0]
93+
foreach ($code in @(0, 22)) {
94+
$probeBatch = Join-Path $work 'record-exit.cmd'
95+
Set-Content -LiteralPath $probeBatch -Encoding ASCII -Value ("@echo off`r`ncmd.exe /d /c exit $code`r`n$recordLine`r`nexit /b 0")
96+
$result = Invoke-NativeCaptured 'cmd.exe' @('/d', '/c', $probeBatch) 10
97+
if ($result.ExitCode -ne 0) { throw "batch exit probe failed: $($result.Output -join '; ')" }
98+
$recorded = Get-Content -LiteralPath (Join-Path $work 'host-service.one.exit') -Raw
99+
if (!$recorded -or $recorded.Trim() -ne "$code") { throw "generated batch failed to record curl exit $code" }
100+
}
90101
function Reset-Proofs {
91102
foreach ($name in @('one', 'two')) {
92-
[IO.File]::WriteAllText((Join-Path $work "host-service.$name.body"), "${nonce}:/allowed/$name")
103+
[IO.File]::WriteAllText((Join-Path $work "host-service.$name.body"), "${nonce}:/$name")
93104
[IO.File]::WriteAllText((Join-Path $work "host-service.$name.exit"), '0')
94105
}
95-
[IO.File]::WriteAllText((Join-Path $work 'host-service.denied.exit'), '22')
96-
[IO.File]::WriteAllText((Join-Path $work 'host-service.denied.status'), '403')
97106
[IO.File]::WriteAllText((Join-Path $work 'host-service.done'), $nonce)
98-
[IO.File]::WriteAllText($requestLog, "/health`n/allowed/one`n/allowed/two`n")
107+
[IO.File]::WriteAllText($requestLog, "/health`n/one`n/two`n")
99108
}
100109
Reset-Proofs
101-
if ((Test-HostServiceResult $work $nonce $requestLog) -notmatch 'never reached') { throw 'valid host-service run must pass' }
102-
foreach ($case in @('transport', 'denial-reached-host', 'wrong-response', 'wrong-workload')) {
110+
if ((Test-HostServiceResult $work $nonce $requestLog) -notmatch '127.0.0.1') { throw 'valid host-service run must pass' }
111+
foreach ($case in @('transport', 'unexpected-request', 'wrong-response', 'wrong-workload')) {
103112
Reset-Proofs
104113
switch ($case) {
105114
'transport' {
106-
[IO.File]::WriteAllText((Join-Path $work 'host-service.denied.exit'), '7')
107-
[IO.File]::WriteAllText((Join-Path $work 'host-service.denied.status'), '000')
115+
[IO.File]::WriteAllText((Join-Path $work 'host-service.one.exit'), '7')
108116
}
109-
'denial-reached-host' { [IO.File]::AppendAllText($requestLog, "/denied`n") }
117+
'unexpected-request' { [IO.File]::AppendAllText($requestLog, "/unexpected`n") }
110118
'wrong-response' { [IO.File]::WriteAllText((Join-Path $work 'host-service.one.body'), 'unrelated service') }
111119
'wrong-workload' { [IO.File]::WriteAllText((Join-Path $work 'host-service.done'), 'stale-run') }
112120
}

‎crates/openshell-supervisor-network/src/opa.rs‎

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5291,46 +5291,6 @@ process:
52915291
OpaEngine::from_strings(TEST_POLICY, L7_TEST_DATA).expect("Failed to load L7 test data")
52925292
}
52935293

5294-
#[test]
5295-
fn mxc_host_service_fixture_enforces_paths_and_socket_owner() {
5296-
let binary = crate::test_support::executable_path("/usr/bin/curl");
5297-
let yaml =
5298-
include_str!("../../openshell-driver-mxc/examples/e2e-policies/host-service.yaml")
5299-
.replace("__HOST_SERVICE_IP__", "192.168.1.20")
5300-
.replace("__HOST_SERVICE_PORT__", "49152")
5301-
.replace(
5302-
"C:/work/openshell-mxc-e2e",
5303-
&std::env::temp_dir().to_string_lossy().replace('\\', "/"),
5304-
)
5305-
.replace("__CURL_EXE__", binary.to_str().unwrap());
5306-
let engine = OpaEngine::from_strings(TEST_POLICY, &yaml).expect("host-service policy");
5307-
let network = NetworkInput {
5308-
host: "192.168.1.20".into(),
5309-
port: 49152,
5310-
binary_path: binary.clone(),
5311-
binary_sha256: "unused".into(),
5312-
ancestors: Vec::new(),
5313-
cmdline_paths: Vec::new(),
5314-
};
5315-
assert!(engine.evaluate_network(&network).unwrap().allowed);
5316-
assert_eq!(
5317-
engine.query_allowed_ips(&network).unwrap(),
5318-
["192.168.1.20/32"]
5319-
);
5320-
for (path, allowed) in [
5321-
("/allowed/one", true),
5322-
("/allowed/two", true),
5323-
("/denied", false),
5324-
] {
5325-
let mut input = l7_input("192.168.1.20", 49152, "GET", path);
5326-
input["exec"]["path"] = binary.to_str().unwrap().into();
5327-
assert_eq!(eval_l7(&engine, &input), allowed, "{path}");
5328-
}
5329-
let mut wrong_binary = network;
5330-
wrong_binary.binary_path = crate::test_support::executable_path("/usr/bin/other");
5331-
assert!(!engine.evaluate_network(&wrong_binary).unwrap().allowed);
5332-
}
5333-
53345294
fn l7_input(host: &str, port: u16, method: &str, path: &str) -> serde_json::Value {
53355295
l7_input_with_query(host, port, method, path, serde_json::json!({}))
53365296
}

0 commit comments

Comments
 (0)