Skip to content

Commit e05532e

Browse files
committed
mgr/dashboard: read cert from in-memory file
Fixes: https://tracker.ceph.com/issues/66303 Signed-off-by: Nizamudeen A <[email protected]>
1 parent af71de4 commit e05532e

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

src/pybind/mgr/dashboard/controllers/multi_cluster.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import base64
44
import json
55
import re
6+
import tempfile
67
import time
78
from urllib.parse import urlparse
89

@@ -37,8 +38,14 @@ def _proxy(self, method, base_url, path, params=None, payload=None, verify=False
3738
'Accept': 'application/vnd.ceph.api.v1.0+json',
3839
'Content-Type': 'application/json',
3940
}
41+
cert_file_path = verify
42+
if verify:
43+
with tempfile.NamedTemporaryFile(delete=False) as cert_file:
44+
cert_file.write(cert.encode('utf-8'))
45+
cert_file_path = cert_file.name
4046
response = requests.request(method, base_url + path, params=params,
41-
json=payload, verify=verify, cert=cert, headers=headers)
47+
json=payload, verify=cert_file_path,
48+
headers=headers)
4249
except Exception as e:
4350
raise DashboardException(
4451
"Could not reach {}, {}".format(base_url+path, e),
@@ -78,11 +85,13 @@ def auth(self, url: str, cluster_alias: str, username: str,
7885
payload={'url': cors_endpoints_string}, token=cluster_token,
7986
verify=ssl_verify, cert=ssl_certificate)
8087

81-
fsid = self._proxy('GET', url, 'api/health/get_cluster_fsid', token=cluster_token)
88+
fsid = self._proxy('GET', url, 'api/health/get_cluster_fsid', token=cluster_token,
89+
verify=ssl_verify, cert=ssl_certificate)
8290

8391
managed_by_clusters_content = self._proxy('GET', url,
8492
'api/settings/MANAGED_BY_CLUSTERS',
85-
token=cluster_token)
93+
token=cluster_token,
94+
verify=ssl_verify, cert=ssl_certificate)
8695

8796
managed_by_clusters_config = managed_by_clusters_content['value']
8897

@@ -95,7 +104,8 @@ def auth(self, url: str, cluster_alias: str, username: str,
95104

96105
# add prometheus targets
97106
prometheus_url = self._proxy('GET', url, 'api/multi-cluster/get_prometheus_api_url',
98-
token=cluster_token)
107+
token=cluster_token, verify=ssl_verify,
108+
cert=ssl_certificate)
99109

100110
_set_prometheus_targets(prometheus_url)
101111

@@ -145,7 +155,8 @@ def check_cluster_connection(self, url, payload, username, ssl_verify, ssl_certi
145155
component='multi-cluster')
146156

147157
user_content = self._proxy('GET', url, f'api/user/{username}',
148-
token=content['token'])
158+
token=content['token'], verify=ssl_verify,
159+
cert=ssl_certificate)
149160

150161
if 'status' in user_content and user_content['status'] == '403 Forbidden':
151162
raise DashboardException(msg='User is not an administrator',
@@ -164,7 +175,8 @@ def check_cluster_connection(self, url, payload, username, ssl_verify, ssl_certi
164175
cluster_token = content['token']
165176

166177
managed_by_clusters_content = self._proxy('GET', url, 'api/settings/MANAGED_BY_CLUSTERS',
167-
token=cluster_token)
178+
token=cluster_token, verify=ssl_verify,
179+
cert=ssl_certificate)
168180

169181
managed_by_clusters_config = managed_by_clusters_content['value']
170182

@@ -247,19 +259,23 @@ def reconnect_cluster(self, url: str, username=None, password=None,
247259
for cluster in cluster_details:
248260
if cluster["url"] == url and cluster["user"] == username:
249261
cluster['token'] = cluster_token
262+
cluster['ssl_verify'] = ssl_verify
263+
cluster['ssl_certificate'] = ssl_certificate
250264
Settings.MULTICLUSTER_CONFIG = multicluster_config
251265
return True
252266

253267
@Endpoint('PUT')
254268
@UpdatePermission
255269
# pylint: disable=unused-variable
256-
def edit_cluster(self, url, cluster_alias, username):
270+
def edit_cluster(self, url, cluster_alias, username, verify=False, ssl_certificate=None):
257271
multicluster_config = self.load_multi_cluster_config()
258272
if "config" in multicluster_config:
259273
for key, cluster_details in multicluster_config["config"].items():
260274
for cluster in cluster_details:
261275
if cluster["url"] == url and cluster["user"] == username:
262276
cluster['cluster_alias'] = cluster_alias
277+
cluster['ssl_verify'] = verify
278+
cluster['ssl_certificate'] = ssl_certificate if verify else ''
263279
Settings.MULTICLUSTER_CONFIG = multicluster_config
264280
return Settings.MULTICLUSTER_CONFIG
265281

@@ -291,7 +307,9 @@ def delete_cluster(self, cluster_name, cluster_user):
291307

292308
managed_by_clusters_content = self._proxy('GET', cluster_url,
293309
'api/settings/MANAGED_BY_CLUSTERS',
294-
token=cluster_token)
310+
token=cluster_token,
311+
verify=cluster_ssl_verify,
312+
cert=cluster_ssl_certificate)
295313

296314
managed_by_clusters_config = managed_by_clusters_content['value']
297315
for cluster in managed_by_clusters_config:

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
197197
case 'edit':
198198
this.subs.add(
199199
this.multiClusterService
200-
.editCluster(this.cluster.url, clusterAlias, this.cluster.user)
200+
.editCluster(this.cluster.url, clusterAlias, this.cluster.user, ssl, ssl_certificate)
201201
.subscribe({
202202
...commonSubscribtion,
203203
complete: () => this.handleSuccess($localize`Cluster updated successfully`)

src/pybind/mgr/dashboard/frontend/src/app/shared/api/multi-cluster.service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,19 @@ export class MultiClusterService {
115115
return this.http.delete(`api/multi-cluster/delete_cluster/${clusterName}/${clusterUser}`);
116116
}
117117

118-
editCluster(url: any, clusterAlias: string, username: string) {
118+
editCluster(
119+
url: any,
120+
clusterAlias: string,
121+
username: string,
122+
verify = false,
123+
ssl_certificate = ''
124+
) {
119125
return this.http.put('api/multi-cluster/edit_cluster', {
120126
url,
121127
cluster_alias: clusterAlias,
122-
username
128+
username: username,
129+
verify: verify,
130+
ssl_certificate: ssl_certificate
123131
});
124132
}
125133

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7222,10 +7222,15 @@ paths:
72227222
properties:
72237223
cluster_alias:
72247224
type: string
7225+
ssl_certificate:
7226+
type: string
72257227
url:
72267228
type: string
72277229
username:
72287230
type: string
7231+
verify:
7232+
default: false
7233+
type: boolean
72297234
required:
72307235
- url
72317236
- cluster_alias

0 commit comments

Comments
 (0)