Skip to content

Commit

Permalink
Update method for checking endpoint protocol (#769) (#775)
Browse files Browse the repository at this point in the history
Update method for checking endpoint protocol

The `https` method is used to check if an endpoint is expected to
be http or https. One of the checks it performs is to examine the
the certificates relation. If the relation is present then it looks
for the existance of a CA. However the OpenStack charms do not
switch to https until a certificate is provided via the certificates
relation. This means there can be a disconnect if the
certificate provider has provided a CA but has not yet provided
the unit specific certificates. If this happens then the payload
will still be using http but the `https` method will return True.

This patch updates the `https` method to return False if an unfilled
certificate request exists.

(cherry picked from commit 6064a34)

Co-authored-by: Liam Young <liam.young@canonical.com>
  • Loading branch information
freyes and Liam Young committed May 10, 2023
1 parent b9444c2 commit ed01437
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions charmhelpers/contrib/hahelpers/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ def https():
return True
if config_get('ssl_cert') and config_get('ssl_key'):
return True
# Local import to avoid ciruclar dependency.
import charmhelpers.contrib.openstack.cert_utils as cert_utils
if (
cert_utils.get_certificate_request() and not
cert_utils.get_requests_for_local_unit("certificates")
):
return False
for r_id in relation_ids('certificates'):
for unit in relation_list(r_id):
ca = relation_get('ca', rid=r_id, unit=unit)
Expand Down
26 changes: 24 additions & 2 deletions tests/contrib/hahelpers/test_cluster_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,11 @@ def test_https_cert_key_in_config(self):
]
self.assertTrue(cluster_utils.https())

def test_https_cert_key_in_identity_relation(self):
@patch('charmhelpers.contrib.openstack.cert_utils')
def test_https_cert_key_in_identity_relation(self, cert_utils):
'''It determines https is available if cert in identity-service'''
cert_utils.get_certificate_request.return_value = False
cert_utils.get_requests_for_local_unit.return_value = {}
self.config_get.return_value = False
self.relation_ids.return_value = 'identity-service:0'
self.relation_list.return_value = 'keystone/0'
Expand All @@ -244,8 +247,27 @@ def test_https_cert_key_in_identity_relation(self):
]
self.assertTrue(cluster_utils.https())

def test_https_cert_key_incomplete_identity_relation(self):
@patch('charmhelpers.contrib.openstack.cert_utils')
def test_https_cert_req_pending(self, cert_utils):
'''It determines https is available if cert in identity-service'''
cert_utils.get_certificate_request.return_value = True
cert_utils.get_requests_for_local_unit.return_value = {}
self.config_get.return_value = False
self.relation_ids.return_value = 'identity-service:0'
self.relation_list.return_value = 'keystone/0'
self.relation_get.side_effect = [
'yes', # relation_get('https_keystone')
'cert', # relation_get('ssl_cert')
'key', # relation_get('ssl_key')
'ca_cert', # relation_get('ca_cert')
]
self.assertFalse(cluster_utils.https())

@patch('charmhelpers.contrib.openstack.cert_utils')
def test_https_cert_key_incomplete_identity_relation(self, cert_utils):
'''It determines https unavailable if cert not in identity-service'''
cert_utils.get_certificate_request.return_value = False
cert_utils.get_requests_for_local_unit.return_value = {}
self.config_get.return_value = False
self.relation_ids.return_value = 'identity-service:0'
self.relation_list.return_value = 'keystone/0'
Expand Down

0 comments on commit ed01437

Please sign in to comment.