HyukjinKwon opened a new pull request, #373:
URL: https://github.com/apache/spark-connect-rust/pull/373

   ### What changes were proposed in this pull request?
   
   [SPARK-61182](https://issues.apache.org/jira/browse/SPARK-61182): PySpark 
connects over TLS when `use_ssl` is set or a token is present, a token on 
`localhost` stays on local channel credentials, and a session ID is any UUID. 
The user ID is the connection string's `user_id`, else `SPARK_USER`, else 
`USER`.
   
   - `ChannelBuilder::secure()` is the scheme predicate, and 
`SparkConnectClient::connect` dials TLS when it holds. It is true for 
`use_ssl=true`, and for a token on a host that is not loopback. A token on 
`localhost`, `127.0.0.1` or `[::1]` stays plaintext, as before. The refusal 
"Refusing to send the authentication token ... over an insecure connection" is 
removed, since the token now always goes over TLS unless the host is loopback.
   - `ChannelBuilder::session_id()` accepts any UUID that parses, and returns 
the string as given. Malformed strings still raise `INVALID_SESSION_UUID_ID`.
   - `SparkConnectClient::connect` takes the user ID from `SPARK_USER`, else 
`USER`, when the connection string sets no `user_id`. An empty value is no user 
ID. The user ID is then set in the user context of each request, as before for 
an explicit `user_id`.
   - `docs/configuration.md` says that a token implies TLS, and that a token is 
sent without TLS only to `localhost`, `127.0.0.1` and `[::1]`.
   
   ### Why are the changes needed?
   
   - A token for a host other than localhost, without `use_ssl=true`, failed to 
connect. A call such as `sc://example.com:443/;token=T`, or a token from 
`SPARK_CONNECT_AUTHENTICATE_TOKEN`, returned the refusal. PySpark connects over 
TLS for it. `DefaultChannelBuilder(...).secure` in PySpark 4.3.0 returns `True` 
for `sc://example.com/;token=T`, and for `sc://localhost/;token=T`.
   - A UUID of version 1, such as 
`sc://localhost/;session_id=6ba7b810-9dad-11d1-80b4-00c04fd430c8`, raised 
`INVALID_SESSION_UUID_ID`, since the check required version 4. PySpark accepts 
it: `DefaultChannelBuilder(...).session_id` returns the string.
   - Without `user_id` in the connection string, the user context of every 
request had an empty `user_id`. PySpark sends the OS user. With 
`SPARK_USER=hook-user`, `SparkConnectClient(...)._user_id` is `'hook-user'` in 
PySpark 4.3.0, and with only `USER=hook-os-user` it is `'hook-os-user'`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes.
   
   - A token for a host other than localhost is sent over TLS, and no longer 
refused without `use_ssl=true`.
   - A session ID of any UUID version is accepted, and sent as given.
   - Requests carry the user ID from `SPARK_USER`, else `USER`, when the 
connection string has no `user_id`. The same user ID is also sent as the 
`user_id` gRPC header, which the client already sent for an explicit `user_id`.
   - Known difference from PySpark: a token on `127.0.0.1` or `[::1]` stays 
plaintext, where PySpark uses TLS for those hosts. This is the existing 
loopback leniency, unchanged.
   
   ### How was this patch tested?
   
   - Rust unit tests in `crates/spark-connect-core/src/channel.rs`: 
`scheme_is_tls_for_a_token_on_a_remote_host`, 
`scheme_uses_the_token_of_the_environment`, 
`session_id_accepts_a_uuid_of_any_version_as_given`, 
`session_id_rejects_a_malformed_uuid`.
   - Rust unit tests in `crates/spark-connect-core/src/client.rs`: 
`test_token_without_ssl_to_remote_host_is_sent_over_tls` (replaces the refusal 
test), `test_token_of_the_environment_to_remote_host_is_sent_over_tls`, 
`test_user_id_from_the_environment_as_pyspark`, 
`test_user_id_of_the_connection_then_the_environment`.
   - `crates/spark-connect-core/tests/user_context.rs`: 
`typed_requests_keep_their_user_context_with_an_empty_user_id` now uses 
`user_id=` in the connection string, since the default would otherwise read the 
`USER` of the machine.
   - `test_cached_arrow_upload_attribution_on_every_frame` and 
`test_file_upload_attribution_on_every_frame` in 
`python/tests/test_arrow_handoff.py` set `SPARK_USER` for a connection string 
without `user_id`, and expect it as the user ID of every frame, where they 
expected an empty one.
   - Environment-variable tests take a shared lock (`channel::set_env`), so 
they do not race other tests.
   - Python offline test 
`test_session_id_of_any_uuid_version_and_the_user_id_of_the_requests` in 
`python/tests/test_dropin_offline.py`: a version 1 session ID is kept as given, 
and the `ExecutePlanRequest` seen by the mock server has that session ID and 
the user ID from `SPARK_USER`, then from `USER`.
   - The same cases checked against official PySpark 4.3.0 with 
`DefaultChannelBuilder` and `SparkConnectClient`: the session ID is accepted, 
`secure` is as above, and the user ID is `SPARK_USER`, else `USER`.
   - The Python test fails without this change, with `INVALID_SESSION_UUID_ID`.
   - The lib tests of both crates (604 passed), the build of all tests, also 
with `wasm-udf`, the offline Python suites (2228 passed, 8 skipped), and the 
live drop-in and Arrow suites (209 passed) and live cases (10 passed) against a 
local Spark 4.3.0 server. Clippy reports no diagnostics in the changed lines.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to