From 1c335c690b4a1749c09460861cd033a0ffa7be4c Mon Sep 17 00:00:00 2001 From: Jamie Taylor Date: Wed, 10 Feb 2016 13:57:38 -0500 Subject: [PATCH 1/2] Replace unsafe characters in SET_HOSTNAME. When setting the hostname from $SET_HOSTNAME, replace any characters not allowed in hostnames (as specified in RFC 952) with a hyphen. This is enables a VM template to safely use the VM's name as the hostname (by setting the context variable SET_HOSTNAME=$NAME). --- base_arch/etc/one-context.d/05-hostname | 2 +- base_deb.one/etc/one-context.d/05-hostname | 2 +- base_rpm.one/etc/one-context.d/05-hostname | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/base_arch/etc/one-context.d/05-hostname b/base_arch/etc/one-context.d/05-hostname index c94549e..60e732b 100755 --- a/base_arch/etc/one-context.d/05-hostname +++ b/base_arch/etc/one-context.d/05-hostname @@ -20,7 +20,7 @@ function get_dns_name() { } if [ -n "$SET_HOSTNAME" ]; then - set_hostname $SET_HOSTNAME + set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g') elif [ -n "$DNS_HOSTNAME" ]; then set_hostname $(get_dns_name) fi diff --git a/base_deb.one/etc/one-context.d/05-hostname b/base_deb.one/etc/one-context.d/05-hostname index c5f9e1d..b0b08c7 100755 --- a/base_deb.one/etc/one-context.d/05-hostname +++ b/base_deb.one/etc/one-context.d/05-hostname @@ -22,7 +22,7 @@ function get_dns_name() { } if [ -n "$SET_HOSTNAME" ]; then - set_hostname $SET_HOSTNAME + set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g') elif [ -n "$DNS_HOSTNAME" ]; then set_hostname $(get_dns_name) fi diff --git a/base_rpm.one/etc/one-context.d/05-hostname b/base_rpm.one/etc/one-context.d/05-hostname index dd43e8d..4532c51 100755 --- a/base_rpm.one/etc/one-context.d/05-hostname +++ b/base_rpm.one/etc/one-context.d/05-hostname @@ -23,7 +23,7 @@ function get_dns_name() { } if [ -n "$SET_HOSTNAME" ]; then - set_hostname $SET_HOSTNAME + set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g') elif [ -n "$DNS_HOSTNAME" ]; then set_hostname $(get_dns_name) fi From 6f07527f36d59a11e6415b535cbf89ce93c36f01 Mon Sep 17 00:00:00 2001 From: Jamie Taylor Date: Thu, 11 Feb 2016 09:50:17 -0500 Subject: [PATCH 2/2] Strip leading and trailing hyphens Strip leading and trailing hyphens in the resulting munged hostname. Leading and trailing hyphens are not valid according to RFCs 952 and 1123. (This problem surfaces immediately when using the default configuration of OneFlow, since it names new VMs ending with a parenthesis.) --- base_arch/etc/one-context.d/05-hostname | 2 +- base_deb.one/etc/one-context.d/05-hostname | 2 +- base_rpm.one/etc/one-context.d/05-hostname | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/base_arch/etc/one-context.d/05-hostname b/base_arch/etc/one-context.d/05-hostname index 60e732b..d401dd0 100755 --- a/base_arch/etc/one-context.d/05-hostname +++ b/base_arch/etc/one-context.d/05-hostname @@ -20,7 +20,7 @@ function get_dns_name() { } if [ -n "$SET_HOSTNAME" ]; then - set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g') + set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g' -e 's/^-*//g' -e 's/-*$//g') elif [ -n "$DNS_HOSTNAME" ]; then set_hostname $(get_dns_name) fi diff --git a/base_deb.one/etc/one-context.d/05-hostname b/base_deb.one/etc/one-context.d/05-hostname index b0b08c7..92bcc76 100755 --- a/base_deb.one/etc/one-context.d/05-hostname +++ b/base_deb.one/etc/one-context.d/05-hostname @@ -22,7 +22,7 @@ function get_dns_name() { } if [ -n "$SET_HOSTNAME" ]; then - set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g') + set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g' -e 's/^-*//g' -e 's/-*$//g') elif [ -n "$DNS_HOSTNAME" ]; then set_hostname $(get_dns_name) fi diff --git a/base_rpm.one/etc/one-context.d/05-hostname b/base_rpm.one/etc/one-context.d/05-hostname index 4532c51..df77aa0 100755 --- a/base_rpm.one/etc/one-context.d/05-hostname +++ b/base_rpm.one/etc/one-context.d/05-hostname @@ -23,7 +23,7 @@ function get_dns_name() { } if [ -n "$SET_HOSTNAME" ]; then - set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g') + set_hostname $(echo "$SET_HOSTNAME" | sed -e 's/[^-a-zA-Z0-9]/-/g' -e 's/^-*//g' -e 's/-*$//g') elif [ -n "$DNS_HOSTNAME" ]; then set_hostname $(get_dns_name) fi