You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by yz...@apache.org on 2026/10/15 03:38:46 UTC

(polaris) branch main updated: TLS options for Python client (#5790)

This is an automated email from the ASF dual-hosted git repository.

MonkeyCanCode pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new f838a62e20 TLS options for Python client (#5790)
f838a62e20 is described below

commit f838a62e20e7de72946d250883e8d9b1d6d2f68e
Author: Alex Stephen <13...@users.noreply.github.com>
AuthorDate: Wed Oct 14 20:38:41 2026 -0700

    TLS options for Python client (#5790)
    
    * TLS options for Python client
    
    * Add changelog entry
---
 CHANGELOG.md                                       |  1 +
 .../apache_polaris/cli/api_client_builder.py       | 16 ++++++--
 client/python/apache_polaris/cli/command/utils.py  |  2 +
 client/python/apache_polaris/cli/constants.py      |  2 +
 client/python/apache_polaris/cli/options/parser.py | 10 +++++
 client/python/tests/cli_test_utils.py              |  2 +
 client/python/tests/test_api_client_builder.py     | 45 ++++++++++++++++++++++
 .../in-dev/unreleased/command-line-interface.md    |  2 +
 8 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8bfff3991..0a968949ad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -93,6 +93,7 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
 
 - Python CLI: added `register` support for both `tables` and `views` commands
 - Python CLI: added `namespaces update` to set and remove namespace properties
+- Python CLI: added global `--ssl-ca-cert` and `--insecure` options to verify the server with a custom CA bundle or to disable TLS certificate verification
 
 ### Changes
 
diff --git a/client/python/apache_polaris/cli/api_client_builder.py b/client/python/apache_polaris/cli/api_client_builder.py
index 9968af639c..07405c2976 100644
--- a/client/python/apache_polaris/cli/api_client_builder.py
+++ b/client/python/apache_polaris/cli/api_client_builder.py
@@ -44,6 +44,8 @@ class BuilderConfig:
     def __init__(self, options: Namespace):
         self.options = options
         self.proxy = options.proxy
+        self.ssl_ca_cert = options.ssl_ca_cert
+        self.insecure = options.insecure
         self.access_token = options.access_token
 
     @cached_property
@@ -140,13 +142,20 @@ class ApiClientBuilder:
         self.conf = BuilderConfig(options)
         self.direct_auth_enabled = direct_authentication
 
+    def _new_configuration(self) -> Configuration:
+        config = Configuration(
+            host=self.conf.management_url, ssl_ca_cert=self.conf.ssl_ca_cert
+        )
+        config.proxy = self.conf.proxy
+        config.verify_ssl = not self.conf.insecure
+        return config
+
     def _get_token(self) -> str:
         header_params = {"Content-Type": "application/x-www-form-urlencoded"}
         if self.conf.header and self.conf.realm:
             header_params[self.conf.header] = self.conf.realm
 
-        conf = Configuration(host=self.conf.management_url)
-        conf.proxy = self.conf.proxy
+        conf = self._new_configuration()
         api_client = ApiClient(conf)
         response = api_client.call_api(
             "POST",
@@ -196,8 +205,7 @@ class ApiClientBuilder:
                 f" {CLIENT_SECRET_ENV}."
             )
 
-        config = Configuration(host=self.conf.management_url)
-        config.proxy = self.conf.proxy
+        config = self._new_configuration()
         if has_access_token:
             config.access_token = self.conf.access_token
         elif has_client_secret:
diff --git a/client/python/apache_polaris/cli/command/utils.py b/client/python/apache_polaris/cli/command/utils.py
index b863cc10b1..028c7f08d6 100644
--- a/client/python/apache_polaris/cli/command/utils.py
+++ b/client/python/apache_polaris/cli/command/utils.py
@@ -81,7 +81,9 @@ def get_catalog_api_client(api: PolarisDefaultApi) -> ApiClient:
         username=mgmt_config.username,
         password=mgmt_config.password,
         access_token=mgmt_config.access_token,
+        ssl_ca_cert=mgmt_config.ssl_ca_cert,
     )
+    configuration.verify_ssl = mgmt_config.verify_ssl
 
     if hasattr(mgmt_config, "proxy"):
         configuration.proxy = mgmt_config.proxy
diff --git a/client/python/apache_polaris/cli/constants.py b/client/python/apache_polaris/cli/constants.py
index 9111e799c6..07cee55579 100644
--- a/client/python/apache_polaris/cli/constants.py
+++ b/client/python/apache_polaris/cli/constants.py
@@ -205,6 +205,8 @@ class Arguments:
     REGION = "region"
     PROFILE = "profile"
     PROXY = "proxy"
+    SSL_CA_CERT = "ssl_ca_cert"
+    INSECURE = "insecure"
     DEBUG = "debug"
     HADOOP_WAREHOUSE = "hadoop_warehouse"
     HIVE_WAREHOUSE = "hive_warehouse"
diff --git a/client/python/apache_polaris/cli/options/parser.py b/client/python/apache_polaris/cli/options/parser.py
index 794e8b1bc8..b7961c1714 100644
--- a/client/python/apache_polaris/cli/options/parser.py
+++ b/client/python/apache_polaris/cli/options/parser.py
@@ -81,6 +81,16 @@ class Parser(object):
         ),
         Argument(Arguments.PROFILE, str, hint="Polaris profile name"),
         Argument(Arguments.PROXY, str, hint="Proxy URL"),
+        Argument(
+            Arguments.SSL_CA_CERT,
+            str,
+            hint="Path to a PEM file of CA certificates used to verify the server",
+        ),
+        Argument(
+            Arguments.INSECURE,
+            bool,
+            hint="Disable TLS certificate verification (not recommended)",
+        ),
         Argument(Arguments.DEBUG, bool, hint="Enable debug mode"),
         Argument(Arguments.PAGE_SIZE, int, hint=Hints.PAGE_SIZE),
     ]
