MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / write_websocket_policy

Function write_websocket_policy

e2e/rust/tests/websocket_conformance.rs:253–306  ·  view source on GitHub ↗
(host: &str, port: u16)

Source from the content-addressed store, hash-verified

251}
252
253fn write_websocket_policy(host: &str, port: u16) -> Result<NamedTempFile, String> {
254 let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?;
255 let policy = format!(
256 r#"version: 1
257
258filesystem_policy:
259 include_workdir: true
260 read_only:
261 - /usr
262 - /lib
263 - /proc
264 - /dev/urandom
265 - /app
266 - /etc
267 - /var/log
268 read_write:
269 - /sandbox
270 - /tmp
271 - /dev/null
272
273landlock:
274 compatibility: best_effort
275
276process:
277 run_as_user: sandbox
278 run_as_group: sandbox
279
280network_policies:
281 websocket_conformance:
282 name: websocket_conformance
283 endpoints:
284 - host: {host}
285 port: {port}
286 protocol: websocket
287 enforcement: enforce
288 access: read-write
289 websocket_credential_rewrite: true
290 allowed_ips:
291 - "10.0.0.0/8"
292 - "172.0.0.0/8"
293 - "192.168.0.0/16"
294 - "fc00::/7"
295 binaries:
296 - path: /usr/bin/python*
297 - path: /usr/local/bin/python*
298 - path: /sandbox/.uv/python/*/bin/python*
299"#
300 );
301 file.write_all(policy.as_bytes())
302 .map_err(|e| format!("write temp policy file: {e}"))?;
303 file.flush()
304 .map_err(|e| format!("flush temp policy file: {e}"))?;
305 Ok(file)
306}
307
308fn websocket_client_script(host: &str, port: u16) -> String {
309 format!(

Calls 1

flushMethod · 0.45

Tested by

no test coverage detected