(host: &str, port: u16)
| 251 | } |
| 252 | |
| 253 | fn 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 | |
| 258 | filesystem_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 | |
| 273 | landlock: |
| 274 | compatibility: best_effort |
| 275 | |
| 276 | process: |
| 277 | run_as_user: sandbox |
| 278 | run_as_group: sandbox |
| 279 | |
| 280 | network_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 | |
| 308 | fn websocket_client_script(host: &str, port: u16) -> String { |
| 309 | format!( |
no test coverage detected