Bug 1405614 - System does not get registered because {"network.hostname-override":""} in /etc/rhsm/facts/katello.facts is empty due `hostname -f`
Summary: System does not get registered because {"network.hostname-override":""} in /e...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Registration
Version: 6.2.5
Hardware: All
OS: Linux
urgent
urgent
Target Milestone: Unspecified
Assignee: Justin Sherrill
QA Contact: Lukas Pramuk
URL:
Whiteboard:
Depends On:
Blocks: 1417068
TreeView+ depends on / blocked
 
Reported: 2016-12-16 20:52 UTC by Marcelo Moreira de Mello
Modified: 2021-12-10 14:50 UTC (History)
19 users (show)

Fixed In Version: katello-installer-base-3.0.0.73-1,rubygem-katello-3.0.0.100-1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1417068 (view as bug list)
Environment:
Last Closed: 2017-03-06 08:36:20 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 17721 0 Normal Closed systems where 'hostname -f' returns an error fails registration 2021-01-22 14:38:51 UTC
Red Hat Knowledge Base (Solution) 2835771 0 None None None 2016-12-29 04:32:13 UTC
Red Hat Product Errata RHBA-2017:0447 0 normal SHIPPED_LIVE Satellite 6.2.8 Async Bug Release 2017-03-06 13:23:41 UTC

Description Marcelo Moreira de Mello 2016-12-16 20:52:13 UTC
Description of problem:

On Satellite 6.2.5 we should enforce FQDN when registering a system. 

To accomplish that, it was introduced a new step on the boostrap process to save the override the FQDN by creating the file /etc/rhsm/facts/katello.facts. 


# tail /usr/bin/katello-rhsm-consumer  -n 7 | grep -v ^# | grep -v ^$
if [ -d /etc/rhsm/facts/ ]; then
  echo "{\"network.hostname-override\":\"`hostname -f`\"}" > /etc/rhsm/facts/katello.facts
fi
exit 0

The problem happens because the `hostname -f` will **FAIL** if there is no PTR entry on the DNS or any entry in /etc/hosts file.


# hostname -f
hostname: Unknown host


Thus, the file will be created as follow:

# cat /etc/rhsm/facts/katello.facts 
{"network.hostname-override":""}

When trying to register it, Satellite will error out with the error below:

# subscription-manager register --org="Default_Organization" --environment="Library"
Registering to: sat6mmello.usersys.redhat.com:443/rhsm
Username: admin
Password: 
Validation failed: Name can't be blank, Name is invalid


# cat /var/log/rhsm/rhsm.log
2016-12-16 15:21:30,151 [ERROR] subscription-manager:30740 @managercli.py:1108 - Validation failed: Name can't be blank, Name is invalid
Traceback (most recent call last):
  File "/usr/share/rhsm/subscription_manager/managercli.py", line 1103, in _do_command
    content_tags=self.installed_mgr.tags)
  File "/usr/lib64/python2.6/site-packages/rhsm/connection.py", line 913, in registerConsumer
    return self.conn.request_post(url, params)
  File "/usr/lib64/python2.6/site-packages/rhsm/connection.py", line 684, in request_post
    return self._request("POST", method, params)
  File "/usr/lib64/python2.6/site-packages/rhsm/connection.py", line 598, in _request
    self.validateResponse(result, request_type, handler)
  File "/usr/lib64/python2.6/site-packages/rhsm/connection.py", line 648, in validateResponse
    raise RestlibException(response['status'], error_msg, response.get('headers'))
RestlibException: Validation failed: Name can't be blank, Name is invalid



==> /var/log/foreman/production.log <==
2016-12-16 12:31:54 [foreman-tasks/action] [E] Validation failed: Name can't be blank, Name is invalid (ActiveRecord::RecordInvalid)
 | /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/validations.rb:57:in `save!'



Version-Release number of selected component (if applicable):
Red Hat Satellite 6.2.5

How reproducible:
100%

Steps to Reproduce:
1. Install a system
2. Set a hostname that does not have a PTR entry or not in /etc/hosts
3. The command `hostname -f` should fail


Actual results:

Registering a system should fail


Expected results:

The /etc/rhsm/facts/katello.facts  should only be created if hostname -f works. 


HOSTNAME=`hostname -f`
IS_FQDN=`echo $?`

if [ -d /etc/rhsm/facts/ ] && [ $IS_FQDN -eq 0 ]; then
  echo "{\"network.hostname-override\":\"$HOSTNAME\"}" > /etc/rhsm/facts/katello.facts
fi

Comment 2 Justin Sherrill 2016-12-16 20:56:08 UTC
Connecting redmine issue http://projects.theforeman.org/issues/17721 from this bug

Comment 5 Bryan Kearney 2016-12-21 01:20:08 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/17721 has been resolved.

Comment 6 Marcus 2017-01-19 02:27:05 UTC
so, the fix is introducing another problem.  The override is in fact now overriding my fqdn.  The katello.facts file being static is not a good idea. I spent hours trying to figure out why all of my hostname settings were not being reflected during registration.

Comment 8 Isaac Freeman 2017-02-08 16:07:56 UTC
I agree that caching the hostname in a static file is a bad idea. I've run in to the issue where "hostname -f" fails and an empty string is cached in the file, but I've also recently run in to an issue where a registered RHEL VM is cloned, and when you change the hostname and IP, reboot, and try to re-register the new system, it just overwrites the registration in Satellite of the original VM because it's still using the original VM's cached hostname. I don't see how there is any sense is caching the hostname in a separate file when it's available easily in the HOSTNAME environment variable or the "hostname" command for any applications running on the system.

Comment 9 Justin Sherrill 2017-02-08 16:26:05 UTC
Its a temporary measure to work around differences in how puppet and subscription-manager report the hostname.  It is obsoleted by:

https://bugzilla.redhat.com/show_bug.cgi?id=1367126

and by installing the newest katello-agent (which will provide the fqdn fact if its not present).

Comment 10 Lukas Pramuk 2017-02-27 15:29:56 UTC
VERIFIED.

@satellite-6.2.8-1.0.el7sat.noarch (snap3)
katello-installer-base-3.0.0.77-1.el7sat.noarch
tfm-rubygem-katello-3.0.0.103-1.el7sat.noarch

by following manual reproducer:

1. Create a VM that SAT (6.2.7) is not aware of (preferably behind NAT)

2. Simulate that `hostname -f` fails for on the VM
# cat > /usr/bin/hostname <<<'exit 1'

3. Install CA consumer certs
# rpm -Uvh http://$SAT/pub/katello-ca-consumer-latest.noarch.rpm

4. Check contents of /etc/rhsm/facts/katello.facts
# cat /etc/rhsm/facts/katello.facts
{"network.hostname-override":""}

5. Try to register to 6.2.7 
# subscription-manager register --force --username admin --password changeme
Registering to: <SATFQDN>:443/rhsm
Validation failed: Name can't be blank, Name is invalid

>>> REPRODUCED


6. Upgrade SAT to 6.2.8

7. Check contents of /etc/rhsm/facts/katello.facts
# cat /etc/rhsm/facts/katello.facts
{"network.hostname-override":""}

8. Register to 6.2.8
# subscription-manager register --force --username admin --password changeme
Registering to: <SATFQDN>:443/rhsm
The system has been registered with ID: f4c33c48-34a2-4b0b-8df4-05a3a0e8b4e4 

>>> VERIFIED that though network.hostname-override is empty the VM registers
>>> re-registration of already (before the fix) registered client succeeds


9. Simulate brand new registration
# subscription-manager unregister
# rpm -e $(rpm -qa katello-ca-consumer-*)
# rm -f /etc/rhsm/facts/katello.facts

10. Install CA consumer certs
# rpm -Uvh http://$SAT/pub/katello-ca-consumer-latest.noarch.rpm

11. Check contents of /etc/rhsm/facts/katello.facts
# cat /etc/rhsm/facts/katello.facts
cat: /etc/rhsm/facts/katello.facts: No such file or directory

12. Register new (not yet registered) client
# subscription-manager register --force --username admin --password changeme 
Registering to: <SATFQDN>:443/rhsm
The system has been registered with ID: 094873f8-3972-4879-9452-fc8af730ea11 

>>> VERIFIED that though /etc/rhsm/facts/katello.facts is no longer generated by /usr/bin/katello-rhsm-consumer the VM registers
>>> the new client registration succeeds

Comment 12 errata-xmlrpc 2017-03-06 08:36:20 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, 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-2017:0447

Comment 13 David Hill 2018-01-11 17:21:20 UTC
This is good information as we hit this with virt-customize on a minimal kickstart image.


Note You need to log in before you can comment on or make changes to this bug.