Bug 1975349

Summary: Make the installer environment hostname set for %post section from kickstart stable
Product: Red Hat Enterprise Linux 8 Reporter: jcastran
Component: anacondaAssignee: Radek Vykydal <rvykydal>
Status: CLOSED ERRATA QA Contact: Release Test Team <release-test-team-automation>
Severity: high Docs Contact:
Priority: medium    
Version: 8.4CC: cbesson, jkonecny, jstodola, linux, peter.vreman, rvykydal, sbarcomb, sdubewar
Target Milestone: betaKeywords: Triaged
Target Release: ---   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: anaconda-33.16.6.2-1.el8 Doc Type: Bug Fix
Doc Text:
.Anaconda sets a static hostname before running the `%post` scripts Previously, when Anaconda was setting the installer environment host name to the value from the kickstart configuration (`network --hostname`), it used to set a transient hostname. Some of the actions performed during `%post` script run, for example network device activation, were causing the host name reset to a value obtained by reverse `dns`. With this update, Anaconda now sets a static hostname of the installer environment to be stable during the run of kickstart `%post` scripts.
Story Points: ---
Clone Of:
: 2009403 (view as bug list) Environment:
Last Closed: 2022-05-10 13:36:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2009403    

Description jcastran 2021-06-23 13:30:14 UTC
* Description of problem:
Anaconda will set the hostname of a system based on DNS. If no entires are found it will set it to localhost.

There is no way to stop this behaviour. 


* Steps to Reproduce:
1. set hostname in kickstart with "network --hostname=<blah>"
2. boot installation with ip=dhcp and inst.ks=http://X.X.X.X/ks.cfg
3.

* Actual results:
NetworkManager will set the hostname based on DNS results and not the kickstart

Jun 21 14:28:10 test.net NetworkManager[1747]: <info>  [1624285690.4197] policy: set-hostname: current hostname was changed outside NetworkManager: 'test.net'
Jun 21 14:28:10 test.net NetworkManager[1747]: <info>  [1624285690.4198] policy: set-hostname: set hostname to 'localhost' (from address lookup)



* Expected results:
Preferably we should be able to either disable this feature of NetworkManager.

Or if a hostname is set to something other than localhost, NetworkManager should not overwrite that.


* Additional info:
This was discussed in Bug 1766944. Opening the request for these options.

https://bugzilla.redhat.com/show_bug.cgi?id=1766944#c20

This could be eventually done by installer boot option (something like inst.nm.hostname.only-from-default). As a global modification of installer environment this does not seem to belong to kickstart.
Also it would apply only to devices/connections configured by kickstart after switch root (NM activating connections in initramfs would be unaffected in this respect).

Comment 2 Peter Vreman 2021-06-24 11:27:04 UTC
The references BZ1766944 looks to be introducing the changed behaviour to do the DNS lookup and enforce that value.

For me as an user this is not understandable. If i 'hardcode' the hostname in the Kickstart file then it should use that Hostname and not something dynamic.



Btw. when adding --noipv6 it suddenly works and the hostname is kept on <blah> and not taken from DNS
network --noipv6 --hostname=<blah>

Comment 3 Radek Vykydal 2021-06-25 12:02:14 UTC
So if I understand the RFE correctly the request is to provide an installer option that would allow to revert the change of behaviour introduced in RHEL 8.4 with bug 1766944.

Which means instead of opting in to the new behaviour (changing the hostname.only-from-default=true default) as proposed in https://bugzilla.redhat.com/show_bug.cgi?id=1766944#c20, the point of the option is to opt out from the new behaviour - the default hostname.only-from-default=false as present in RHEL 8.4 per https://bugzilla.redhat.com/show_bug.cgi?id=1766944#c42.

(Please note that the network --hostname option configures the hostname of target system. Configuration of installer environment has never been guaranteed and IIRC the behavior changed in this aspect in the past. )

Comment 4 Peter Vreman 2021-06-25 12:56:14 UTC
The behavior is about the hostname being change to a 'random' value during %post section.
There are many customer dependent installation steps that you want to be done %post that rely on the hostname being already the target hostname.

In the past you could just kill NetworkManager in the post-nochroot and is documented at https://access.redhat.com/solutions/102823


This RFE is to ask that the 'network --hostname=<blah>' is honored to have a for the customer a predictable name without relying on external services (that might be out-of-control of the engineers, e.g. the DNS server is often Windows-AD controlled and without direct access for the Linux teams) to set also during the Kickstart process instead of a random name.

If a new option is preferred i can think of:

network --hostname=<blah> --kickstart-hostname

The '--kickstart-hostname' means that the kickstart process will also be continuing using the hostname


In the end it is about predictability/control for the customer, both the BZ1766944 and this RFE ask for this, only the source of the hostname is different
- BZ1766944 asks for predictability/control of the hostname by asking from DNS
- This RFE asks for predictability/control of the hostname through the kickstart-file
- Backwards/legacy behaviour is keep localhost.localdomain


Did you also check why there is then the difference between using 'network --hostname=<blah>' and 'network --noipv6 --hostname=<blah>'?

Comment 5 jcastran 2021-06-30 19:22:31 UTC
*** Bug 1975347 has been marked as a duplicate of this bug. ***

Comment 6 Radek Vykydal 2021-09-29 10:31:26 UTC
Anaconda is setting installer environment transient hostname to the value configured in kickstart (network --hostname) close to the end of installation, before running the %post scripts.
As also reported in comment #4 this setting is not stable and can be updated by NetworkManager. From my experience, (re-)activation of a network device by Network Manager can update the installer environment hostname. I used this kickstart to reproduce the issue from the Description:

network --hostname myhostname

%post
hostname
nmcli con up ens3
sleep 4
hostname
%end

For RHEL 8 it seems to start to happen in RHEL 8.4 release - the installer environment hostname is updated from address lookup by NM. The description suggests the issue is related to the change in the bug 1766944, but even when configuring NM to disable the change of default behavior in 8.4 by:

[connection]
hostname.only-from-defalut=1

the hostname is still modified from address lookup. Maybe there has been some more fundamental change than the one related to a device having/not having default route. So the option requested in the BZ Description does not seem to resolve the issue from comment #4.

The issue would be fixed by installer setting static hostname instead of transient hostname (as it does in RHEL-7). This patch should do the change:

https://github.com/rhinstaller/anaconda/pull/3627

I've prepared an installer updates image for RHEL 8.4 with the patch for checking the fix, it can be applied by boot option
updates=https://rvykydal.fedorapeople.org/updates.hostname-static-84.img
or by adding kickstart command
updates https://rvykydal.fedorapeople.org/updates.hostname-static-84.img

Also a workaround setting the static hostname at the beginning of the %post section could be used:

%post
hostnamectl --set-hostname $(hostname)
# your post section
%end

Comment 7 Radek Vykydal 2021-09-29 10:36:44 UTC
(In reply to Peter Vreman from comment #4)

 
> Did you also check why there is then the difference between using 'network
> --hostname=<blah>' and 'network --noipv6 --hostname=<blah>'?

In case of

network --hostname=<blah>

anaconda just configures the hostname.


If there are also options for a network device configuration present in the network command, like --noipv6 in

network --noipv6 --hostname=<blah>

anaconda assumes that also a network device should be configured with default values [1] (eg --device=link, --bootproto=dhcp) and configuration / activation of a network device by NM can trigger hostname update from DNS lookup as described in previous comment.


[1] The documentation has been recently updated with this information, in --hostname option of https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/performing_an_advanced_rhel_installation/kickstart-commands-and-options-reference_installing-rhel-as-an-experienced-user#network_kickstart-commands-for-network-configuration

Comment 8 Radek Vykydal 2021-09-30 13:48:27 UTC
Updating the BZ title to reflect the resolution proposed in comment #6.

Comment 10 Radek Vykydal 2021-10-06 13:23:10 UTC
(In reply to Radek Vykydal from comment #6)

> https://github.com/rhinstaller/anaconda/pull/3627

Moving into POST

Comment 19 Chris Adams 2021-12-20 22:55:00 UTC
I found that using the rhsm directive with an activation key in a kickstart, combined with a "network --bootproto=dhcp --hostname=foo" line, results with a system being registered as localhost.localdomain. If the network line has static config, the hostname is set before registration. I'm guessing this is the same issue; will this patch set the hostname prior to registration (which is done before %post scripts)?

If there's a hostname in the kickstart, it should be applied as soon as possible, before taking any action for the to-be-installed system. Multiple things can use the hostname during install - I've seen RPMs with %post scripts that create sample configs for example. Even just building a Linux software RAID set encodes the hostname it was created on.

Comment 21 errata-xmlrpc 2022-05-10 13:36:52 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (anaconda bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:1780