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.
389430function 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}
10811178finally {
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
11211222after endpoint deletion. Missing coverage exits non-zero; network-policy proves
11221223admission and execution, not network enforcement. Forwarding proves managed
11231224ingress 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