| 140 | } |
| 141 | |
| 142 | fn write_policy(port: u16) -> Result<NamedTempFile, String> { |
| 143 | let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?; |
| 144 | let policy = format!( |
| 145 | r#"version: 1 |
| 146 | |
| 147 | filesystem_policy: |
| 148 | include_workdir: true |
| 149 | read_only: |
| 150 | - /usr |
| 151 | - /lib |
| 152 | - /proc |
| 153 | - /dev/urandom |
| 154 | - /app |
| 155 | - /etc |
| 156 | - /var/log |
| 157 | read_write: |
| 158 | - /sandbox |
| 159 | - /tmp |
| 160 | - /dev/null |
| 161 | |
| 162 | landlock: |
| 163 | compatibility: best_effort |
| 164 | |
| 165 | process: |
| 166 | run_as_user: sandbox |
| 167 | run_as_group: sandbox |
| 168 | |
| 169 | network_policies: |
| 170 | host_echo: |
| 171 | name: host_echo |
| 172 | endpoints: |
| 173 | - host: host.openshell.internal |
| 174 | port: {port} |
| 175 | allowed_ips: |
| 176 | - "10.0.0.0/8" |
| 177 | - "172.0.0.0/8" |
| 178 | - "192.168.0.0/16" |
| 179 | - "fc00::/7" |
| 180 | binaries: |
| 181 | - path: /usr/bin/curl |
| 182 | "# |
| 183 | ); |
| 184 | file.write_all(policy.as_bytes()) |
| 185 | .map_err(|e| format!("write temp policy file: {e}"))?; |
| 186 | file.flush() |
| 187 | .map_err(|e| format!("flush temp policy file: {e}"))?; |
| 188 | Ok(file) |
| 189 | } |
| 190 | |
| 191 | #[tokio::test] |
| 192 | async fn sandbox_reaches_host_openshell_internal_via_host_gateway_alias() { |