Skip to content

Commit b0c1f34

Browse files
committed
MB-35254 Merge branch 'alice'
* alice: MB-35254 Verify the CA cert correctly Change-Id: I9397e34add4d38eb94539ab559ca413e3963d1c9
2 parents ea2e91a + 2ddc1a0 commit b0c1f34

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

cbmgr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def __init__(self, deprecate_username=False, deprecate_password=False, cluster_d
470470
help="Use ssl when connecting to Couchbase (Deprecated)")
471471
group.add_argument("--no-ssl-verify", dest="ssl_verify", action="store_false", default=True,
472472
help="Skips SSL verification of certificates against the CA")
473-
group.add_argument("--cacert", dest="cacert", default=None,
473+
group.add_argument("--cacert", dest="cacert", default=True,
474474
help="Verifies the cluster identity with this certificate")
475475
group.add_argument("-h", "--help", action=CBHelpAction, klass=self,
476476
help="Prints the short or long help message")

cluster_manager.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def g(*args, **kwargs):
4646
'your client certificate.']
4747
elif str(e).startswith('[SSL]'):
4848
return None, [f'Unable to connect with the given CA certificate: {str(e)}']
49-
return None, [f'Unable to connect to host at {cm.hostname}']
49+
return None, [f'Unable to connect to host at {cm.hostname}: {str(e)}']
5050
except requests.exceptions.ReadTimeout as e:
5151
return None, [f'Request to host `{url}` timed out after {cm.timeout} seconds']
5252
return g
@@ -63,12 +63,19 @@ class ClusterManager(object):
6363
"""A set of REST API's for managing a Couchbase cluster"""
6464

6565
def __init__(self, hostname, username, password, sslFlag=False, verifyCert=True,
66-
cert=None, debug=False, timeout=DEFAULT_REQUEST_TIMEOUT):
66+
caCert=True, debug=False, timeout=DEFAULT_REQUEST_TIMEOUT, cert=None):
6767
hostname = hostname.replace("couchbase://", "http://", 1)
6868
hostname = hostname.replace("couchbases://", "https://", 1)
6969

7070
self.hostname = hostname
71+
# verify argument on Request functions can take boolean or a path to a CA if
72+
# a path is not provide but the cert still needs to be verified it should use
73+
# the system provided CAs
7174
self.verifyCert = verifyCert
75+
self.caCert = caCert
76+
if not verifyCert:
77+
self.caCert = False
78+
# This is for client side certs which is currently not used.
7279
self.cert = cert
7380

7481
parsed = urllib.parse.urlparse(hostname)
@@ -83,7 +90,7 @@ def __init__(self, hostname, username, password, sslFlag=False, verifyCert=True,
8390
# Certificates and verification are not used when the ssl flag is
8491
# specified.
8592
self.verifyCert = False
86-
self.cert = None
93+
self.caCert = False
8794

8895
self.username = username
8996
self.password = password
@@ -1853,7 +1860,7 @@ def node_get_address_family(self, host):
18531860
def _get(self, url):
18541861
if self.debug:
18551862
print(f'GET {url}')
1856-
response = requests.get(url, auth=(self.username, self.password), verify=self.verifyCert,
1863+
response = requests.get(url, auth=(self.username, self.password), verify=self.caCert,
18571864
cert=self.cert, timeout=self.timeout,
18581865
headers=self.headers)
18591866
return _handle_response(response, self.debug)
@@ -1865,7 +1872,7 @@ def _post_form_encoded(self, url, params):
18651872
params = {}
18661873
print(f'POST {url} {urllib.parse.urlencode(params)}')
18671874
response = requests.post(url, auth=(self.username, self.password), data=params,
1868-
cert=self.cert, verify=self.verifyCert, timeout=self.timeout,
1875+
cert=self.cert, verify=self.caCert, timeout=self.timeout,
18691876
headers=self.headers)
18701877
return _handle_response(response, self.debug)
18711878

@@ -1876,7 +1883,7 @@ def _post_json(self, url, params):
18761883
params = {}
18771884
print(f'POST {url} {json.dumps(params)}')
18781885
response = requests.post(url, auth=(self.username, self.password), json=params,
1879-
cert=self.cert, verify=self.verifyCert, timeout=self.timeout,
1886+
cert=self.cert, verify=self.caCert, timeout=self.timeout,
18801887
headers=self.headers)
18811888
return _handle_response(response, self.debug)
18821889

@@ -1887,7 +1894,7 @@ def _put(self, url, params):
18871894
params = {}
18881895
print(f'PUT {url} {urllib.parse.urlencode(params)}')
18891896
response = requests.put(url, params, auth=(self.username, self.password),
1890-
cert=None, verify=self.verifyCert, timeout=self.timeout,
1897+
cert=None, verify=self.caCert, timeout=self.timeout,
18911898
headers=self.headers)
18921899
return _handle_response(response, self.debug)
18931900

@@ -1898,7 +1905,7 @@ def _put_json(self, url, params):
18981905
params = {}
18991906
print(f'PUT {url} {json.dumps(params)}')
19001907
response = requests.put(url, auth=(self.username, self.password), json=params,
1901-
cert=None, verify=self.verifyCert, timeout=self.timeout,
1908+
cert=None, verify=self.caCert, timeout=self.timeout,
19021909
headers = self.headers)
19031910
return _handle_response(response, self.debug)
19041911

@@ -1909,7 +1916,7 @@ def _delete(self, url, params):
19091916
params = {}
19101917
print(f'DELETE {url} {urllib.parse.urlencode(params)}')
19111918
response = requests.delete(url, auth=(self.username, self.password), data=params,
1912-
cert=None, verify=self.verifyCert, timeout=self.timeout,
1919+
cert=None, verify=self.caCert, timeout=self.timeout,
19131920
headers=self.headers)
19141921
return _handle_response(response, self.debug)
19151922

0 commit comments

Comments
 (0)