Skip to content

Commit c218431

Browse files
authoredSep 20, 2024
[HWORKS-1624][APPEND] ca_chain.pem is needed when calling _get_credentials for internal clients (#337)
1 parent 10726a9 commit c218431

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed
 

‎python/hopsworks_common/client/hopsworks.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
from hopsworks_common.client import auth, base
2222

2323

24+
try:
25+
import jks
26+
except ImportError:
27+
pass
28+
29+
2430
class Client(base.Client):
2531
HOPSWORKS_HOSTNAME_VERIFICATION = "HOPSWORKS_HOSTNAME_VERIFICATION"
2632
DOMAIN_CA_TRUSTSTORE_PEM = "DOMAIN_CA_TRUSTSTORE_PEM"
@@ -50,7 +56,7 @@ def __init__(self, hostname_verification):
5056
self._hostname_verification = os.environ.get(
5157
self.HOPSWORKS_HOSTNAME_VERIFICATION, "{}".format(hostname_verification)
5258
).lower() in ("true", "1", "y", "yes")
53-
self._hopsworks_ca_trust_store_path = self._get_ca_chain_path()
59+
self._hopsworks_ca_trust_store_path = self._materialize_ca_chain()
5460

5561
self._project_id = os.environ[self.PROJECT_ID]
5662
self._project_name = self._project_name()
@@ -67,10 +73,23 @@ def __init__(self, hostname_verification):
6773

6874
credentials = self._get_credentials(self._project_id)
6975

70-
self._write_pem_file(credentials["caChain"], self._get_ca_chain_path())
7176
self._write_pem_file(credentials["clientCert"], self._get_client_cert_path())
7277
self._write_pem_file(credentials["clientKey"], self._get_client_key_path())
7378

79+
def _materialize_ca_chain(self):
80+
"""Convert truststore from jks to pem and return the location"""
81+
ca_chain_path = Path(self._get_ca_chain_path())
82+
if not ca_chain_path.exists():
83+
keystore_pw = self._cert_key
84+
ks = jks.KeyStore.load(
85+
self._get_jks_key_store_path(), keystore_pw, try_decrypt_keys=True
86+
)
87+
ts = jks.KeyStore.load(
88+
self._get_jks_trust_store_path(), keystore_pw, try_decrypt_keys=True
89+
)
90+
self._write_ca_chain(ks, ts, ca_chain_path)
91+
return str(ca_chain_path)
92+
7493
def _get_hopsworks_rest_endpoint(self):
7594
"""Get the hopsworks REST endpoint for making requests to the REST API."""
7695
return os.environ[self.REST_ENDPOINT]

‎python/hopsworks_common/connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
HOPSWORKS_PORT_DEFAULT = 443
4040
HOSTNAME_VERIFICATION_DEFAULT = os.environ.get(
41-
"HOPSWORKS_HOSTNAME_VERIFICATION", "True"
41+
"HOPSWORKS_HOSTNAME_VERIFICATION", "False"
4242
).lower() in ("true", "1", "y", "yes")
4343
# alias for backwards compatibility:
4444
HOPSWORKS_HOSTNAME_VERIFICATION_DEFAULT = HOSTNAME_VERIFICATION_DEFAULT

‎python/tests/test_connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_constants(self):
3131
# adding / removing / updating tests, if necessary.
3232
assert HOSTS.APP_HOST == "c.app.hopsworks.ai"
3333
assert HOPSWORKS_PORT_DEFAULT == 443
34-
assert HOSTNAME_VERIFICATION_DEFAULT
34+
assert HOSTNAME_VERIFICATION_DEFAULT is False
3535

3636
# constructor
3737

0 commit comments

Comments
 (0)