Project

General

Profile

Bug #2130

normalize_hostname appends domain to end of fqdn on Update

Added by Mikael Fridh over 6 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Web Interface
Target version:
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

So, not sure if this is just my freaky environment, where I have hosts whose fqdn really is:
willy.freaky.com

but they have a hardcoded fqdn in puppet as:
willy.deaky.net

From Foreman and Puppets point of view, the hosts are named *.deaky.net.
When editing a Host, the normalize_hostname filter will append $domain to the end of the fqdn, thus renaming the host:
willy.deaky.net.freaky.com

Associated revisions

Revision 0c8f532e (diff)
Added by Mikael Fridh about 6 years ago

fixes #2130 - normalize_hostname appends domainname to fqdn

When the trailing part of $fqdn doesn't match $domain, the normalize_hostname
function would append $domain onto the end of $fqdn, saving the host as
$fqdn.$domain (Example: hostname.domain1.com.domain2.com).

This rename would happen if you edit a host already named 'host.domain1.com'
where a (hardcoded) certname says 'host.domain1.com' but the domain fact says
'domain2.com'.

If a hostname is supposed to follow RFC952 format, any . (dot) is only allowed
as a separator between domain parts and not in the hostname part itself.
Thus if there is already a dot in the hostname we have to assume the host name
(fqdn) is already fully qualified.

Revision c72cc3b1 (diff)
Added by Mikael Fridh about 6 years ago

fixes #2130 - normalize_hostname appends domainname to fqdn

When the trailing part of $fqdn doesn't match $domain, the normalize_hostname
function would append $domain onto the end of $fqdn, saving the host as
$fqdn.$domain (Example: hostname.domain1.com.domain2.com).

This rename would happen if you edit a host already named 'host.domain1.com'
where a (hardcoded) certname says 'host.domain1.com' but the domain fact says
'domain2.com'.

If a hostname is supposed to follow RFC952 format, any . (dot) is only allowed
as a separator between domain parts and not in the hostname part itself.
Thus if there is already a dot in the hostname we have to assume the host name
(fqdn) is already fully qualified.
(cherry picked from commit 0c8f532ed251049dcd93f6ce054f07093f9507f8)

History

#1 Updated by Mikael Fridh over 6 years ago

I'm thinking either this patch, or simply matching one dot /\./

diff --git a/app/models/host.rb b/app/models/host.rb
index fcb8838..9e81b9a 100644
--- a/app/models/host.rb
+++ b/app/models/host.rb
@@ -819,7 +819,7 @@ class Host < Puppet::Rails::Host
         old_domain = Domain.find(changed_attributes["domain_id"])
         self.name.gsub(old_domain.to_s,"")
       end
-      self.name += ".#{domain}" unless name =~ /.#{domain}$/i
+      self.name += ".#{domain}" unless name =~ /\..*\./i
     end
   end

#2 Updated by Mikael Fridh over 6 years ago

pullreq https://github.com/theforeman/foreman/pull/376 I opted for the single-dot patch.

#3 Updated by Mikael Fridh over 6 years ago

  • Target version set to 1.2.0

I'll just set this to 1.2 for consideration as there was some agreement on #theforeman-dev that the patch does make some sense. Why should hosts be renamed if they already look like an fqdn style hostname. I'm unaware of an edge case where it would make sense but please enlighten me if you do!

#4 Updated by Dominic Cleal about 6 years ago

  • Status changed from New to Ready For Testing
  • Assignee changed from Ohad Levy to Mikael Fridh

#5 Updated by Mikael Fridh about 6 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF