Skip to content

Commit 74af01f

Browse files
committed
[HWORKS-1624][APPEND] ca_chain.pem is needed when calling _get_credentials for internal clients
1 parent 10726a9 commit 74af01f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

python/hopsworks_common/client/hopsworks.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, hostname_verification):
5050
self._hostname_verification = os.environ.get(
5151
self.HOPSWORKS_HOSTNAME_VERIFICATION, "{}".format(hostname_verification)
5252
).lower() in ("true", "1", "y", "yes")
53-
self._hopsworks_ca_trust_store_path = self._get_ca_chain_path()
53+
self._hopsworks_ca_trust_store_path = self._materialize_ca_chain()
5454

5555
self._project_id = os.environ[self.PROJECT_ID]
5656
self._project_name = self._project_name()
@@ -67,10 +67,23 @@ def __init__(self, hostname_verification):
6767

6868
credentials = self._get_credentials(self._project_id)
6969

70-
self._write_pem_file(credentials["caChain"], self._get_ca_chain_path())
7170
self._write_pem_file(credentials["clientCert"], self._get_client_cert_path())
7271
self._write_pem_file(credentials["clientKey"], self._get_client_key_path())
7372

73+
def _materialize_ca_chain(self):
74+
"""Convert truststore from jks to pem and return the location"""
75+
ca_chain_path = self._get_ca_chain_path()
76+
if not ca_chain_path.exists():
77+
keystore_pw = self._cert_key
78+
ks = jks.KeyStore.load(
79+
self._get_jks_key_store_path(), keystore_pw, try_decrypt_keys=True
80+
)
81+
ts = jks.KeyStore.load(
82+
self._get_jks_trust_store_path(), keystore_pw, try_decrypt_keys=True
83+
)
84+
self._write_ca_chain(ks, ts, ca_chain_path)
85+
return str(ca_chain_path)
86+
7487
def _get_hopsworks_rest_endpoint(self):
7588
"""Get the hopsworks REST endpoint for making requests to the REST API."""
7689
return os.environ[self.REST_ENDPOINT]

0 commit comments

Comments
 (0)