(&self, disk_crypt_key: &str, name: &str)
| 1247 | } |
| 1248 | |
| 1249 | fn open_encrypted_volume(&self, disk_crypt_key: &str, name: &str) -> Result<()> { |
| 1250 | let root_hd = &self.args.device; |
| 1251 | let disk_crypt_key = disk_crypt_key.trim(); |
| 1252 | // Create a private tmpfs mount to ensure the header stays in-memory. |
| 1253 | let tmp_hdr_dir = "/tmp/dstack-luks-header"; |
| 1254 | let in_mem_hdr = format!("{tmp_hdr_dir}/luks-header"); |
| 1255 | defer! { |
| 1256 | // Ensure cleanup of header file and tmpfs mount. |
| 1257 | cmd! { |
| 1258 | info "Cleaning up in-memory LUKS header"; |
| 1259 | rm -f $in_mem_hdr; |
| 1260 | umount $tmp_hdr_dir; |
| 1261 | rmdir $tmp_hdr_dir; |
| 1262 | }.ok(); |
| 1263 | } |
| 1264 | cmd! { |
| 1265 | info "Mounting tmpfs for in-memory LUKS header"; |
| 1266 | mkdir -p $tmp_hdr_dir; |
| 1267 | mount -t tmpfs -o size=64M,mode=0700,nosuid,nodev,noexec tmpfs $tmp_hdr_dir; |
| 1268 | info "Loading the LUKS2 header"; |
| 1269 | cryptsetup luksHeaderBackup --header-backup-file=$in_mem_hdr $root_hd; |
| 1270 | } |
| 1271 | .context("Failed to load LUKS2 header")?; |
| 1272 | |
| 1273 | let hdr_file = fs::File::open(&in_mem_hdr).context("Failed to open LUKS2 header")?; |
| 1274 | validate_luks2_headers(hdr_file).context("Failed to validate LUKS2 header")?; |
| 1275 | |
| 1276 | cmd! { |
| 1277 | info "Opening the device"; |
| 1278 | echo -n $disk_crypt_key | cryptsetup luksOpen --type luks2 --header $in_mem_hdr -d- $root_hd $name; |
| 1279 | } |
| 1280 | .or(Err(anyhow!("Failed to open encrypted data disk")))?; |
| 1281 | |
| 1282 | // Wait for device mapper to create the device |
| 1283 | let dm_path = format!("/dev/mapper/{name}"); |
| 1284 | for i in 0..10 { |
| 1285 | if std::path::Path::new(&dm_path).exists() { |
| 1286 | info!("Device mapper {} is ready", dm_path); |
| 1287 | break; |
| 1288 | } |
| 1289 | if i == 9 { |
| 1290 | bail!("Timed out waiting for device mapper {}", dm_path); |
| 1291 | } |
| 1292 | info!("Waiting for device mapper {}...", dm_path); |
| 1293 | std::thread::sleep(std::time::Duration::from_millis(500)); |
| 1294 | } |
| 1295 | Ok(()) |
| 1296 | } |
| 1297 | |
| 1298 | fn measure_app_info(&self) -> Result<AppInfo> { |
| 1299 | let compose_hash = sha256_file(self.shared.dir.app_compose_file())?; |
no test coverage detected