Project

General

Profile

Actions

Bug #36646

open

Host Identification during userdata download fails when requesting host addr is IPv6

Added by Alexander K. 10 months ago. Updated 4 months ago.

Status:
Ready For Testing
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Difficulty:
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

Hello, we found a bug regarding host identification during the userdata download when building a host. The problem lies in the function find_host_by_ip_or_mac in the foreman/app/services/foreman/unattended_installation/host_finder.rb file.

def find_host_by_ip_or_mac
        # In-case we get back multiple ips (see #1619)
        address_parser = IPAddr.new query_params[:ip].split(',').first
        ip = address_parser.native.to_s

        mac_list = query_params[:mac_list]

        query = mac_list.empty? ? { :nics => { :ip => ip } } : ["lower(nics.mac) IN (?)", mac_list] # HERE
        hosts = Host.joins(:provision_interface).where(query).order(:created_at)

        Rails.logger.warn("Multiple hosts found with #{ip} or #{mac_list}, picking up the most recent") if hosts.count > 1

        return unless hosts.present?

        # We return the last host and reload it since it is readonly because of associations.
        hosts.last.reload
      end

The line below that builds a query will fail if "ip" (the requesting ip) is an IPv6 address as foreman will then attempt to match an IPv6 address with the IPv4 field of the host, therefore resulting in no host being found and the installation failing.

query = mac_list.empty? ? { :nics => { :ip => ip } } : ["lower(nics.mac) IN (?)", mac_list]

Changing this to the following will result in IPv6 requester working correctly, but Ipv4 failing.

query = mac_list.empty? ? { :nics => { :ip6 => ip } } : ["lower(nics.mac) IN (?)", mac_list]

There needs to be a way of identifying the correct address family beforehand and then checking against the correct field of the object, to ensure that a host can be found by either its v4 or v6 address.

Actions #1

Updated by The Foreman Bot 4 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/10001 added
Actions

Also available in: Atom PDF