Skip to content

Commit 716ce7b

Browse files
authored
Merge pull request #145 from bcgov/dev
allow exact match upstream host validation (#143)
2 parents 81d0504 + f4a6bbe commit 716ce7b

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.github/workflows/pr-reminder.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'Send review reminders'
22
on:
33
schedule:
4-
- cron: '30 8 * * 1,2,3,4,5' # Scheduled to run at 1:30 AM, weekdays
4+
- cron: '30 13 * * 1,2,3,4,5' # Scheduled to run at 5:30 AM PST, weekdays
55

66
jobs:
77
remind:

microservices/gatewayApi/tests/utils/test_validate_upstream.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ def test_upstream_pass_validation(app):
137137

138138
validate_upstream (y, { "perm-upstreams": ["my-namespace"]}, [], True)
139139

140+
def test_upstream_pass_validation_exact_match(app):
141+
payload = '''
142+
services:
143+
- name: my-service
144+
tags: ["ns.mytest", "another"]
145+
host: 192.168.1.1
146+
'''
147+
y = yaml.load(payload, Loader=yaml.FullLoader)
148+
149+
validate_upstream (y, { "perm-upstreams": ["192.168.1.1"]}, [], True)
150+
140151
def test_upstream_fail_validation(app):
141152
payload = '''
142153
services:

microservices/gatewayApi/utils/validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def validate_upstream_host(_host, errors, allow_protected_ns, protected_kube_nam
5252

5353
if host in restricted:
5454
errors.append("service upstream is invalid (e1)")
55-
elif host.endswith('svc'):
55+
elif host.endswith('.svc'):
5656
partials = host.split('.')
5757
# get the namespace, and make sure it is not in the protected_kube_namespaces list
5858
if len(partials) != 3:
@@ -61,7 +61,7 @@ def validate_upstream_host(_host, errors, allow_protected_ns, protected_kube_nam
6161
errors.append("service upstream is invalid (e3)")
6262
elif do_validate_upstreams and (partials[1] in perm_upstreams) is False:
6363
errors.append("service upstream is invalid (e6)")
64-
elif host.endswith('svc.cluster.local'):
64+
elif host.endswith('.svc.cluster.local'):
6565
partials = host.split('.')
6666
# get the namespace, and make sure it is not in the protected_kube_namespaces list
6767
if len(partials) != 5:
@@ -70,5 +70,5 @@ def validate_upstream_host(_host, errors, allow_protected_ns, protected_kube_nam
7070
errors.append("service upstream is invalid (e5)")
7171
elif do_validate_upstreams and (partials[1] in perm_upstreams) is False:
7272
errors.append("service upstream is invalid (e6)")
73-
elif do_validate_upstreams:
73+
elif do_validate_upstreams and (host in perm_upstreams) is False:
7474
errors.append("service upstream is invalid (e6)")

0 commit comments

Comments
 (0)