(
overlay_disk: &Path,
dropins: &[GuestInitDropin],
)
| 4676 | |
| 4677 | #[allow(clippy::result_large_err)] |
| 4678 | fn inject_guest_init_dropins( |
| 4679 | overlay_disk: &Path, |
| 4680 | dropins: &[GuestInitDropin], |
| 4681 | ) -> Result<(), Status> { |
| 4682 | validate_guest_init_dropins(dropins).map_err(Status::failed_precondition)?; |
| 4683 | |
| 4684 | // Drop-ins are *executed* in a child shell by run_openshell_init_dropins |
| 4685 | // in the guest init script, not sourced into the parent. Mode 0o755 is |
| 4686 | // required (the runner skips anything that is not `-x`) and is the |
| 4687 | // contract drop-in authors should rely on. |
| 4688 | for dropin in dropins { |
| 4689 | let guest_path = overlay_upper_path(&format!("{GUEST_INIT_DROPIN_DIR}/{}", dropin.name)); |
| 4690 | write_rootfs_image_file(overlay_disk, &guest_path, &dropin.contents).map_err(|err| { |
| 4691 | Status::internal(format!( |
| 4692 | "write VM guest init drop-in '{}' failed: {err}", |
| 4693 | dropin.name |
| 4694 | )) |
| 4695 | })?; |
| 4696 | set_rootfs_image_file_mode(overlay_disk, &guest_path, 0o755).map_err(|err| { |
| 4697 | Status::internal(format!( |
| 4698 | "set VM guest init drop-in '{}' executable failed: {err}", |
| 4699 | dropin.name |
| 4700 | )) |
| 4701 | })?; |
| 4702 | } |
| 4703 | |
| 4704 | // Write the allow-list manifest the guest runner consults. We write it |
| 4705 | // unconditionally — including an empty manifest when no drop-ins were |
| 4706 | // injected — so the guest always fails closed: only names the driver |
| 4707 | // explicitly injected this launch are eligible to run, and a guest |
| 4708 | // image cannot smuggle in extra `init.d` entries. |
| 4709 | write_guest_init_dropin_manifest(overlay_disk, dropins)?; |
| 4710 | Ok(()) |
| 4711 | } |
| 4712 | |
| 4713 | /// Render the drop-in allow-list as newline-separated, ASCII-sorted, |
| 4714 | /// de-duplicated names. Names are already validated to be path-safe by |
no test coverage detected