#8501 Unify how FreeIPA gets FQDN of current host
Closed: fixed by ftweedal. Opened by cheimes.

Request for enhancement

To get a consistent behavior and to simplify container setups FreeIPA code should use a consistent API to access the FQDN of the current host. At the moment FreeIPA uses:

  • gethostname()
  • nodename member from uname()
  • Python's socket.getfqdn() which uses gethostbyname(gethostname()) internally. gethostbyname is an obsolete API.

The recommended way to get the canonical hostname of the current host is getaddrinfo(gethostname()) with AI_CANONNAME flag. The call uses NSS (name service switch) to look up the canonical hostname for the current node name. On modern systems with systemd-resolved or nss-myhostname NSS provider the call can never fail. Both NSS providers ensure that lookups for hostname from gethostname() always resolves to local interfaces. Like socket.getfqdn() the lookup may involve a DNS query. Therefore the result should be cached.

The command hostname --fqdn as well as some code paths in MIT KRB5 and Samba use the same approach. Eventually getaddrinfo(gethostname()) will allow FreeIPA to work on hosts that have a short name as node name.


Metadata Update from @cheimes:
- Custom field on_review adjusted to https://github.com/freeipa/freeipa/pull/5107

master:

  • 731c5b211041ee18940082b29e6a21b3f084fc57 Lookup ipa-ca record with NSS

Metadata Update from @abbra:
- Issue set to the milestone: FreeIPA 4.9

ipa-4-8:

  • 81cf1db50e0b3431c07d206b7b774679cb163e03 Lookup ipa-ca record with NSS

master:

  • e28ec76898a0240e416910b9cfea24e82e7d91ba Unify access to FQDN
  • 5d4ed65b83f6ed8bb7f3da05561698cbea692bb3 Replace nodename with ipa_gethostfqdn()
  • b66b961fdd3d0b7f3c37bd245decf700e720708c Remove problematic optimization from gethostfqdn()
  • 3d796a7e5102eded524e4847f8f9dd26f508ae94 Update debug strings to reflect new calls
  • 727a2ffb9336a050c26c790989edaf41864c6911 Easier to use ipa_gethostfqdn()
  • 3f59118ffcce07cbd74360f9ce8047e0b35960be (HEAD) ipa_sam: do not modify static buffer holding fqdn

Metadata Update from @ftweedal:
- Issue close_status updated to: fixed
- Issue status updated to: Closed (was: Open)

Metadata