all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH qemu-server/pve-manager 0/2] fix #7100: allow disabling cloud-init /etc/hosts management
@ 2026-11-24 21:26 negineri
  2026-11-24 21:26 ` [PATCH qemu-server 1/2] fix #7100: cloud-init: make /etc/hosts management configurable negineri
  2026-11-24 21:26 ` [PATCH pve-manager 2/2] fix #7100: ui: cloud-init: allow configuring /etc/hosts management negineri
  0 siblings, 2 replies; 3+ messages in thread
From: negineri @ 2026-11-24 21:26 UTC (permalink / raw)
  To: pve-devel

Proxmox VE writes manage_etc_hosts: true in its generated cloud-init user
data. This can overwrite /etc/hosts during provisioning, before a guest
administrator has a chance to configure it. Bug #7100 asks for a way to
opt out through the GUI or API before first boot, without supplying a
custom user-data file:

https://bugzilla.proxmox.com/show_bug.cgi?id=7100

The series adds the per-VM boolean cimanagehosts. It defaults to enabled
to preserve existing VM behavior. For a VM with a cloud-init disk, set it
to 0 before boot and regenerate the image:

    qm set <vmid> --cimanagehosts 0
    qm cloudinit update <vmid>

This writes manage_etc_hosts: false explicitly. Deleting the option
restores the default. Custom user data continues to take precedence.

Apply the qemu-server patch first. It registers the option, requires
VM.Config.Cloudinit to change it, and reports zero correctly in the
cloud-init image diff. The pve-manager patch then exposes the option in
the Cloud-Init panel, with the same permission for editing and removal.

On a Debian 13 test VM with qemu-server 9.2.22 and pve-manager 9.2.38,
the generated NoCloud and ConfigDrive2 images contained the expected
values. A nested Debian guest with cloud-init 25.1.4 kept a manual
/etc/hosts entry across a reboot with the option disabled. After it was
enabled and the image regenerated, cloud-init replaced the file using
its template. I also compared the image diff transitions and checked
the Edit and Remove buttons under Cloudinit, Audit and Network roles
in Chrome.

On the rebased series (qemu-server base 6a0c35f5 and pve-manager
base 75610602), both packages built with make deb and tests enabled.
The qemu-server API and cloud-init tests passed, including the five
new image diff cases, and pve-manager passed make -C www check.

I used an AI coding assistant to prepare and test these changes.

qemu-server
 src/PVE/API2/Qemu.pm                     |  9 ++---
 src/PVE/QemuServer.pm                    |  6 ++++
 src/PVE/QemuServer/Cloudinit.pm          |  3 +-
 src/test/run_api_cloudinit_dump_tests.pl | 42 ++++++++++++++++++++++++

pve-manager
 www/manager6/qemu/CloudInit.js | 22 ++++++++++++++++++++++

 5 files changed, 77 insertions(+), 5 deletions(-) in total



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH qemu-server 1/2] fix #7100: cloud-init: make /etc/hosts management configurable
  2026-11-24 21:26 [PATCH qemu-server/pve-manager 0/2] fix #7100: allow disabling cloud-init /etc/hosts management negineri
@ 2026-11-24 21:26 ` negineri
  2026-11-24 21:26 ` [PATCH pve-manager 2/2] fix #7100: ui: cloud-init: allow configuring /etc/hosts management negineri
  1 sibling, 0 replies; 3+ messages in thread
From: negineri @ 2026-11-24 21:26 UTC (permalink / raw)
  To: pve-devel

Add the cimanagehosts boolean option to control manage_etc_hosts in
generated cloud-config user data. Keep the default enabled to preserve
the behavior of existing guests, and emit false explicitly when
disabled.

Register the option for VM.Config.Cloudinit permission checks. The
cloud-init schema also includes it in pending image changes and
generated option documentation. Treat zero as a configured value when
reporting the current and pending state. Test adding, applying,
changing and deleting zero.

Cover default, enabled, disabled and removed values in the cloud-init
dump tests for NoCloud and ConfigDrive2.

Signed-off-by: negineri <negineri@sfc.wide.ad.jp>
---
 src/PVE/API2/Qemu.pm                     |  9 ++---
 src/PVE/QemuServer.pm                    |  6 ++++
 src/PVE/QemuServer/Cloudinit.pm          |  3 +-
 src/test/run_api_cloudinit_dump_tests.pl | 42 ++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 53c5f1bf..1499b2ad 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -977,6 +977,7 @@ my $cloudinitoptions = {
     citype => 1,
     ciuser => 1,
     ciupgrade => 1,
+    cimanagehosts => 1,
     sshkeys => 1,
     $cloudinitoptions_net->%*,
 };
@@ -2188,14 +2189,14 @@ __PACKAGE__->register_method({

         # All already existing values (+ their new value, if it exists)
         for my $opt (keys %$cloudinitoptions) {
-            next if !$conf->{$opt};
+            next if !defined($conf->{$opt});
             next if $added =~ m/$opt/;
             my $item = {
                 key => $opt,
             };

-            if (my $pending = $ci->{$opt}) {
-                $item->{value} = $pending;
+            if (defined($ci->{$opt})) {
+                $item->{value} = $ci->{$opt};
                 $item->{pending} = $conf->{$opt};
             } else {
                 $item->{value} = $conf->{$opt};
@@ -2206,7 +2207,7 @@ __PACKAGE__->register_method({

         # Now, we'll find the deleted ones
         for my $opt (keys %$ci) {
-            next if $conf->{$opt};
+            next if defined($conf->{$opt});
             push @$res, { key => $opt, delete => 1 };
         }

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index ecbaa27f..29de6177 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -818,6 +818,12 @@ my $confdesc_cloudinit = {
             . ' recommended. Use ssh keys instead. Also note that older cloud-init versions do not'
             . ' support hashed passwords.',
     },
+    cimanagehosts => {
+        optional => 1,
+        type => 'boolean',
+        description => 'cloud-init: Manage /etc/hosts in the guest.',
+        default => 1,
+    },
     ciupgrade => {
         optional => 1,
         type => 'boolean',
diff --git a/src/PVE/QemuServer/Cloudinit.pm b/src/PVE/QemuServer/Cloudinit.pm
index f7f8c8e1..c99e392c 100644
--- a/src/PVE/QemuServer/Cloudinit.pm
+++ b/src/PVE/QemuServer/Cloudinit.pm
@@ -150,7 +150,8 @@ sub cloudinit_userdata {
     my $content = "#cloud-config\n";

     $content .= "hostname: $hostname\n";
-    $content .= "manage_etc_hosts: true\n";
+    my $manage_hosts = ($conf->{cimanagehosts} // 1) ? 'true' : 'false';
+    $content .= "manage_etc_hosts: $manage_hosts\n";
     $content .= "fqdn: $fqdn\n";

     my $username = $conf->{ciuser};
diff --git a/src/test/run_api_cloudinit_dump_tests.pl b/src/test/run_api_cloudinit_dump_tests.pl
index a4db1857..e2625c54 100755
--- a/src/test/run_api_cloudinit_dump_tests.pl
+++ b/src/test/run_api_cloudinit_dump_tests.pl
@@ -64,4 +64,46 @@ $can_config_cloudinit = 1;
 like(dump_config('user'), qr/^password: Secret1!$/m, 'user data: password shown with privilege');
 ok(defined(eval { dump_config('meta') }), 'meta data: available with privilege');

+for my $citype ('nocloud', 'configdrive2') {
+    for my $case (
+        ['default', undef, 'true'],
+        ['enabled', 1, 'true'],
+        ['disabled', 0, 'false'],
+    ) {
+        my ($name, $value, $expected) = @$case;
+        $conf = { %$base_conf, citype => $citype };
+        $conf->{cimanagehosts} = $value if defined($value);
+        like(
+            dump_config('user'),
+            qr/^manage_etc_hosts: $expected$/m,
+            "$citype user data: manage /etc/hosts $name",
+        );
+    }
+
+    delete $conf->{cimanagehosts};
+    like(
+        dump_config('user'),
+        qr/^manage_etc_hosts: true$/m,
+        "$citype user data: removing option restores default",
+    );
+}
+
+subtest 'cloud-init pending reports zero as a configured value' => sub {
+    for my $case (
+        ['added false', 0, { added => 'cimanagehosts' }, { pending => 0 }],
+        ['applied false', 0, {}, { value => 0 }],
+        ['false to true', 1, { cimanagehosts => 0 }, { value => 0, pending => 1 }],
+        ['true to false', 0, { cimanagehosts => 1 }, { value => 1, pending => 0 }],
+        ['deleted false', undef, { cimanagehosts => 0 }, { delete => 1 }],
+    ) {
+        my ($name, $value, $previous, $expected) = @$case;
+        $conf = { %$base_conf, 'special-sections' => { cloudinit => $previous } };
+        $conf->{cimanagehosts} = $value if defined($value);
+
+        my $rows = PVE::API2::Qemu->cloudinit_pending({ node => 'node', vmid => 100 });
+        my @matching = grep { $_->{key} eq 'cimanagehosts' } @$rows;
+        is_deeply(\@matching, [{ key => 'cimanagehosts', %$expected }], $name);
+    }
+};
+
 done_testing();
-- 
2.56.1




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH pve-manager 2/2] fix #7100: ui: cloud-init: allow configuring /etc/hosts management
  2026-11-24 21:26 [PATCH qemu-server/pve-manager 0/2] fix #7100: allow disabling cloud-init /etc/hosts management negineri
  2026-11-24 21:26 ` [PATCH qemu-server 1/2] fix #7100: cloud-init: make /etc/hosts management configurable negineri
@ 2026-11-24 21:26 ` negineri
  1 sibling, 0 replies; 3+ messages in thread
From: negineri @ 2026-11-24 21:26 UTC (permalink / raw)
  To: pve-devel

Expose cimanagehosts as a checkbox in the Cloud-Init panel, with the
enabled default matching qemu-server. Require VM.Config.Cloudinit to
edit or remove the option and submit an explicit zero when unchecked.

Requires the qemu-server patch adding cimanagehosts.

Signed-off-by: negineri <negineri@sfc.wide.ad.jp>
---
 www/manager6/qemu/CloudInit.js | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/www/manager6/qemu/CloudInit.js b/www/manager6/qemu/CloudInit.js
index 0895d83a..fb053ca5 100644
--- a/www/manager6/qemu/CloudInit.js
+++ b/www/manager6/qemu/CloudInit.js
@@ -169,6 +169,7 @@ Ext.define('PVE.qemu.CloudInit', {
         me.editorConfig.pveSelNode = me.pveSelNode;

         let caps_ci = caps.vms['VM.Config.Cloudinit'] || caps.vms['VM.Config.Network'];
+        let canManageHosts = !!caps.vms['VM.Config.Cloudinit'];
         /* editor is string and object */
         me.rows = {
             ciuser: {
@@ -269,6 +270,27 @@ Ext.define('PVE.qemu.CloudInit', {
                 },
                 defaultValue: '',
             },
+            cimanagehosts: {
+                header: gettext('Manage /etc/hosts'),
+                iconCls: 'fa fa-file-text-o',
+                renderer: Proxmox.Utils.format_boolean,
+                defaultValue: 1,
+                never_delete: !canManageHosts,
+                editor: canManageHosts
+                    ? {
+                          xtype: 'proxmoxWindowEdit',
+                          subject: gettext('Manage /etc/hosts'),
+                          items: {
+                              xtype: 'proxmoxcheckbox',
+                              name: 'cimanagehosts',
+                              uncheckedValue: 0,
+                              value: 1,
+                              fieldLabel: gettext('Manage /etc/hosts'),
+                              labelWidth: 140,
+                          },
+                      }
+                    : undefined,
+            },
             ciupgrade: {
                 header: gettext('Upgrade packages'),
                 iconCls: 'fa fa-archive',
-- 
2.56.1




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-24 21:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 21:26 [PATCH qemu-server/pve-manager 0/2] fix #7100: allow disabling cloud-init /etc/hosts management negineri
2026-11-24 21:26 ` [PATCH qemu-server 1/2] fix #7100: cloud-init: make /etc/hosts management configurable negineri
2026-11-24 21:26 ` [PATCH pve-manager 2/2] fix #7100: ui: cloud-init: allow configuring /etc/hosts management negineri

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal