Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong EC2 hostname set if DHCP Options Set has multiple domain-name #3659

Open
ubuntu-server-builder opened this issue May 12, 2023 · 1 comment
Labels
bug Something isn't working correctly launchpad Migrated from Launchpad

Comments

@ubuntu-server-builder
Copy link
Collaborator

This bug was originally filed in Launchpad as LP: #1874527

Launchpad details
affected_projects = []
assignee = None
assignee_name = None
date_closed = None
date_created = 2020-04-23T19:47:30.783162+00:00
date_fix_committed = None
date_fix_released = None
id = 1874527
importance = low
is_complete = False
lp_url = https://bugs.launchpad.net/cloud-init/+bug/1874527
milestone = None
owner = rehevkor5
owner_name = SC
private = False
status = triaged
submitter = rehevkor5
submitter_name = SC
tags = []
duplicates = []

Launchpad user SC(rehevkor5) wrote on 2020-04-23T19:47:30.783162+00:00

Cloud Provider: AWS.
Cloud-init v. 19.3-2.amzn2.
Config says system_info: distro: amazon

Per https://docs.aws.amazon.com/vpc/latest/userguide/VPC_DHCP_Options.html the VPC DHCP Options set can have a domain-name value with multiple domain names separated by spaces. However, if using this approach, cloud-init sets an incorrect hostname. It appears to concatenate the unqualified host name to the Options Set host names without spaces, and truncating to a certain number of characters.

This is with "set-hostname" and "update-hostname" modules enabled, but no other relevant cloud-init config.

For example, if your unqualified hostname is ip-10-30-10-155 and your DHCP Options Set domain-name is "foo.bar.example.com baz.bat.example.com" you might get an incorrect hostname such as "ip-10-30-10-155.foo.bar.example.combaz.bat.ex"

This problem appears to be due to misinterpretation of the output of the EC2 metadata service for "local-hostname", which responds with output similar to above, but with spaces retained and no truncating, for example: "ip-10-30-10-155.foo.bar.example.com baz.bat.example.com"

The cloud-init log output also mentions this problem, for example you might have logs which look like:

Mar 18 00:31:33 cloud-init[3825]: cc_set_hostname.py[DEBUG]: Setting the hostname to ip-10-30-10-155.us-west-2.i.test.abcdefg.example.com i.test.abcdefg.example.com
us-west-2.test.abcdefg.example.com test.abcdefg.example.com us-west-2.compute.internal (ip-10-30-10-155)
Mar 18 00:31:33 cloud-init[3825]: util.py[DEBUG]: Running command ['hostnamectl', 'set-hostname', 'ip-10-30-10-155.us-west-2.i.test.abcdefg.example.com i.test.abcdefg.example.com us-west-2.test.abcdefg.example.com test.abcdefg.example.com us-west-2.compute.internal'] with allowed return codes [0] (shell=False, capture=True)
Mar 18 00:31:33 cloud-init[3825]: init.py[DEBUG]: Non-persistently setting the system hostname to ip-10-30-10-155.us-west-2.i.test.abcdefg.example.com i.test.abcdefg.example.com us-west-2.test.abcdefg.example.com test.abcdefg.example.com us-west-2.compute.internal
Mar 18 00:31:33 cloud-init[3825]: util.py[DEBUG]: Running command ['hostname', 'ip-10-30-10-155.us-west-2.i.test.abcdefg.example.com i.test.abcdefg.example.com us-we
st-2.test.abcdefg.example.com test.abcdefg.example.com us-west-2.compute.internal'] with allowed return codes [0] (shell=False, capture=True)
Mar 18 00:31:33 cloud-init[3825]: util.py[WARNING]: Failed to non-persistently adjust the system hostname to ip-10-30-10-155.us-west-2.i.test.abcdefg.example.com i.te
st.abcdefg.example.com us-west-2.test.abcdefg.example.com test.abcdefg.example.com us-west-2.compute.internal
Mar 18 00:31:33 cloud-init[3825]: util.py[DEBUG]: Failed to non-persistently adjust the system hostname to ip-10-30-10-155.us-west-2.i.test.abcdefg.example.com i.test.abcdefg.example.com us-west-2.test.abcdefg.example.com test.abcdefg.example.com us-west-2.compute.internal
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cloudinit/distros/init.py", line 230, in _apply_hostname
    util.subp(['hostname', hostname])
  File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 2105, in subp
    cmd=args)
ProcessExecutionError: Unexpected error while running command.
Command: ['hostname', 'ip-10-30-10-155.us-west-2.i.test.abcdefg.example.com i.test.abcdefg.example.com us-west-2.test.abcdefg.example.com test.abcdefg.example.com us-west-2.compute.internal']
Exit code: 1
Reason: -
Stdout:
Stderr: hostname: the specified hostname is invalid

@ubuntu-server-builder ubuntu-server-builder added bug Something isn't working correctly launchpad Migrated from Launchpad labels May 12, 2023
@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Paride Legovini(paride) wrote on 2020-04-24T14:07:14.894296+00:00

Thanks for taking the time to report this bug. Multiple domain names are currently not supported; the case falls in the warning given in the page you pointed to:


Some Linux operating systems accept multiple domain names separated by spaces. However, other Linux operating systems and Windows treat the value as a single domain, which results in unexpected behavior.

I'm not sure of what the Linux distributions supporting multiple domain names are doing; I imagine the first one is expected to become the true hostname of the instance, while all of them have to be added at least to /etc/hosts. In any case I agree it is something we should support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly launchpad Migrated from Launchpad
Projects
None yet
Development

No branches or pull requests

1 participant