public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server 2/4] api/cli: add enroll-efi-keys endpoint
Date: Tue, 18 Nov 2025 13:34:40 +0100	[thread overview]
Message-ID: <20251118123516.112546-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20251118123516.112546-1-f.ebner@proxmox.com>

A new enroll-efi-keys API endpoint and command for qm is added. It
enrolls the latest known-to-be-important certificates to the EFI disk,
which currently is just the Microsoft UEFI CA 2023.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/API2/Qemu.pm | 60 ++++++++++++++++++++++++++++++++++++++++++++
 src/PVE/CLI/qm.pm    |  2 ++
 2 files changed, 62 insertions(+)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 5cdba4bb..665afbe2 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -7048,4 +7048,64 @@ __PACKAGE__->register_method({
     },
 });
 
+__PACKAGE__->register_method({
+    name => 'enroll-efi-keys',
+    path => '{vmid}/enroll-efi-keys',
+    method => 'POST',
+    protected => 1,
+    proxyto => 'node',
+    description =>
+        "Enroll important updated certificates to the EFI disk with pre-enrolled-keys. Currently,"
+        . " this is only the Microsoft UEFI CA 2023. Must be called while the VM is shut down.",
+    permissions => {
+        check => ['perm', '/vms/{vmid}', ['VM.Config.Disk']],
+    },
+    parameters => {
+        additionalProperties => 0,
+        properties => {
+            node => get_standard_option('pve-node'),
+            vmid =>
+                get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
+        },
+    },
+    returns => { type => 'null' },
+    code => sub {
+        my ($param) = @_;
+
+        my $vmid = extract_param($param, 'vmid');
+
+        my $enroll_fn = sub {
+            my $conf = PVE::QemuConfig->load_config($vmid);
+
+            PVE::QemuConfig->check_lock($conf);
+            die "VM $vmid is running\n" if PVE::QemuServer::Helpers::vm_running_locally($vmid);
+            die "VM $vmid is a template\n" if PVE::QemuConfig->is_template($conf);
+            die "VM $vmid has no EFI disk configured\n" if !$conf->{efidisk0};
+
+            my $ostype = $conf->{ostype};
+            if (!defined($ostype) || ($ostype ne 'win10' && $ostype ne 'win11')) {
+                print "skipping - OS type is neither Windows 10 nor Windows 11\n";
+                return;
+            }
+
+            my $storecfg = PVE::Storage::config();
+
+            my $updated = PVE::QemuServer::OVMF::ensure_ms_2023_cert_enrolled(
+                $storecfg, $vmid, $conf->{efidisk0},
+            );
+            if ($updated) {
+                $conf->{efidisk0} = $updated;
+                PVE::QemuConfig->write_config($vmid, $conf);
+            } else {
+                print "skipping - no pre-enrolled keys or already got ms-cert=2023 marker\n";
+            }
+
+            return;
+        };
+
+        PVE::QemuConfig->lock_config($vmid, $enroll_fn);
+        return;
+    },
+});
+
 1;
diff --git a/src/PVE/CLI/qm.pm b/src/PVE/CLI/qm.pm
index 9398780e..d0f80b20 100755
--- a/src/PVE/CLI/qm.pm
+++ b/src/PVE/CLI/qm.pm
@@ -1341,6 +1341,8 @@ our $cmddef = {
         unlink => ["PVE::API2::Qemu", 'unlink', ['vmid'], {%node}],
     },
 
+    'enroll-efi-keys' => ["PVE::API2::Qemu", 'enroll-efi-keys', ['vmid'], {%node}],
+
     monitor => [__PACKAGE__, 'monitor', ['vmid']],
 
     agent => { alias => 'guest cmd' }, # FIXME: remove with PVE 8.0
-- 
2.47.3



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-11-18 12:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18 12:34 [pve-devel] [PATCH-SERIS qemu-server 0/4] vm start: ovmf: do not auto-enroll Microsoft UEFI CA 2023 Fiona Ebner
2025-11-18 12:34 ` [pve-devel] [PATCH qemu-server 1/4] ovmf: enroll ms 2023 cert: change QSD ID to allow calling outside of VM start Fiona Ebner
2025-11-18 12:34 ` Fiona Ebner [this message]
2025-11-18 12:58   ` [pve-devel] [PATCH qemu-server 2/4] api/cli: add enroll-efi-keys endpoint Fabian Grünbichler
2025-11-18 13:07     ` Thomas Lamprecht
2025-11-18 13:09       ` Fabian Grünbichler
2025-11-18 14:11         ` Thomas Lamprecht
2025-11-18 12:34 ` [pve-devel] [PATCH qemu-server 3/4] ovmf: factor out helper for checking whether MS 2023 certificate should be enrolled Fiona Ebner
2025-11-18 12:34 ` [pve-devel] [PATCH qemu-server 4/4] vm start: ovmf: do not auto-enroll Microsoft UEFI CA 2023 Fiona Ebner
2025-11-18 13:30 ` [pve-devel] [PATCH-SERIS qemu-server 0/4] " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251118123516.112546-3-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal