allow injection of hostname via API
This commit is contained in:
parent
de94e74ab6
commit
3d90a7b39b
@ -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<InstallForm>) -> 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:?}")),
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ pub fn encrypt_and_install_os(
|
||||
install_url: &str,
|
||||
install_sha: &str,
|
||||
keyfile: &str,
|
||||
vm_hostname: &str,
|
||||
) -> Result<String> {
|
||||
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() {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user