* [pve-devel] [PATCH container] setup: template_fixup: remove bogus LXC_NAME line from /etc/hosts
@ 2023-06-09 17:36 Stoiko Ivanov
2023-06-13 15:02 ` Stoiko Ivanov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Stoiko Ivanov @ 2023-06-09 17:36 UTC (permalink / raw)
To: pve-devel
Templates not built directly by us, but redistributed from
images.linuxcontainer.org contain the following line in /etc/hosts:
`127.0.1.1 LXC_NAME`
While it is mostly cosmetic - LXC_NAME, contains an underscore and is
not a valid DNS name.
Simply drop it for newly created containers in template_fixup.
We ship Debian, Devuan ourselves, without this line - so no need for
modification there.
Currently the nixos container-template (see [0]) also does not seem to
contain the line.
Noticed the issue with a fresh fedora container, where systemd-resolved
logs a warning upon boot.
[0] https://nixos.wiki/wiki/Proxmox_Linux_Container
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
src/PVE/LXC/Setup/Alpine.pm | 2 ++
src/PVE/LXC/Setup/ArchLinux.pm | 2 ++
src/PVE/LXC/Setup/Base.pm | 11 +++++++++++
src/PVE/LXC/Setup/CentOS.pm | 2 ++
src/PVE/LXC/Setup/Fedora.pm | 2 ++
src/PVE/LXC/Setup/Gentoo.pm | 2 ++
src/PVE/LXC/Setup/SUSE.pm | 2 ++
7 files changed, 23 insertions(+)
diff --git a/src/PVE/LXC/Setup/Alpine.pm b/src/PVE/LXC/Setup/Alpine.pm
index 87d72be..8672f3c 100644
--- a/src/PVE/LXC/Setup/Alpine.pm
+++ b/src/PVE/LXC/Setup/Alpine.pm
@@ -40,6 +40,8 @@ sub template_fixup {
$self->ct_symlink('/etc/init.d/savecache', '/etc/runlevels/shutdown/savecache');
$self->setup_securetty($conf);
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
diff --git a/src/PVE/LXC/Setup/ArchLinux.pm b/src/PVE/LXC/Setup/ArchLinux.pm
index 60118ef..e379ea1 100644
--- a/src/PVE/LXC/Setup/ArchLinux.pm
+++ b/src/PVE/LXC/Setup/ArchLinux.pm
@@ -40,6 +40,8 @@ sub template_fixup {
# edit /etc/securetty (enable login on console)
$self->setup_securetty($conf);
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index 5534397..2d14599 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -841,4 +841,15 @@ sub remove_pve_sections {
return $data =~ s/^\h*\Q$head\E.*^\h*\Q$tail\E.*?$//rgms;
}
+# templates from images.linuxcontainers.org have a bogus LXC_NAME line in /etc/hosts
+sub remove_lxc_name_from_etc_hosts {
+ my ($self) = @_;
+ my $hosts = $self->ct_file_get_contents('/etc/hosts');
+ my @lines = grep { !/^127.0.1.1\s+LXC_NAME$/ } split(/\n/, $hosts);
+
+ $hosts = join("\n", @lines). "\n";
+
+ $self->ct_file_set_contents('/etc/hosts', $hosts);
+}
+
1;
diff --git a/src/PVE/LXC/Setup/CentOS.pm b/src/PVE/LXC/Setup/CentOS.pm
index 1d31cee..e603d6c 100644
--- a/src/PVE/LXC/Setup/CentOS.pm
+++ b/src/PVE/LXC/Setup/CentOS.pm
@@ -119,6 +119,8 @@ sub template_fixup {
# always call so root can login, if /etc/securetty doesn't exists it's a no-op
$self->setup_securetty($conf);
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
diff --git a/src/PVE/LXC/Setup/Fedora.pm b/src/PVE/LXC/Setup/Fedora.pm
index 17ae7da..6e54a9e 100644
--- a/src/PVE/LXC/Setup/Fedora.pm
+++ b/src/PVE/LXC/Setup/Fedora.pm
@@ -24,6 +24,8 @@ sub template_fixup {
my ($self, $conf) = @_;
$self->setup_securetty($conf);
$self->ct_unlink('/etc/systemd/system/getty@.service');
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
diff --git a/src/PVE/LXC/Setup/Gentoo.pm b/src/PVE/LXC/Setup/Gentoo.pm
index 6dc8e9f..501db54 100644
--- a/src/PVE/LXC/Setup/Gentoo.pm
+++ b/src/PVE/LXC/Setup/Gentoo.pm
@@ -35,6 +35,8 @@ sub devttydir {
sub template_fixup {
my ($self, $conf) = @_;
$self->setup_securetty($conf);
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
diff --git a/src/PVE/LXC/Setup/SUSE.pm b/src/PVE/LXC/Setup/SUSE.pm
index 7863b50..3c5fc68 100644
--- a/src/PVE/LXC/Setup/SUSE.pm
+++ b/src/PVE/LXC/Setup/SUSE.pm
@@ -52,6 +52,8 @@ sub template_fixup {
# temporary fix for systemd-firstboot
$self->ct_file_set_contents('/etc/locale.conf', "LANG=C.utf8") if !$self->ct_file_exists('/etc/locale.conf');
$self->ct_symlink('/usr/share/zoneinfo/UTC', '/etc/localtime') if !$self->ct_file_exists('/etc/localtime');
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pve-devel] [PATCH container] setup: template_fixup: remove bogus LXC_NAME line from /etc/hosts
2023-06-09 17:36 [pve-devel] [PATCH container] setup: template_fixup: remove bogus LXC_NAME line from /etc/hosts Stoiko Ivanov
@ 2023-06-13 15:02 ` Stoiko Ivanov
2023-06-13 15:25 ` [pve-devel] applied: " Thomas Lamprecht
2023-06-13 16:46 ` [pve-devel] " Thomas Lamprecht
2 siblings, 0 replies; 4+ messages in thread
From: Stoiko Ivanov @ 2023-06-13 15:02 UTC (permalink / raw)
To: pve-devel
I just realized that this has been reported in our bugzilla:
https://bugzilla.proxmox.com/show_bug.cgi?id=4515
can gladly resent with the fitting prefix, (and will add it in case this
needs more work and a v2) - but if it gets applied as is adding
a reference to the bug would be appreciated!
On Fri, 9 Jun 2023 19:36:27 +0200
Stoiko Ivanov <s.ivanov@proxmox.com> wrote:
> Templates not built directly by us, but redistributed from
> images.linuxcontainer.org contain the following line in /etc/hosts:
> `127.0.1.1 LXC_NAME`
>
> While it is mostly cosmetic - LXC_NAME, contains an underscore and is
> not a valid DNS name.
>
> Simply drop it for newly created containers in template_fixup.
>
> We ship Debian, Devuan ourselves, without this line - so no need for
> modification there.
>
> Currently the nixos container-template (see [0]) also does not seem to
> contain the line.
>
> Noticed the issue with a fresh fedora container, where systemd-resolved
> logs a warning upon boot.
>
> [0] https://nixos.wiki/wiki/Proxmox_Linux_Container
>
> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
> src/PVE/LXC/Setup/Alpine.pm | 2 ++
> src/PVE/LXC/Setup/ArchLinux.pm | 2 ++
> src/PVE/LXC/Setup/Base.pm | 11 +++++++++++
> src/PVE/LXC/Setup/CentOS.pm | 2 ++
> src/PVE/LXC/Setup/Fedora.pm | 2 ++
> src/PVE/LXC/Setup/Gentoo.pm | 2 ++
> src/PVE/LXC/Setup/SUSE.pm | 2 ++
> 7 files changed, 23 insertions(+)
>
> diff --git a/src/PVE/LXC/Setup/Alpine.pm b/src/PVE/LXC/Setup/Alpine.pm
> index 87d72be..8672f3c 100644
> --- a/src/PVE/LXC/Setup/Alpine.pm
> +++ b/src/PVE/LXC/Setup/Alpine.pm
> @@ -40,6 +40,8 @@ sub template_fixup {
> $self->ct_symlink('/etc/init.d/savecache', '/etc/runlevels/shutdown/savecache');
>
> $self->setup_securetty($conf);
> +
> + $self->remove_lxc_name_from_etc_hosts();
> }
>
> sub setup_init {
> diff --git a/src/PVE/LXC/Setup/ArchLinux.pm b/src/PVE/LXC/Setup/ArchLinux.pm
> index 60118ef..e379ea1 100644
> --- a/src/PVE/LXC/Setup/ArchLinux.pm
> +++ b/src/PVE/LXC/Setup/ArchLinux.pm
> @@ -40,6 +40,8 @@ sub template_fixup {
>
> # edit /etc/securetty (enable login on console)
> $self->setup_securetty($conf);
> +
> + $self->remove_lxc_name_from_etc_hosts();
> }
>
> sub setup_init {
> diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
> index 5534397..2d14599 100644
> --- a/src/PVE/LXC/Setup/Base.pm
> +++ b/src/PVE/LXC/Setup/Base.pm
> @@ -841,4 +841,15 @@ sub remove_pve_sections {
> return $data =~ s/^\h*\Q$head\E.*^\h*\Q$tail\E.*?$//rgms;
> }
>
> +# templates from images.linuxcontainers.org have a bogus LXC_NAME line in /etc/hosts
> +sub remove_lxc_name_from_etc_hosts {
> + my ($self) = @_;
> + my $hosts = $self->ct_file_get_contents('/etc/hosts');
> + my @lines = grep { !/^127.0.1.1\s+LXC_NAME$/ } split(/\n/, $hosts);
> +
> + $hosts = join("\n", @lines). "\n";
> +
> + $self->ct_file_set_contents('/etc/hosts', $hosts);
> +}
> +
> 1;
> diff --git a/src/PVE/LXC/Setup/CentOS.pm b/src/PVE/LXC/Setup/CentOS.pm
> index 1d31cee..e603d6c 100644
> --- a/src/PVE/LXC/Setup/CentOS.pm
> +++ b/src/PVE/LXC/Setup/CentOS.pm
> @@ -119,6 +119,8 @@ sub template_fixup {
>
> # always call so root can login, if /etc/securetty doesn't exists it's a no-op
> $self->setup_securetty($conf);
> +
> + $self->remove_lxc_name_from_etc_hosts();
> }
>
> sub setup_init {
> diff --git a/src/PVE/LXC/Setup/Fedora.pm b/src/PVE/LXC/Setup/Fedora.pm
> index 17ae7da..6e54a9e 100644
> --- a/src/PVE/LXC/Setup/Fedora.pm
> +++ b/src/PVE/LXC/Setup/Fedora.pm
> @@ -24,6 +24,8 @@ sub template_fixup {
> my ($self, $conf) = @_;
> $self->setup_securetty($conf);
> $self->ct_unlink('/etc/systemd/system/getty@.service');
> +
> + $self->remove_lxc_name_from_etc_hosts();
> }
>
> sub setup_init {
> diff --git a/src/PVE/LXC/Setup/Gentoo.pm b/src/PVE/LXC/Setup/Gentoo.pm
> index 6dc8e9f..501db54 100644
> --- a/src/PVE/LXC/Setup/Gentoo.pm
> +++ b/src/PVE/LXC/Setup/Gentoo.pm
> @@ -35,6 +35,8 @@ sub devttydir {
> sub template_fixup {
> my ($self, $conf) = @_;
> $self->setup_securetty($conf);
> +
> + $self->remove_lxc_name_from_etc_hosts();
> }
>
> sub setup_init {
> diff --git a/src/PVE/LXC/Setup/SUSE.pm b/src/PVE/LXC/Setup/SUSE.pm
> index 7863b50..3c5fc68 100644
> --- a/src/PVE/LXC/Setup/SUSE.pm
> +++ b/src/PVE/LXC/Setup/SUSE.pm
> @@ -52,6 +52,8 @@ sub template_fixup {
> # temporary fix for systemd-firstboot
> $self->ct_file_set_contents('/etc/locale.conf', "LANG=C.utf8") if !$self->ct_file_exists('/etc/locale.conf');
> $self->ct_symlink('/usr/share/zoneinfo/UTC', '/etc/localtime') if !$self->ct_file_exists('/etc/localtime');
> +
> + $self->remove_lxc_name_from_etc_hosts();
> }
>
> sub setup_init {
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pve-devel] applied: [PATCH container] setup: template_fixup: remove bogus LXC_NAME line from /etc/hosts
2023-06-09 17:36 [pve-devel] [PATCH container] setup: template_fixup: remove bogus LXC_NAME line from /etc/hosts Stoiko Ivanov
2023-06-13 15:02 ` Stoiko Ivanov
@ 2023-06-13 15:25 ` Thomas Lamprecht
2023-06-13 16:46 ` [pve-devel] " Thomas Lamprecht
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2023-06-13 15:25 UTC (permalink / raw)
To: Proxmox VE development discussion, Stoiko Ivanov
Am 09/06/2023 um 19:36 schrieb Stoiko Ivanov:
> Templates not built directly by us, but redistributed from
> images.linuxcontainer.org contain the following line in /etc/hosts:
> `127.0.1.1 LXC_NAME`
>
> While it is mostly cosmetic - LXC_NAME, contains an underscore and is
> not a valid DNS name.
>
> Simply drop it for newly created containers in template_fixup.
>
> We ship Debian, Devuan ourselves, without this line - so no need for
> modification there.
>
> Currently the nixos container-template (see [0]) also does not seem to
> contain the line.
>
> Noticed the issue with a fresh fedora container, where systemd-resolved
> logs a warning upon boot.
>
> [0] https://nixos.wiki/wiki/Proxmox_Linux_Container
>
> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
> src/PVE/LXC/Setup/Alpine.pm | 2 ++
> src/PVE/LXC/Setup/ArchLinux.pm | 2 ++
> src/PVE/LXC/Setup/Base.pm | 11 +++++++++++
> src/PVE/LXC/Setup/CentOS.pm | 2 ++
> src/PVE/LXC/Setup/Fedora.pm | 2 ++
> src/PVE/LXC/Setup/Gentoo.pm | 2 ++
> src/PVE/LXC/Setup/SUSE.pm | 2 ++
> 7 files changed, 23 insertions(+)
>
>
applied, with bug ID amended, thanks!
FWIW, I'd think that having a more flexible regex to drop any IP + LXC_NET would
be fine too, as would be doing this more centrally for any template (not all Debian
templates users use are guaranteed to come from us), e.g., as separate call inside
the PVE::LXC::Setup->template_fix-up's protected_call closure, but just throwing out
for future reference, i.e., if we need to extend this or add to more distros.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pve-devel] [PATCH container] setup: template_fixup: remove bogus LXC_NAME line from /etc/hosts
2023-06-09 17:36 [pve-devel] [PATCH container] setup: template_fixup: remove bogus LXC_NAME line from /etc/hosts Stoiko Ivanov
2023-06-13 15:02 ` Stoiko Ivanov
2023-06-13 15:25 ` [pve-devel] applied: " Thomas Lamprecht
@ 2023-06-13 16:46 ` Thomas Lamprecht
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2023-06-13 16:46 UTC (permalink / raw)
To: Proxmox VE development discussion, Stoiko Ivanov
Am 09/06/2023 um 19:36 schrieb Stoiko Ivanov:
> diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
> index 5534397..2d14599 100644
> --- a/src/PVE/LXC/Setup/Base.pm
> +++ b/src/PVE/LXC/Setup/Base.pm
> @@ -841,4 +841,15 @@ sub remove_pve_sections {
> return $data =~ s/^\h*\Q$head\E.*^\h*\Q$tail\E.*?$//rgms;
> }
>
> +# templates from images.linuxcontainers.org have a bogus LXC_NAME line in /etc/hosts
> +sub remove_lxc_name_from_etc_hosts {
> + my ($self) = @_;
> + my $hosts = $self->ct_file_get_contents('/etc/hosts');
This failed the build...
prepare test-alpine-001
can't open '/etc/hosts' - No such file or directory
error in setup task PVE::LXC::Setup::post_create_hook
make[3]: *** [Makefile:8: test_setup] Error 1
Please add an actual test for this.
> + my @lines = grep { !/^127.0.1.1\s+LXC_NAME$/ } split(/\n/, $hosts);
> +
> + $hosts = join("\n", @lines). "\n";
> +
> + $self->ct_file_set_contents('/etc/hosts', $hosts);
> +}
> +
> 1;
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-13 16:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09 17:36 [pve-devel] [PATCH container] setup: template_fixup: remove bogus LXC_NAME line from /etc/hosts Stoiko Ivanov
2023-06-13 15:02 ` Stoiko Ivanov
2023-06-13 15:25 ` [pve-devel] applied: " Thomas Lamprecht
2023-06-13 16:46 ` [pve-devel] " Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox