Skip to content

[Data] Validate read_hive TLS with HiveServer2 - #67273

Open
jiangxt2 wants to merge 24 commits into
ray-project:masterfrom
jiangxt2:feature/read-hive-auth-tls-validation
Open

jiangxt2 wants to merge 24 commits into
ray-project:masterfrom
jiangxt2:feature/read-hive-auth-tls-validation

Conversation

@jiangxt2

@jiangxt2 jiangxt2 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add real-service validation for read_hive() verified TLS through the existing connection_factory API. Extend the HiveServer2 integration fixture to exercise connections on the driver and a separate Ray worker process.

Before: Documented real-server coverage was limited to Impyla PLAIN with HiveServer2 in NONE mode, which does not validate passwords.

After: The existing Hive premerge job is configured to run table and query reads over verified TLS and check untrusted CAs and hostname mismatches at the connection boundary. Production reading behavior and the public API remain unchanged.

Subsystems: IO (Hive datasource tests), API (docstring only), plus supporting test infrastructure, CI, and documentation.

Related issues

Part of #67072

The existing #67144 Hive premerge job is configured to run PLAIN/NONE over TLS. GSSAPI and NOSASL remain in the scope of #67072.

Additional information

Coverage and execution

  • Use Hive 4.2.0 with Impyla PLAIN and server mode NONE; verified TLS is configured by the caller's connection factory.
  • Exercise verified table and query reads, including schema, scalar types, and timestamps. The existing connection test checks a trusted CA, an untrusted CA, and a hostname mismatch.
  • These checks target regressions where verified TLS reads fail, an untrusted certificate is accepted, or a mismatched hostname is accepted.
  • The driver and worker run on one Ray node and share its filesystem. The negative cases operate at the connection boundary; they do not separately test failed read_hive calls or assert zero data RPCs after a TLS failure.
  • Runner tests check that TLS settings and the public CA are passed to the Bazel invocation and that a missing CA prevents the test command from starting.

Validation

Local checks on the consolidated Hive fixture:

  • Real Hive verified TLS integration module — 4 passed, using a local pytest adapter for the Bazel invocation.
  • Runner tests — 16 passed using Docker/Bazel stubs.
  • Buildkite Hive TLS job: bash ci/ray_ci/data/run_hive_integration.sh --tls — the //python/ray/data:test_hive_integration target passed.

The local Hive run invoked run_hive_integration.sh --tls in a Linux
container. A local adapter replaced its Bazel invocation and ran the Hive
test module with the checkout's Data sources and a Ray wheel Core.

Runner test command:

PYTHONDONTWRITEBYTECODE=1 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 \
  "$PYTHON" -m pytest -v --noconftest -p no:cacheprovider -c /dev/null \
  --basetemp="$TEMP_DIR" ci/ray_ci/data/test_run_hive_integration.py \
  --junitxml="$RESULTS_DIR/runner-results.xml"

Pre-commit and Pyrefly checks passed using a local Python 3.10/Arrow 17 Pyrefly configuration.

In a prepared RayCI environment, run the Hive suite with:

bash ci/ray_ci/data/run_hive_integration.sh --tls

Validation environment and scope

The real-service run used Linux ARM64, Python 3.10.19, PyArrow 25.0.1, Hive 4.2.0, Impyla 0.23.0, checkout Data and test sources, and an official Ray wheel Core. The runner tests used macOS and Python 3.10.18.

See ci/ray_ci/data/README.md for the manual runner's required environment.

AI assistance

Codex assisted with implementation, testing, documentation, and review.

Add real HiveServer2 coverage for GSSAPI, verified TLS, their
combination, and NOSASL with separate Ray driver and worker nodes.

Reuse Hive test helpers, add isolated security fixtures and bounded
orchestration, register executable pytest targets, and document
credential requirements. Add a dedicated CI job and dependency lock.

