From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <t.lamprecht@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 96447724F1
 for <pve-devel@lists.proxmox.com>; Tue, 25 May 2021 15:45:55 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 881872C8B0
 for <pve-devel@lists.proxmox.com>; Tue, 25 May 2021 15:45:55 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id AB0322C8A2
 for <pve-devel@lists.proxmox.com>; Tue, 25 May 2021 15:45:54 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 764E242D6B
 for <pve-devel@lists.proxmox.com>; Tue, 25 May 2021 15:45:54 +0200 (CEST)
Message-ID: <bc3cd68f-8780-04ce-2fa3-8b6bef19f787@proxmox.com>
Date: Tue, 25 May 2021 15:45:53 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101
 Thunderbird/89.0
Content-Language: en-US
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Oguz Bektas <o.bektas@proxmox.com>
References: <20210525131711.1007675-1-o.bektas@proxmox.com>
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
In-Reply-To: <20210525131711.1007675-1-o.bektas@proxmox.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.007 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 NICE_REPLY_A           -0.001 Looks like a legit reply (A)
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [proxmox.com, systemd.io, base.pm]
Subject: Re: [pve-devel] [PATCH container] fix #3443: setup: clear
 /etc/machine-id in post-create hook
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 25 May 2021 13:45:55 -0000

On 25.05.21 15:17, Oguz Bektas wrote:
> this way when new containers are created the will have a unique
> /etc/machine-id
> 

why the dbus then? systemd talks explicitly only about /etc/machine-id
in the docs and also in their CT interface [0], the thematic is only touched
there though.

The dbus one is most often a symlink to /etc/machine-id, removing that can
break things...

[0] https://systemd.io/CONTAINER_INTERFACE/

> note that post_create_hook doesn't run for cloned containers so that
> will need to be handled separately
> 

If you read my post you also read that we must not remove the file in the
clone case.

We currently always generate a new random MAC-address for all netX devies of
a CT on clone, that suggests that we always want to truncate in the clone case,
to ensure that IPv6 SLAAC, among other things, can work OK.

We could add a "unique" param to the clone call, but until now this was never
requested to be configurable.

[1]: https://forum.proxmox.com/threads/bug-machine-id-etc-machine-id-not-unique-in-lxc-containers.89708/post-392258

> 
> Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
> ---
>  src/PVE/LXC/Setup/Base.pm | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
> index be41874..75a7f74 100644
> --- a/src/PVE/LXC/Setup/Base.pm
> +++ b/src/PVE/LXC/Setup/Base.pm
> @@ -476,6 +476,18 @@ sub set_timezone {
>      }
>  }
>  
> +sub clear_machine_id {
> +    my ($self, $conf) = @_;
> +
> +    my $dbus_machine_id_path = "/var/lib/dbus/machine-id";
> +    my $machine_id_path = "/etc/machine-id";
> +    if ($self->ct_file_exists($dbus_machine_id_path)) {
> +        $self->ct_unlink($dbus_machine_id_path);
> +    }
> +    $self->ct_unlink($machine_id_path);
> +    $self->ct_file_set_contents($machine_id_path, "uninitialized\n");
> +}
> +
>  sub pre_start_hook {
>      my ($self, $conf) = @_;
>  
> @@ -491,6 +503,7 @@ sub pre_start_hook {
>  sub post_create_hook {
>      my ($self, $conf, $root_password, $ssh_keys) = @_;
>  
> +    $self->clear_machine_id($conf);

only relevant for systemd envs. so it should be only called then, if we must call this
in such a general place.

Either called in in the respective distro setup or check if any of "/lib/systemd/systemd"
or "/usr/lib/systemd/system" is executable for a heuristic to find out if the CT is
systemd managed.

>      $self->template_fixup($conf);
>  
>      $self->randomize_crontab($conf);
> 

this now depends on the patch which changed the private randomize_crontab helper
to a plugin method as the change is visible in the context, but that isn't mentioned
anywhere...