Skip to content

Commit 9c8ffd4

Browse files
committed
test(mxc): add workload-to-host service e2e coverage
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 68d61b0 commit 9c8ffd4

7 files changed

Lines changed: 279 additions & 13 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,19 @@ variable by default). Require both a nonempty response and the OpenShell proxy
452452
CA issuer; never replace these assertions with an insecure TLS request. This
453453
fixture permits unavailable CRL information using best-effort Schannel revocation
454454
for the ephemeral private CA; this is not revocation qualification. This
455-
scenario is not part of the default six offline-capable E2E scenarios.
455+
scenario is not part of the default seven offline-capable E2E scenarios.
456+
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.
456468

457469
When reporting `windows:ci`, distinguish these categories:
458470

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ explicitly loads the boundary-injected CA bundle and records the peer certificat
270270
success requires a nonempty response and the OpenShell proxy CA issuer. It does
271271
not install a host trust root or disable CA/hostname verification. The fixture
272272
uses best-effort Schannel revocation because the ephemeral private CA has no CRL
273-
distribution point; it does not qualify revocation enforcement. The default six E2E
273+
distribution point; it does not qualify revocation enforcement. The default seven E2E
274274
scenarios remain independent of Internet access.
275275

276276
The `forwarding` scenario starts a TCP listener inside MXC, then verifies two
@@ -287,12 +287,22 @@ 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.
299+
290300
The `ws-agent.yaml` and `openclaw-gateway.yaml` policies preserve the Windows
291301
branch's workload grants. `inference.yaml` is a template: replace its filesystem,
292302
curl executable, inference host, and port placeholders before use. Authorize
293303
curl, which owns the network socket, not its cmd launcher. These policies have
294304
parser/mapper regression coverage; they do not add live WebSocket, OpenClaw,
295-
or provider-backed inference scenarios to the six-scenario E2E runner.
305+
or provider-backed inference scenarios to the seven-scenario E2E runner.
296306

297307
With `-KeepRunning`, the runner restores the caller's environment but retains
298308
the disposable CLI/runtime directory for the live gateway and prints its path.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
version: 1
4+
filesystem_policy:
5+
include_workdir: false
6+
read_only: []
7+
read_write:
8+
- "C:/work/openshell-mxc-e2e"
9+
network_policies:
10+
host_service:
11+
name: host-service
12+
endpoints:
13+
- host: '__HOST_SERVICE_IP__'
14+
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/*
22+
binaries:
23+
- path: '__CURL_EXE__'

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//! Test-only TCP fixture for real MXC ingress E2E; not a shipped runtime binary.
4+
//! Test-only TCP/HTTP fixture for real MXC E2E; not a shipped runtime binary.
55
66
use std::io::{BufRead, BufReader, Read, Write};
77
use std::net::TcpListener;
88
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 || (arguments.len() == 4 && arguments[3] == "http")) {
12+
if !(arguments.len() == 3 || (matches!(arguments.len(), 4 | 6) && arguments[3] == "http")) {
1313
return Err(std::io::Error::new(
1414
std::io::ErrorKind::InvalidInput,
15-
"usage: mxc-forwarding-agent READY_FILE NONCE [http]",
15+
"usage: mxc-forwarding-agent READY_FILE NONCE [http [BIND_IPV4 REQUEST_LOG]]",
1616
));
1717
}
18-
let http_mode = arguments.len() == 4;
19-
let listener = TcpListener::bind((std::net::Ipv4Addr::LOCALHOST, 0))?;
18+
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);
27+
if let Some(path) = request_log {
28+
std::fs::write(path, "")?;
29+
}
30+
let listener = TcpListener::bind((bind_ip, 0))?;
2031
let ready_file = std::path::Path::new(&arguments[1]);
2132
let staged_ready = ready_file.with_extension("tmp");
2233
std::fs::write(&staged_ready, listener.local_addr()?.port().to_string())?;
@@ -59,6 +70,10 @@ fn main() -> std::io::Result<()> {
5970
let target = fields.next().ok_or_else(|| {
6071
std::io::Error::new(std::io::ErrorKind::InvalidData, "missing HTTP target")
6172
})?;
73+
if let Some(path) = request_log {
74+
let mut log = std::fs::OpenOptions::new().append(true).open(path)?;
75+
writeln!(log, "{target}")?;
76+
}
6277
let body = format!("{}:{target}", arguments[2]);
6378
write!(
6479
socket,

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

Lines changed: 108 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +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.
3940
# https-ca - opt-in outbound HTTPS using the injected proxy CA.
4041

4142
[CmdletBinding()]
@@ -384,6 +385,46 @@ function Wait-File([string]$path, [int]$seconds) {
384385
return (Test-Path $path)
385386
}
386387

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+
}
399+
}
400+
throw 'host-service requires an active host IPv4 address outside loopback and link-local ranges'
401+
}
402+
403+
function Test-HostServiceResult([string]$work, [string]$nonce, [string]$requestLog) {
404+
if (-not (Wait-File (Join-Path $work 'host-service.done') 60)) { throw 'host-service workload did not complete' }
405+
if ((Get-Content -LiteralPath (Join-Path $work 'host-service.done') -Raw).Trim() -ne $nonce) {
406+
throw 'host-service completion marker does not match this workload'
407+
}
408+
foreach ($name in @('one', 'two')) {
409+
$body = Get-Content -LiteralPath (Join-Path $work "host-service.$name.body") -Raw
410+
$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"
413+
}
414+
}
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+
}
420+
$requests = @(Get-Content -LiteralPath $requestLog)
421+
if ($requests.Count -ne 3 -or $requests[0] -ne '/health' -or
422+
$requests[1] -ne '/allowed/one' -or $requests[2] -ne '/allowed/two') {
423+
throw "host-service received unexpected requests: $($requests -join ', ')"
424+
}
425+
return 'two exact host responses; denied request returned HTTP 403 and never reached the service'
426+
}
427+
387428
# Exercise the public gRPC forward path, never dial the workload port directly.
388429
# The nonce identifies this workload, not an unrelated host-loopback listener.
389430
function Test-Forwarding([string]$sandboxName, [string]$readyFile, [string]$nonce) {
@@ -610,6 +651,7 @@ function Probe-Backend([string] $backendName, [string] $wxc) {
610651

611652
$results = @()
612653
$gw = $null
654+
$hostService = $null
613655
$harnessError = $null
614656
$backendProbe = @{ Live = $false; Reason = "not probed" }
615657
# Unique per-run suffix so a stale sandbox record from an earlier run can never
@@ -750,10 +792,15 @@ try {
750792
Backends = "process_container"; Kind = "service-forwarding"
751793
ReadyFile = (Join-Path $DemoDir "service-forwarding-port.txt")
752794
Description = "named HTTP service routes two requests into MXC and stops routing after deletion"
795+
},
796+
@{
797+
Name = 'host-service'; PolicyFile = Join-Path $policyDir 'host-service.yaml'
798+
SandboxId = 'host'; Backends = 'process_container'; Kind = 'host-service'
799+
Description = 'workload HTTP egress reaches a host service only for explicitly allowed paths'
753800
}
754801
)
755802

756-
# External connectivity is deliberately opt-in; the default six scenarios
803+
# External connectivity is deliberately opt-in; the default seven scenarios
757804
# remain runnable without Internet access. Use the same authenticated
758805
# gateway launch path as every other workload, not a bare driver fixture.
759806
if ($Scenario -eq 'https-ca') {
@@ -826,6 +873,30 @@ try {
826873
$DemoDir.Replace('\', '/')
827874
)
828875
$curlExe = [IO.Path]::Combine([IO.Path]::GetDirectoryName($cmdExe), 'curl.exe')
876+
if ($sc.Kind -eq 'host-service') {
877+
$hostIp = Get-HostServiceAddress
878+
$hostNonce = [guid]::NewGuid().ToString('N')
879+
# The workload has write access only to DemoDir, not these host-side proofs.
880+
$hostReady = Join-Path $resultDir 'host-service.port'
881+
$hostRequests = Join-Path $resultDir 'host-service.requests'
882+
$fixture = Join-Path $BinaryDir 'mxc-forwarding-agent.exe'
883+
if (-not (Test-Path -LiteralPath $fixture)) { $fixture = Join-Path $BinaryDir 'examples/mxc-forwarding-agent.exe' }
884+
if (-not (Test-Path -LiteralPath $fixture)) { throw 'Missing host-service fixture; run windows:build:mxc-fixtures' }
885+
$hostArguments = @($hostReady, $hostNonce, 'http', $hostIp, $hostRequests)
886+
$hostService = Start-Process -FilePath $fixture -PassThru -WindowStyle Hidden `
887+
-ArgumentList (($hostArguments | ForEach-Object { Quote-NativeArgument $_ }) -join ' ') `
888+
-RedirectStandardOutput (Join-Path $resultDir 'host-service.stdout.log') `
889+
-RedirectStandardError (Join-Path $resultDir 'host-service.stderr.log')
890+
if (-not (Wait-File $hostReady 10) -or $hostService.HasExited) { throw 'host-service fixture did not start' }
891+
$hostPort = [int](Get-Content -LiteralPath $hostReady -Raw).Trim()
892+
$hostUrl = "http://${hostIp}:$hostPort"
893+
$health = Invoke-NativeCaptured $curlExe @('--disable', '--proxy', '', '--noproxy', '*',
894+
'--fail', '--silent', '--show-error', '--max-time', '10', "$hostUrl/health") 15
895+
if ($health.ExitCode -ne 0 -or ($health.Output -join '').Trim() -ne "${hostNonce}:/health") {
896+
throw 'host-service health check failed before sandbox launch'
897+
}
898+
$policyText = $policyText.Replace('__HOST_SERVICE_IP__', $hostIp).Replace('__HOST_SERVICE_PORT__', "$hostPort")
899+
}
829900
# Preserve the exact Windows executable path used in the launch;
830901
# network binary identities are compared as strings, not FS paths.
831902
$policyText = $policyText.Replace('__CURL_EXE__', $curlExe.Replace("'", "''"))
@@ -852,6 +923,20 @@ try {
852923
} else {
853924
$command = @($cmdExe, "/c", "echo denied 1> $denied")
854925
}
926+
} elseif ($sc.Kind -eq 'host-service') {
927+
Remove-Item -Path (Join-Path $DemoDir 'host-service.*') -Force -ErrorAction SilentlyContinue
928+
$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
939+
$command = @($cmdExe, '/d', '/c', $batch)
855940
} elseif ($sc.Kind -eq 'socket-owner') {
856941
Remove-Item -LiteralPath $sc.PosTarget, $sc.ControlTarget, $sc.ErrorTarget -Force -ErrorAction SilentlyContinue
857942
$child = 'echo launched > "{0}" && "{1}" --disable --fail --silent --show-error --max-time 30 --ssl-revoke-best-effort --cacert "%CURL_CA_BUNDLE%" --stderr "{2}" --output "{3}" https://example.com/' -f $sc.ControlTarget, $curlExe, $sc.ErrorTarget, $sc.PosTarget
@@ -916,12 +1001,13 @@ try {
9161001
# Run sandbox create; require artifact evidence for live workload tests.
9171002
$createOut = $null; $createExitCode = 0
9181003
try {
919-
$createResult = Invoke-NativeCaptured $cli @(
1004+
$createArguments = @(
9201005
"sandbox", "create", "--name", $sandboxName,
9211006
"--policy", [string]$policyUsed,
922-
"--driver-config-json", $driverConfig,
923-
"--no-tty"
1007+
"--driver-config-json", $driverConfig
9241008
)
1009+
$createArguments += if ($sc.Kind -eq 'host-service') { '--detach' } else { '--no-tty' }
1010+
$createResult = Invoke-NativeCaptured $cli $createArguments
9251011
$createOut = $createResult.Output
9261012
$createExitCode = $createResult.ExitCode
9271013
} catch {
@@ -933,7 +1019,18 @@ try {
9331019
$gwText = (Get-Content $gwLog, $gwErrLog -Raw -ErrorAction SilentlyContinue) -join "`n"
9341020

9351021
# Evaluate.
936-
if ($sc.Kind -eq 'socket-owner') {
1022+
if ($sc.Kind -eq 'host-service') {
1023+
try {
1024+
if ($createExitCode -ne 0) { throw "host-service sandbox creation failed: $createOutStr" }
1025+
if ($hostService.HasExited) { throw 'host-service fixture exited before scoring' }
1026+
$reason = Test-HostServiceResult $DemoDir $hostNonce $hostRequests
1027+
Ok "host-service: $reason"
1028+
$results += [pscustomobject]@{ Scenario = $sc.Name; Result = 'PASS'; Reason = $reason }
1029+
} catch {
1030+
Bad "host-service: $($_.Exception.Message)"
1031+
$results += [pscustomobject]@{ Scenario = $sc.Name; Result = 'FAIL'; Reason = $_.Exception.Message }
1032+
}
1033+
} elseif ($sc.Kind -eq 'socket-owner') {
9371034
try {
9381035
if (-not (Wait-File $sc.ControlTarget 30)) { throw "parent cmd did not launch: $createOutStr" }
9391036
$deadline = (Get-Date).AddSeconds(45)
@@ -1079,6 +1176,10 @@ catch {
10791176
Bad "harness error: $harnessError"
10801177
}
10811178
finally {
1179+
if ($hostService -and -not $hostService.HasExited) {
1180+
Stop-Process -Id $hostService.Id -Force -ErrorAction SilentlyContinue
1181+
$hostService.WaitForExit()
1182+
}
10821183
# --- Summary + results bundle ---------------------------------------------
10831184
Step "Summary"
10841185
$results | Format-Table -AutoSize
@@ -1121,6 +1222,8 @@ through OpenShell. Service forwarding verifies two HTTP replies and HTTP 404
11211222
after endpoint deletion. Missing coverage exits non-zero; network-policy proves
11221223
admission and execution, not network enforcement. Forwarding proves managed
11231224
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.
11241227
"@
11251228
Set-Content -Path (Join-Path $resultDir "summary.txt") -Value $summary -Encoding UTF8
11261229
Write-Host $summary -ForegroundColor ($(if ($verdict -eq "PASS") { "Green" } else { "Red" }))

0 commit comments

Comments
 (0)