Skip to content

Commit f5dfb32

Browse files
tanadeauTrent Nadeau
authored and
Trent Nadeau
committed
avahi-cname-manager: Fix CNAME regex to match OpenShift constraints
Bug 1258562 Bugzilla link https://bugzilla.redhat.com/show_bug.cgi?id=1258562 The old CNAME validity regex is far more restrictive than OpenShift, which allows alphanumeric domains while the regex allowed only alphabetical.
1 parent e8bbb78 commit f5dfb32

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

extras/avahi-cname-manager/bin/avahi-cname-manager

+7-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Avahi
1616
TYPE_CNAME = 0x05
1717
TYPE_A = 0x01
1818
TTL = 60
19+
CNAME_REGEX = /^[a-zA-Z0-9]+(?:\-[a-zA-Z0-9]+)?\.local$/
1920

2021
##
2122
# Class initializer. Creates a DBUS connection to Avahi service.
@@ -38,9 +39,8 @@ class Avahi
3839
# @return status Integer HTTP codes 200, 400, 404
3940
# @return message String Detailed message of success or error
4041
def remove_alias(cname)
41-
if cname.nil? || cname.empty? ||
42-
(not cname.match(/[a-z]+(.[a-z]+)?.local/))
43-
return 400, "Invlaid CNAME '#{cname}'"
42+
if cname.nil? || cname.empty? || (not cname.match(CNAME_REGEX))
43+
return 400, "Invalid CNAME '#{cname}'"
4444
return 400, "Invalid CNAME"
4545
end
4646

@@ -81,15 +81,13 @@ class Avahi
8181
# @return status Integer HTTP codes 200, 400, 404
8282
# @return message String Detailed message of success or error
8383
def add_alias(cname, fqdn)
84-
if cname.nil? || cname.empty? ||
85-
(not cname.match(/[a-z]+(.[a-z]+)?.local/))
86-
return 400, "Invlaid CNAME '#{cname}'"
84+
if cname.nil? || cname.empty? || (not cname.match(CNAME_REGEX))
85+
return 400, "Invalid CNAME '#{cname}'"
8786
return 400, "Invalid CNAME"
8887
end
8988

90-
if fqdn.nil? || fqdn.empty? ||
91-
(not fqdn.match(/[a-z]+(.[a-z]+)?.local/))
92-
return 400, "Invlaid FQDN '#{fqdn}'"
89+
if fqdn.nil? || fqdn.empty? || (not fqdn.match(CNAME_REGEX))
90+
return 400, "Invalid FQDN '#{fqdn}'"
9391
return 400, "Invalid FQDN"
9492
end
9593

0 commit comments

Comments
 (0)