@@ -14,18 +14,17 @@ use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
1414use tokio:: net:: { TcpListener , TcpStream } ;
1515use tokio:: task:: JoinHandle ;
1616
17- /// The Python test image's virtual environment , which links to a uv-managed
18- /// Python under `/sandbox/.uv/python`.
19- const VENV_PYTHON : & str = "/sandbox/.venv/bin/python3" ;
20-
21- /// Prints the interpreter's prefix, then requests `/` from
22- /// ` host.openshell.internal` on the port in `argv[1]` and prints the
23- /// response. A failed connection is retried for 20 seconds, so a slow
24- /// start doesn't fail the test, and reported on stderr.
17+ /// The image's system Python , which needs nothing beyond its standard library.
18+ /// The policy names its real path, `/usr/bin/python3.*`, because a rule matches
19+ /// the executable behind a symlink.
20+ const PYTHON : & str = "/usr/bin/python3" ;
21+
22+ /// Requests `/` from ` host.openshell.internal` on the port in `argv[1]` and
23+ /// prints the response. A failed connection is retried for 20 seconds, so a
24+ /// slow start doesn't fail the test, and reported on stderr.
2525const CLIENT : & str = r#"
2626import socket, sys, time
2727
28- print(f"prefix={sys.prefix}", flush=True)
2928host, port = "host.openshell.internal", int(sys.argv[1])
3029deadline = time.monotonic() + 20
3130while True:
@@ -46,9 +45,9 @@ print(response.decode(errors="replace"))
4645"# ;
4746
4847/// A sandbox from the Python test image resolves `host.openshell.internal`
49- /// and gets a response from a server the test runs on the host. The image's
50- /// virtual environment runs the client , so its workspace content reached the
51- /// sandbox, and the policy lets only that Python reach the server's port.
48+ /// and gets a response from a server the test runs on the host. The default
49+ /// policy denies all network access , so the test passes one that lets only the
50+ /// image's Python reach the server's port.
5251#[ testkit:: test]
5352async fn python_sandbox_reaches_host_server ( cx : & mut Context ) -> testkit:: Result {
5453 let marker = format ! ( "host-gateway-{}" , cx. run_id( ) ) ;
@@ -87,25 +86,11 @@ async fn python_sandbox_reaches_host_server(cx: &mut Context) -> testkit::Result
8786
8887 let client = cx
8988 . cli ( [
90- "sandbox" ,
91- "exec" ,
92- "--name" ,
93- & name,
94- "--no-tty" ,
95- "--" ,
96- VENV_PYTHON ,
97- "-c" ,
98- CLIENT ,
99- & port,
89+ "sandbox" , "exec" , "--name" , & name, "--no-tty" , "--" , PYTHON , "-c" , CLIENT , & port,
10090 ] )
10191 . await ?
10292 . success ( )
10393 . context ( "run the client in the sandbox" ) ?;
104- testkit:: ensure!(
105- client. stdout. contains( "prefix=/sandbox/.venv" ) ,
106- "the client did not run in the image's virtual environment:\n {}" ,
107- client. stdout
108- ) ;
10994 testkit:: ensure!(
11095 client. stdout. contains( & marker) ,
11196 "the client did not get the host server's response:\n {}{}" ,
@@ -115,11 +100,10 @@ async fn python_sandbox_reaches_host_server(cx: &mut Context) -> testkit::Result
115100 Ok ( ( ) )
116101}
117102
118- /// A sandbox policy for the Python test image that allows its uv-managed
119- /// Python, which [`VENV_PYTHON`] links to, to connect to
120- /// `host.openshell.internal` on `port`. The endpoint names only the host and
121- /// port, as the policy docs describe, so the driver's address for the name
122- /// is what makes it reachable, not an `allowed_ips` range.
103+ /// A sandbox policy that allows the image's system Python ([`PYTHON`]) to
104+ /// connect to `host.openshell.internal` on `port`. The endpoint names only the
105+ /// host and port, as the policy docs describe, so the driver's address for the
106+ /// name is what makes it reachable, not an `allowed_ips` range.
123107fn policy ( port : u16 ) -> String {
124108 format ! (
125109 r#"version: 1
@@ -142,7 +126,7 @@ network_policies:
142126 - host: host.openshell.internal
143127 port: {port}
144128 binaries:
145- - path: /sandbox/.uv/python/**/python *
129+ - path: /usr/bin/python3. *
146130"#
147131 )
148132}
0 commit comments