Skip to content

Commit f3c211a

Browse files
author
Alexander Stefanov
committed
validate hostnames
1 parent ecac079 commit f3c211a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

build-rpm.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@
6666
src_rpm = []
6767
logfile = output_dir + '/' + 'test.' + time.strftime("%m-%d-%Y-%H-%M-%S") + '.log'
6868

69+
def is_valid_hostname(hostname):
70+
if hostname[-1] == ".":
71+
hostname = hostname[:-1] # strip exactly one dot from the right, if present
72+
if len(hostname) > 255:
73+
return False
74+
if re.match(r"[a-f0-9]{12}", hostname.split(".")[0]):
75+
print("container hostname does not pass naming policy [{}]".format(hostname))
76+
return False
77+
6978

7079
def print_log(message):
7180
try:
@@ -520,6 +529,8 @@ def cleanup_all():
520529

521530
if __name__ == '__main__':
522531
cleanup_all()
532+
if is_valid_hostname(socket.gethostname()) is False:
533+
sys.exit(1)
523534
if rerun_tests == 'true':
524535
relaunch_tests()
525536
else:

0 commit comments

Comments
 (0)