The instance hostname didn't match the RFC 952 and 1123's definition

Bug #1495388 reported by Alex Xu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Medium
Alex Xu
Kilo
Fix Released
Undecided
Unassigned

Bug Description

The instance hostname is convert from instance's name. There is method used to do that https://github.com/openstack/nova/blob/master/nova/utils.py#L774

But looks like this method didn't match all the cases described in the RFC

For example, if the host name just one character, like 'A', this method return 'A‘ also, this isn't allowed by RFC.

And the hostname was updated at wrong place: https://github.com/openstack/nova/blob/master/nova/compute/api.py#L641
It just update the instance db entry again after instance entry creation. We can populate the hostname before instance creation, then we can save one db operation.

Revision history for this message
Mark Doffman (mjdoffma) wrote :

Is this causing any specific issues?

There is a fairly lengthy discussion about single character hostnames here http://serverfault.com/questions/162038/are-one-letter-host-names-valid

The general impression I get is that its supported in DNS domain names and probably elsewhere as there is some ambiguity between RFC952 and RFC1123.

If this isn't causing you any specific issues I'd think that its best to leave it alone rather than adding restrictions to the api that currently don't exist and could break things.

As for the hostname being updated in the wrong place this is actually fairly well explained in the codebase. https://github.com/openstack/nova/blob/master/nova/compute/api.py#L1377

The instance needs to be created first to obtain a uuid that is used in the hostname for multi instance api calls.

Changed in nova:
status: New → Incomplete
Changed in nova:
importance: Undecided → Medium
Revision history for this message
Eli Qiao (taget-9) wrote :

co-worked with alex xu : we found that current v2.1 allow to create an instance from a Chinese character, but the hostname is not correctly set by sanitize_hostname, it is empty.

            hostname = display_name
            instance.hostname = utils.sanitize_hostname(hostname)

if display_name = ‘哈哈哈’

then instance.hostname = “”

we need to fix this?

Revision history for this message
Alex Xu (xuhj) wrote :

@Mark, thanks for the comments. I think you are right, we can just leave the single character case alone. And the host update problem, I think you are right also, that isn't a problem.

@Eli, thanks for working with me on this.

Also the display_name = "-----", will lead to instance.hostname = ""

I think we should fix this.

My first idea is if the hostname become empty after strip invalid characters, we use "server [uuid]" instead of it.

But that still not good for non-english users. Maybe we can enable user to set hostname in the future with microversions

Alex Xu (xuhj)
Changed in nova:
status: Incomplete → Confirmed
assignee: nobody → Eli Qiao (taget-9)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/224438

Changed in nova:
status: Confirmed → In Progress
tags: added: api liberty-rc-potential
Changed in nova:
assignee: Eli Qiao (taget-9) → Alex Xu (xuhj)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/224438
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=bc6f30de953303604625e84ad2345cfb595170d2
Submitter: Jenkins
Branch: master

commit bc6f30de953303604625e84ad2345cfb595170d2
Author: Eli Qiao <email address hidden>
Date: Thu Sep 17 13:57:24 2015 +0800

    Give instance default hostname if hostname is empty

    Instance hostname is generated by displayname, currently, displayname
    can be '----', and other Non-ASCII character such as Chinese characters,
    sanitize_hostname will return empty in such cases.

    This patch adds a helper function _default_host_name to give an instance
    default name if sanitize_hostname returns empty hostname. And,
    sanitize_hostname will truncated to 63 if the host name is too long.

    Also Window, Linux, and Dnsmasq have different limitation:

    Windows: 255 (net_bios limit to 15, but window will truncate it)
    Linux: 64
    Dnsmasq: 63

    Due to nova-network will leverage dnsmasq to set hostname, so we chose
    63.

    Besides, added more test cases to cover sanitize_hostname.

    DocImpact
    Change-Id: I443b51e0576cf657d96e498d6700bfc34d987301
    Closes-Bug: #1495388
    Co-authored-by: Alex Xu <email address hidden>

Changed in nova:
status: In Progress → Fix Committed
Matt Riedemann (mriedem)
tags: removed: liberty-rc-potential
Thierry Carrez (ttx)
Changed in nova:
milestone: none → liberty-rc1
status: Fix Committed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/kilo)

Fix proposed to branch: stable/kilo
Review: https://review.openstack.org/227159

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: stable/kilo
Review: https://review.openstack.org/227176

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on nova (stable/kilo)

Change abandoned by Alex Xu (<email address hidden>) on branch: stable/kilo
Review: https://review.openstack.org/227159

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/kilo)

Reviewed: https://review.openstack.org/227176
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=db45b1eca8a3db8f1b5153c58b138711ed69c388
Submitter: Jenkins
Branch: stable/kilo

commit db45b1eca8a3db8f1b5153c58b138711ed69c388
Author: Eli Qiao <email address hidden>
Date: Thu Sep 17 13:57:24 2015 +0800

    Give instance default hostname if hostname is empty

    Instance hostname is generated by displayname, currently, displayname
    can be '----', and other Non-ASCII character such as Chinese characters,
    sanitize_hostname will return empty in such cases.

    This patch adds a helper function _default_host_name to give an instance
    default name if sanitize_hostname returns empty hostname. And,
    sanitize_hostname will truncated to 63 if the host name is too long.

    Also Window, Linux, and Dnsmasq have different limitation:

    Windows: 255 (net_bios limit to 15, but window will truncate it)
    Linux: 64
    Dnsmasq: 63

    Due to nova-network will leverage dnsmasq to set hostname, so we chose
    63.

    Besides, added more test cases to cover sanitize_hostname.

    DocImpact
    Closes-Bug: #1495388
    Co-authored-by: Alex Xu <email address hidden>

    (cherry picked from commit bc6f30de953303604625e84ad2345cfb595170d2)

    Conflicts:
     nova/tests/unit/compute/test_compute_api.py
     nova/tests/unit/test_utils.py
     nova/utils.py

    Change-Id: I443b51e0576cf657d96e498d6700bfc34d987301

tags: added: in-stable-kilo
Thierry Carrez (ttx)
Changed in nova:
milestone: liberty-rc1 → 12.0.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.