diff --git a/client/python/tests/cli_test_utils.py b/client/python/tests/cli_test_utils.py
index a43d100756..a3379bc08b 100644
--- a/client/python/tests/cli_test_utils.py
+++ b/client/python/tests/cli_test_utils.py
@@ -38,6 +38,8 @@ class CLITestBase(unittest.TestCase):
         client.api_client.configuration.host = "http://localhost:8080/api/management"
         client.api_client.configuration.proxy = None
         client.api_client.configuration.proxy_headers = None
+        client.api_client.configuration.ssl_ca_cert = None
+        client.api_client.configuration.verify_ssl = True
         client.api_client.configuration.username = None
         client.api_client.configuration.password = None
         client.api_client.configuration.access_token = None
diff --git a/client/python/tests/test_api_client_builder.py b/client/python/tests/test_api_client_builder.py
index 0f31c21a04..79b8db1213 100644
--- a/client/python/tests/test_api_client_builder.py
+++ b/client/python/tests/test_api_client_builder.py
@@ -24,8 +24,10 @@ from argparse import Namespace
 from unittest.mock import MagicMock, patch
 
 from apache_polaris.cli.api_client_builder import ApiClientBuilder, BuilderConfig
+from apache_polaris.cli.command.utils import get_catalog_api_client
 from apache_polaris.cli.constants import DEFAULT_HEADER, HEADER_ENV
 from apache_polaris.cli.exceptions import CliError, CLI_ERROR_EXIT_CODE
+from apache_polaris.sdk.management import PolarisDefaultApi
 
 
 def _builder_options() -> Namespace:
@@ -36,6 +38,8 @@ def _builder_options() -> Namespace:
         port=None,
         scheme=None,
         proxy=None,
+        ssl_ca_cert=None,
+        insecure=False,
         access_token=None,
         client_id="test-id",
         client_secret="test-secret",
@@ -121,6 +125,8 @@ class TestBuilderConfigCatalogUrl(unittest.TestCase):
             port=None,
             scheme=None,
             proxy=None,
+            ssl_ca_cert=None,
+            insecure=False,
             access_token=None,
             client_id=None,
             client_secret=None,
@@ -188,6 +194,8 @@ class TestBuilderConfigBaseUrl(unittest.TestCase):
             port=port,
             scheme=scheme,
             proxy=None,
+            ssl_ca_cert=None,
+            insecure=False,
             access_token=None,
             client_id=None,
             client_secret=None,
@@ -276,5 +284,42 @@ class TestBuilderConfigHeader(unittest.TestCase):
                     self.assertEqual(BuilderConfig(opts).header, expected)
 
 
+class TestBuilderTls(unittest.TestCase):
+    def test_tls_options_applied_to_management_and_catalog_clients(self) -> None:
+        cases = [
+            (None, False, None, True),
+            ("/certs/ca.pem", False, "/certs/ca.pem", True),
+            (None, True, None, False),
+        ]
+        for ssl_ca_cert, insecure, expected_ca_cert, expected_verify in cases:
+            with self.subTest(ssl_ca_cert=ssl_ca_cert, insecure=insecure):
+                opts = _builder_options()
+                opts.client_id = None
+                opts.client_secret = None
+                opts.access_token = "token"
+                opts.ssl_ca_cert = ssl_ca_cert
+                opts.insecure = insecure
+                api_client = ApiClientBuilder(opts).get_api_client()
+                catalog_client = get_catalog_api_client(PolarisDefaultApi(api_client))
+                for config in (api_client.configuration, catalog_client.configuration):
+                    self.assertEqual(config.ssl_ca_cert, expected_ca_cert)
+                    self.assertEqual(config.verify_ssl, expected_verify)
+
+    def test_tls_options_applied_to_token_request(self) -> None:
+        opts = _builder_options()
+        opts.ssl_ca_cert = "/certs/ca.pem"
+        opts.insecure = True
+        with patch(
+            "apache_polaris.cli.api_client_builder.ApiClient"
+        ) as mock_api_client:
+            mock_api_client.return_value.call_api.return_value.response.data = (
+                json.dumps({"access_token": "abc123"})
+            )
+            ApiClientBuilder(opts)._get_token()
+        config = mock_api_client.call_args.args[0]
+        self.assertEqual(config.ssl_ca_cert, "/certs/ca.pem")
+        self.assertFalse(config.verify_ssl)
+
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/site/content/in-dev/unreleased/command-line-interface.md b/site/content/in-dev/unreleased/command-line-interface.md
index 943a33bd28..bd267b0093 100644
--- a/site/content/in-dev/unreleased/command-line-interface.md
+++ b/site/content/in-dev/unreleased/command-line-interface.md
@@ -55,6 +55,8 @@ Global Options:
   --header HEADER                Context header name (default: Polaris-Realm)
   --profile PROFILE              Polaris profile name
   --proxy PROXY                  Proxy URL
+  --ssl-ca-cert SSL_CA_CERT      Path to a PEM file of CA certificates used to verify the server
+  --insecure                     Disable TLS certificate verification (not recommended)
   --debug                        Enable debug mode
   --page-size PAGE_SIZE          Upper bound on the number of entries returned per API request where pagination is supported. Requires the server-side LIST_PAGINATION_ENABLED feature flag. If not set, fetches all results in a single API request.
 ```