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
403401function 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
12221206after endpoint deletion. Missing coverage exits non-zero; network-policy proves
12231207admission and execution, not network enforcement. Forwarding proves managed
12241208ingress 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" }))
0 commit comments