diff --git a/dtrfs_api/src/main.rs b/dtrfs_api/src/main.rs index 42260f3..9506b77 100644 --- a/dtrfs_api/src/main.rs +++ b/dtrfs_api/src/main.rs @@ -84,6 +84,7 @@ async fn get_report() -> HttpResponse { #[derive(Deserialize)] struct InstallForm { + hostname: String, url: String, sha: String, keyfile: String, @@ -95,7 +96,7 @@ async fn post_install_form(req: HttpRequest, form: web::Form) -> Ht if let Err(e) = verify(&req) { return HttpResponse::BadRequest().body(format!("Signature verification failed: {}", e)); }; - match os::encrypt_and_install_os(&form.url, &form.sha, &form.keyfile) { + match os::encrypt_and_install_os(&form.url, &form.sha, &form.keyfile, &form.hostname) { Ok(s) => HttpResponse::Ok().body(s), Err(e) => HttpResponse::InternalServerError().body(format!("{e:?}")), } diff --git a/dtrfs_api/src/os.rs b/dtrfs_api/src/os.rs index f46b975..9c196cd 100644 --- a/dtrfs_api/src/os.rs +++ b/dtrfs_api/src/os.rs @@ -15,6 +15,7 @@ pub fn encrypt_and_install_os( install_url: &str, install_sha: &str, keyfile: &str, + vm_hostname: &str, ) -> Result { let binary_keyfile = BASE64_URL_SAFE.decode(keyfile)?; std::fs::write(BACKUP_KEYFILE_PATH, binary_keyfile)?; @@ -24,6 +25,7 @@ pub fn encrypt_and_install_os( .env("INSTALL_SHA", install_sha) .env("SNP_KEY_FILE", SNP_KEYFILE_PATH) .env("ROOT_KEYFILE", BACKUP_KEYFILE_PATH) + .env("VM_HOSTNAME", vm_hostname) .output()?; if !install_result.status.success() { diff --git a/scripts/install_os.sh b/scripts/install_os.sh index 77d5c6d..d53e52a 100755 --- a/scripts/install_os.sh +++ b/scripts/install_os.sh @@ -7,11 +7,16 @@ exit 1 } -[[ -z "$INSTALL_URL" ]] && { +[[ -z "$INSTALL_SHA" ]] && { echo "Did not find INSTALL_SHA env variable". exit 2 } +[[ -z "$VM_HOSTNAME" ]] && { + echo "Did not find VM_HOSTNAME env variable". + exit 2 +} + [[ -f "$ROOT_KEYFILE" ]] || { echo "Did not find keyfile at the following location: $ROOT_KEYFILE" exit 3 @@ -55,9 +60,8 @@ fsarchiver restdir /mnt/template.fsa / rm /mnt/template.fsa # TODO: decide for UX if maybe we should allow user to inject fstab echo "" > /mnt/etc/fstab -hostname=$(cat /proc/cmdline | grep -oE 'detee_name=[0-9a-z\_\.\-]+' | cut -d '=' -f2) -echo "=== Setting up guest hostname as $hostname" -[[ -n "$hostname" ]] && echo $hostname > /mnt/etc/hostname +echo "=== Setting up guest hostname as $VM_HOSTNAME" +echo $VM_HOSTNAME > /mnt/etc/hostname echo "=== Generating SSH public keys" echo "root:x:0:0:root:/root:/bin/sh" > /etc/passwd