Local validation passed: 26 service cases, 66 helper/orchestration
tests, 18 no-replay/lifecycle tests, and pytest_format. Upstream
Python 3.10 CI with a Core build from the checkout has not run.

Signed-off-by: jiangxt2 <[email protected]>
Translate pytest status 1 to RayCI status 42 inside the driver container after pytest returns, and retain the original status as an event artifact. Preserve Docker exec errors before pytest starts and let RayCI manage job retries without a separate approval gate.

Remove the unused killed-producer evidence path and the Docker COPY shadowed by Compose mounts. Add runner and real pytest subprocess coverage, and document the exit-code artifact.

Validation: 37 orchestration and 24 helper cases passed; a real Compose exec probe returned 1 before pytest started. Upstream CI validation for these changes is pending.

Signed-off-by: jiangxt2 <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive integration tests for Hive authentication and TLS in Ray Data, covering GSSAPI, verified TLS, and NOSASL profiles. It adds a dedicated Docker Compose-based test runner, updates Buildkite CI configurations, refactors existing Hive tests to share utilities, and updates the documentation. The feedback highlights a fragile date parsing logic in the Kerberos ticket preparation script that could fail depending on the Kerberos client version's year format, recommending a more robust parsing strategy.

Comment thread ci/ray_ci/data/hive_auth/prepare.py Outdated
Comment on lines +328 to +334
matches = re.findall(r"\d\d/\d\d/\d\d \d\d:\d\d:\d\d", listing)
ends = [
datetime.strptime(v, "%m/%d/%y %H:%M:%S")
.replace(tzinfo=timezone.utc)
.timestamp()
for v in matches[1::2]
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The regular expression and date parsing format for klist output are fragile because different versions of MIT Kerberos or Heimdal (and different OS environments) can output either 2-digit (YY) or 4-digit (YYYY) years. Using a fixed 2-digit year pattern (\d\d/\d\d/\d\d and %m/%d/%y) can cause unexpected test failures when run in environments with newer Kerberos clients. We should support both 2-digit and 4-digit years.

    matches = re.findall(r"\d\d/\d\d/\d{2,4} \d\d:\d\d:\d\d", listing)
    ends = []
    for v in matches[1::2]:
        year_part = v.split()[0].split("/")[-1]
        fmt = "%m/%d/%Y %H:%M:%S" if len(year_part) == 4 else "%m/%d/%y %H:%M:%S"
        ends.append(datetime.strptime(v, fmt).replace(tzinfo=timezone.utc).timestamp())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expired-ticket validation has been deferred, and its klist parsing and short-lived-ticket fixture have been removed. This date-format assumption is no longer present.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread ci/ray_ci/data/hive_auth/hive-entry.sh Resolved
@ray-gardener ray-gardener Bot added docs An issue or change related to documentation data Ray Data-related issues community-contribution Contributed by the community labels Nov 2, 2026
Use native CI image builds and completed connection summaries while preserving all 26 security integration cases. Restore the existing Hive integration tests and retain exit-code and scoped cleanup checks.

Signed-off-by: jiangxt2 <[email protected]>
Keep the dedicated runtime image as root so the downstream CI environment can create /rayci and update copied sources when installing checkout Core.

Signed-off-by: jiangxt2 <[email protected]>
@jiangxt2
jiangxt2 marked this pull request as draft November 2, 2026 17:12
Keep 19 real-service cases for GSSAPI, verified TLS, combined GSSAPI/TLS,
and NOSASL with independent driver/worker and complete RPC evidence.
Remove automatic security CI, expired-ticket probes, and repeated
worker-table failure cases.

Use a standalone Python 3.12 dependency lock and return raw
Docker/pytest statuses from the manual runner.

Signed-off-by: jiangxt2 <[email protected]>
@jiangxt2
jiangxt2 marked this pull request as ready for review November 3, 2026 01:43
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Rely on exact case counts, JSON parsing, and completed connection summaries
for the existing security validation. Drop internal UUID and preliminary
write-access checks.

Keep malformed JSON rejection and verify aggregation of completed
summaries without a trailing newline.

Signed-off-by: jiangxt2 <[email protected]>
Merge upstream master at 891a5a8 and pin the matching Ray runtime for the Hive security fixture. Disable Ray token authentication within the isolated Compose cluster.

Signed-off-by: jiangxt2 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread ci/ray_ci/data/hive_auth/run.py Resolved
Resolve the log directory against the caller working directory before invoking Compose. Cover relative and absolute destinations in the runner tests.

Signed-off-by: jiangxt2 <[email protected]>
Use Python 3.11 for the shuffle_batches benchmark to match its inherited torch-cu128 image and release configuration validation.

Signed-off-by: jiangxt2 <[email protected]>
Merge upstream master at a83e55e, including the independent shuffle benchmark configuration fix.

Signed-off-by: jiangxt2 <[email protected]>
Merge master at 74b21dc and reuse the Hive integration fixture for focused TLS validation.

Signed-off-by: jiangxt2 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 8b2096c. Configure here.

@jiangxt2 jiangxt2 changed the title [Data] Validate read_hive authentication and TLS [Data] Validate read_hive TLS with HiveServer2 Nov 14, 2026
@abhishekverma-ray

Copy link
Copy Markdown
Contributor

Thanks for these! The team is aligning on some Ray Data test conventions (#67919 / #67928). In short: each test should fail if the change is reverted, extend or parametrize existing tests before adding new ones, test through the public read_* APIs rather than asserting on internal mock calls, and use ray_start_regular_shared instead of starting new clusters. This PR has about 2.6× more test lines than code. Could you trim it to the tests that catch a revert, and note in the description which revert each one catches?

@jiangxt2
jiangxt2 requested a review from a team as a code owner November 20, 2026 14:32

@abhishekverma-ray abhishekverma-ray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you link one real Buildkite run of run_hive_integration.sh --tls? So far the runner path has only been tested with stubs. Please also list the exact test commands, and say which regression each new test would catch.

not os.environ.get("RAY_HIVE_CA_PEM_B64"),
reason="Set RAY_HIVE_CA_PEM_B64 to run the Hive TLS integration suite",
)
class TestHiveTLS:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging into TLS! A design question before the details. This class only runs when someone starts run_hive_integration.sh --tls by hand. No CI step calls it, and it needs ECR access, so outside contributors can't run it either. Meanwhile test_hive_auth_utils.py runs in every Data premerge step, but it only tests the test helper.

Also, master already has test_hive_tls_rejects_untrusted_or_mismatched_server (line 275), which makes the same checks (right CA works, untrusted CA fails, wrong host fails). It still never runs, in either mode.

Could we instead run the existing Hive premerge job against your TLS server, with RAY_HIVE_TEST_USE_SSL=true and RAY_HIVE_TEST_CA_CERT set to the decoded CA? Then every existing read test runs over verified TLS, the existing negative test finally runs, and we can drop _hive_test_utils.py, test_hive_auth_utils.py, _EnsureCases and this class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing Hive premerge job is now configured to run against the TLS-enabled server. The existing read and certificate checks are reused, and the dedicated test class and helpers have been removed.

return None


def _hostname_mismatch(error):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks for an ssl.match_hostname frame, but ssl.match_hostname was removed in Python 3.12. On 3.12, thrift 0.16 falls back to a check that raises a plain TTransportException. I ran this helper against a local TLS server on 3.12. The client correctly rejected the host, but the helper recorded certificate_error=False, hostname_mismatch=False, so test_hostname_worker would fail there. The unit test at test_hive_auth_utils.py:79 monkeypatches ssl.match_hostname, which thrift no longer reads after import, so it passes anyway. Could we assert on the visible result instead (the read fails, and the same read with the right CA passes)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the hostname helper and reused the existing connection checks. They verify that the trusted connection succeeds and that an untrusted CA or mismatched hostname is rejected.

Configure authentication, transport, TLS certificate verification, and client retries in the factory. Choose `auth_mechanism` explicitly when calling `impala.dbapi.connect()`. Use `NOSASL` only with a HiveServer2 configured for `NOSASL`. Hive server mode `NONE` uses `PLAIN`, a Simple Authentication and Security Layer (SASL) mechanism. Use a non-sensitive placeholder password because that server mode doesn't check it. `PLAIN` doesn't encrypt the password without TLS. For TLS connections, set `verify_cert=True` or provide a trusted `ca_cert`. For `GSSAPI`, install `impyla[kerberos]`, set `kerberos_service_name="hive"`, and configure authentication credentials on the driver and read worker.

The real-server integration test verifies the `PLAIN` mechanism with HiveServer2 in server mode `NONE`. It doesn't cover `NOSASL` or `GSSAPI`.
Configure authentication, transport, TLS certificate verification, and client retries in the factory. Choose `auth_mechanism` explicitly when calling `impala.dbapi.connect()`. Use `NOSASL` only with a HiveServer2 configured for `NOSASL`. Hive server mode `NONE` uses `PLAIN`, a Simple Authentication and Security Layer (SASL) mechanism. Use a non-sensitive placeholder password because that server mode doesn't check it. `PLAIN` doesn't encrypt the password without TLS. For TLS, set `use_ssl=True` and provide a trusted certificate authority (CA) file with `ca_cert`. The host name must match the server certificate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for removing the verify_cert=True advice; I confirmed it gives an empty trust store on binary transport. One more sentence would help users a lot. With use_ssl=True and no ca_cert, impyla doesn't check the certificate at all, on both binary and HTTP transport (I tested this with a server signed by a private CA). The PLAIN password then goes to whatever server answers. Could you add that warning, plus a small factory example with use_ssl=True, ca_cert="/path/ca.pem"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the warning for Impyla 0.23.0 without a ca_cert and with the default verify_cert=False, along with a factory example that passes a trusted ca_cert.

(read-hive-auth-tls)=
#### Configure TLS certificate verification

Configure TLS inside `connection_factory` and make any CA file available wherever the factory runs. For GSSAPI, install `impyla[kerberos]`, set `kerberos_service_name` to the service component of the server principal (for example, `"hive"` for `hive/host@REALM`), and provide credentials wherever the factory runs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a short troubleshooting note here?

  • With an untrusted CA, the error is only Could not connect to any of [...], the same as a wrong port. The real certificate error is logged at INFO on thrift.transport.TSocket.
  • A missing CA file shows No such file or directory with no path. The CA must be at the same path on every node.
  • impyla has no timeout by default, so a port that never replies hangs the read task. Consider timeout=.
  • On Python 3.12+, thrift 0.16 checks the hostname only against the certificate's CN, not its SANs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note that an error for a missing CA file may omit the path.

Comment thread python/ray/data/read_api.py Outdated
The real-server integration test covers ``PLAIN`` with HiveServer2 in
server mode ``NONE``. It doesn't cover ``NOSASL`` or ``GSSAPI``.
Real-server TLS validation of HS2 mode uses ``PLAIN`` with HiveServer2 in
server mode ``NONE``. GSSAPI and NOSASL aren't covered by this TLS suite.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small one: "this TLS suite" points at test infrastructure users can't see. Could this say what to do instead, for example "pass ca_cert; it must exist on every node"? Keep the :ref: link.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the docstring to tell users to pass a trusted CA in the factory and make it available wherever the factory runs. The documentation link is retained.

@abhishekverma-ray abhishekverma-ray added the go add ONLY when ready to merge, run all tests label Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

The Buildkite Hive TLS job passed with bash ci/ray_ci/data/run_hive_integration.sh --tls. The PR description also lists the local runner test command and explains the regressions covered by the TLS and runner checks.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues docs An issue or change related to documentation go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants