HyukjinKwon opened a new pull request, #918:
URL: https://github.com/apache/spark-connect-rust/pull/918
### What changes were proposed in this pull request?
A follow-up of the known-differences audit against pyspark-client 4.3.0
(finding 7).
PySpark's `SparkConnectClient` connects through its builder's `toChannel`
(`pyspark/sql/connect/client/core.py:615-644`, of `secure` at 596-598).
- The channel of a `DefaultChannelBuilder` connects to its `endpoint`, which
is `f"{self._host}:{self._port}"`.
- It is of no security, and sends no token, unless the builder is `secure`
(`use_ssl` is true or a token is set).
- Else it takes gRPC's local credentials, plaintext with the token, when
`use_ssl` is false and `_host` is `localhost`. Their handshake takes a
connection whose local address is `127.0.0.1` or `::1` only, and fails the call
with `Endpoint is neither UDS or TCP loopback address.` otherwise.
- Else it is TLS with the token.
Each of these reads the builder's properties, so a subclass's own
`endpoint`, `_host`, `_port`, `secure`, `use_ssl` and `token` decide them.
The drop-in's transport instead connected to the builder's `host` and
`port`, read `use_ssl` from its parameters only, and was TLS of `use_ssl` or of
a token on a host that is not `localhost`. This made these kinds of difference:
- A subclass that overrides `host` changed the drop-in's address but not
PySpark's, which shows `host` only, through `client.host`.
- A subclass that overrides `endpoint` changed PySpark's address but not the
drop-in's.
- A subclass that overrides `port`, a property PySpark's builder does not
have, changed the drop-in's address, while PySpark ignores it.
- A subclass's own `secure` was not read: `secure -> False` with a token
still sent the token, over TLS to `127.0.0.1`; `secure -> True` without a token
was plaintext to `127.0.0.1`.
- Local credentials were decided on the endpoint's host, not on `_host`: a
token with `_host` `localhost` and an endpoint of `127.0.0.1` was TLS, and one
with `_host` `127.0.0.1` and an endpoint of `localhost` was plaintext.
Also, a subclass's own `default_port` gave the port of a URL with no port in
the drop-in. PySpark's `_extract_attributes` calls
`DefaultChannelBuilder.default_port()` instead.
So:
- **`url_of_channel_builder` (`crates/pyspark-rs/src/session.rs`) connects a
`DefaultChannelBuilder`, and any subclass of it, to its `endpoint`.** It no
longer reads `host` and `port` for it. The endpoint is read as gRPC reads a
target (`endpoint_of_target`):
- bytes are taken as they are, and any other object goes through
`encode("utf8")`, as grpc's `_common.encode` does. So an int raises grpc's
`AttributeError: 'int' object has no attribute 'encode'`;
- for a URI of `dns:[//authority/]`, the address is taken; for `ipv4:` and
`ipv6:`, the first address. The scheme can be of any case;
- `unix:` raises `NOT_IMPLEMENTED`, since the transport connects over TCP;
- anything else is a `host[:port]`. Without a port it gets gRPC's default
port, 443, also for an IPv6 address without brackets.
- **It decides the credentials of the channel as `toChannel` does**, of the
builder's `secure`, `use_ssl`, `_host` and `token`, a subclass's own too, in
`toChannel`'s order (of the token twice, as `toChannel` checks it and then
gives it to grpcio), so an error of a subclass's `secure` is raised when the
session is made. It gives them to the session apart from the URL, through
`SparkSessionBuilder::channel_credentials` and
`ChannelBuilder::with_credentials` (of `channel::Credentials`; not a stable
API), which no connection string sets:
- `Insecure`: plaintext, and no token, also of
`SPARK_CONNECT_AUTHENTICATE_TOKEN`;
- `Local`: plaintext with the token;
- `Ssl`: TLS with the token.
- **An endpoint that is not of a host and a port is refused when the session
is made.** Of a `/`, `?`, `#`, `;`, `@` or whitespace, which would be a part of
the URL and not of its authority, it raises `INVALID_CONNECT_URL`. A key of the
parameters of a character other than `[0-9a-z_.-]`, which a gRPC metadata key
does not take, such as `;` or `=`, raises the transport's own `ValueError` of
the key as it is (`metadata was invalid: 'a=b;use_ssl' is not a gRPC metadata
key, which is of the characters [0-9a-z_.-]`), the text that master raises of
such a key of a connection string, so that it never becomes a part of the URL.
- **The connector (`crates/spark-connect-core/src/connector.rs`) checks the
connections of local credentials as gRPC's handshake does.** It reads the local
address of the TCP connection (that to the proxy of a tunnel too), not the
address it connects to, so a connection to `0.0.0.0` or `127.0.0.2` is of the
loopback. Another fails with gRPC's text (`Failure::NotLoopback`). A target of
local credentials shares its connections with targets of local credentials only.
- **`DefaultChannelBuilder._extract_attributes` (`client/core.py`) takes the
port of a URL with no port from `DefaultChannelBuilder.default_port()`**, as
PySpark's does. The docstring of `_checked_channel_builder` is updated to match.
- **A plain `ChannelBuilder`** is unchanged. PySpark connects through its
`toChannel`; the drop-in still connects to its `host` and `port`, of its token.
A connection string never sets the credentials: one of a parameter of any
name is as before, so `sc://` URLs (`remote()`, `SPARK_REMOTE`,
`SparkSession(connection=str)`) and the Rust API keep their rule of
`ChannelBuilder::secure`, and a parameter named as the old reserved one is a
metadata key of capitals, which fails the session when it is made, as master
did and as gRPC refuses it. `docs/compatibility.md` notes the doc-hidden API in
the Rust migration notes of the 4.4 line, and `docs/configuration.md` states
the case of a `_host` of `localhost` and an endpoint of `127.0.0.1`.
`dev/parity/known-differences.md` rewrites the rows "Custom gRPC channels"
and "A channel builder without a host" to say exactly what remains (SPARK-62220
makes all of it PySpark's):
- A builder's own `toChannel` channel, which the transport cannot dial
through.
- The reads of the builder: `userId` three times, or four when it is set,
where PySpark's client reads it once, or twice; and a subclass's keepalive
properties and `metadata()` are not read, as the keepalive and the metadata are
of the parameters.
- The forms of a gRPC target that the transport does not take:
- of `dns:`, the transport resolves the address itself, where gRPC's
resolver asks the DNS server of the authority and fails the first call of an
authority that is not an IP address and a port (`Cannot parse authority`);
- of `ipv4:` and `ipv6:`, the first entry only, of 443 without a port,
where gRPC tries each address in turn and fails the first call of an invalid
entry or of none;
- of `unix:` and `unix-abstract:`, `NOT_IMPLEMENTED`;
- of a `/`, `?`, `#`, `;`, `@` or whitespace, `INVALID_CONNECT_URL` when
the session is made, where gRPC drops a fragment and a query that is not empty
and connects (`127.0.0.1:15002#`, `127.0.0.1:15002?x=1`,
`dns:///127.0.0.1:15002?x=1`, `localhost: 15002`), and fails the first call of
the others;
- of a port that is not a number of 0 to 65535, the transport's
`ValueError`, where gRPC takes a sign, wraps one out of the range
(`localhost:99999` is 34463) and fails the first call of another, and of an
empty port 15002, where gRPC's is 443;
- percent-encoded bytes, which gRPC decodes (`loc%61lhost:15002`, and the
zone of `[fe80::1%25eth0]:15002` of `sc://[fe80::1%25eth0]:15002`), where the
transport does not.
Checked on both clients against a Spark 4.3.0 server. Each line is the
outcome of `range(2).count()` and then of `client.host`:
| builder | pyspark-client 4.3.0 | drop-in before | drop-in now |
|---|---|---|---|
| DefaultChannelBuilder | connects / host 'localhost' | connects / host
'localhost' | connects / host 'localhost' |
| host -> dead, URL live | connects / host 'nohost.invalid' | unreachable
(nohost.invalid) / host 'nohost.invalid' | connects / host 'nohost.invalid' |
| host -> live, URL dead | unreachable (nohost.invalid) / host 'localhost' |
connects / host 'localhost' | unreachable (nohost.invalid) / host 'localhost' |
| endpoint -> live, URL dead | connects / host 'nohost.invalid' |
unreachable (nohost.invalid) / host 'nohost.invalid' | connects / host
'nohost.invalid' |
| endpoint -> dead, URL live | unreachable (nohost.invalid) / host
'localhost' | connects / host 'localhost' | unreachable (nohost.invalid) / host
'localhost' |
| port -> 1, URL live | connects / host 'localhost' | unreachable / host
'localhost' | connects / host 'localhost' |
| _host = localhost, URL dead | connects / host 'localhost' | connects /
host 'localhost' | connects / host 'localhost' |
| _host = dead, URL live | unreachable (nohost.invalid) / host
'nohost.invalid' | unreachable (nohost.invalid) / host 'nohost.invalid' |
unreachable (nohost.invalid) / host 'nohost.invalid' |
| _port = PORT, URL :1 | connects / host 'localhost' | connects / host
'localhost' | connects / host 'localhost' |
| _port = 1, URL live | unreachable / host 'localhost' | unreachable / host
'localhost' | unreachable / host 'localhost' |
| default_port -> PORT, URL of no port | unreachable / host 'localhost' |
connects / host 'localhost' | unreachable / host 'localhost' |
| DefaultChannelBuilder subclass of its own toChannel, URL dead | connects /
host 'nohost.invalid' | unreachable (nohost.invalid) / host 'nohost.invalid' |
unreachable (nohost.invalid) / host 'nohost.invalid' |
| use_ssl -> True, URL live (plaintext server) | unreachable / host
'localhost' | connects / host 'localhost' | unreachable / host 'localhost' |
| ChannelBuilder subclass of a host and toChannel | connects / host
'localhost' | unreachable / host 'localhost' | unreachable / host 'localhost' |
| ChannelBuilder subclass of a host, an endpoint and toChannel | connects /
host 'localhost' | connects / host 'localhost' | connects / host 'localhost' |
| endpoint -> 'localhost' (no port) | unreachable / host 'localhost' |
connects / host 'localhost' | unreachable / host 'localhost' |
| endpoint -> 127.0.0.1:PORT, URL dead | connects / host 'nohost.invalid' |
unreachable (nohost.invalid) / host 'nohost.invalid' | connects / host
'nohost.invalid' |
| endpoint -> 5 | creation raises AttributeError: 'int' object has no
attribute 'encode' | connects / host 'localhost' | creation raises
AttributeError: 'int' object has no attribute 'encode' |
| endpoint raises KeyError | creation raises KeyError: 'endpoint' | connects
/ host 'localhost' | creation raises KeyError: 'endpoint' |
| host raises KeyError | connects; host raises KeyError: 'host' | creation
raises KeyError: 'host' | connects; host raises KeyError: 'host' |
| endpoint -> bytes, URL dead | connects / host 'nohost.invalid' |
unreachable (nohost.invalid) / host 'nohost.invalid' | connects / host
'nohost.invalid' |
| endpoint -> [::1]:PORT, URL dead | connects / host 'nohost.invalid' |
unreachable (nohost.invalid) / host 'nohost.invalid' | connects / host
'nohost.invalid' |
| endpoint -> ::1 (no port) | unreachable / host 'localhost' | connects /
host 'localhost' | unreachable / host 'localhost' |
| URL of [::1]:PORT | connects / host '[::1]' | connects / host '[::1]' |
connects / host '[::1]' |
| endpoint -> dns:///localhost:PORT, URL dead | connects / host
'nohost.invalid' | unreachable (nohost.invalid) / host 'nohost.invalid' |
connects / host 'nohost.invalid' |
| use_ssl -> False of a URL of use_ssl=true (plaintext server) | connects /
host 'localhost' | unreachable / host 'localhost' | connects / host 'localhost'
|
| use_ssl raises KeyError | creation raises KeyError: 'use_ssl' | connects /
host 'localhost' | creation raises KeyError: 'use_ssl' |
| SparkSession(connection=builder) of an endpoint override | connects / host
'nohost.invalid' | unreachable (nohost.invalid) / host 'nohost.invalid' |
connects / host 'nohost.invalid' |
"dead" is `nohost.invalid` and "live" the server. The two rows of a
`toChannel` of their own differ: PySpark connects through their channel, which
the transport cannot use. The KD row "Custom gRPC channels" says so. Of 28
cases, the two clients differed in 21 before this PR and in those 2 after it.
The target forms of an `endpoint`, with the URL `sc://nohost.invalid:1`:
| case | pyspark-client 4.3.0 | drop-in before (master) | drop-in now |
|---|---|---|---|
| 'localhost:17839' | count=2 | fails: details = "errors resolving
nohost.invalid:1: [field:hostname lookup error:address looku | count=2 |
| 'dns:///localhost:17839' | count=2 | fails: details = "errors resolving
nohost.invalid:1: [field:hostname lookup error:address looku | count=2 |
| 'dns:localhost:17839' | count=2 | fails: details = "errors resolving
nohost.invalid:1: [field:hostname lookup error:address looku | count=2 |
| 'dns://8.8.8.8/localhost:17839' | fails: details = "Illegal status code
from resolver; original status: INVALID_ARGUMENT: Cannot | fails: details =
"errors resolving nohost.invalid:1: [field:hostname lookup error:address looku
| count=2 |
| 'dns://127.0.0.1:53/localhost:17839' | count=2 | fails: details = "errors
resolving nohost.invalid:1: [field:hostname lookup error:address looku |
count=2 |
| 'ipv4:127.0.0.1:17839' | count=2 | fails: details = "errors resolving
nohost.invalid:1: [field:hostname lookup error:address looku | count=2 |
| 'ipv4:127.0.0.1:17839,127.0.0.1:1' | count=2 | fails: details = "errors
resolving nohost.invalid:1: [field:hostname lookup error:address looku |
count=2 |
| 'ipv4:127.0.0.1:1,127.0.0.1:17839' | count=2 | fails: details = "errors
resolving nohost.invalid:1: [field:hostname lookup error:address looku | fails:
details = "failed to connect to all addresses; last error: UNKNOWN:
ipv4:127.0.0.1:1: Fa |
| 'ipv6:[::1]:17839' | count=2 | fails: details = "errors resolving
nohost.invalid:1: [field:hostname lookup error:address looku | count=2 |
| 'ipv4:127.0.0.1' | fails: details = "Failed to create channel to
'ipv4:127.0.0.1':the target uri is not valid: ipv | fails: details = "errors
resolving nohost.invalid:1: [field:hostname lookup error:address looku | fails:
details = "failed to connect to all addresses; last error: UNKNOWN:
ipv4:127.0.0.1:443: |
| 'unix:/tmp/nonexistent.sock' | fails: details = "failed to connect to all
addresses; last error: FAILED_PRECONDITION: unix:/tm | fails: details = "errors
resolving nohost.invalid:1: [field:hostname lookup error:address looku | raises
when made: PySparkNotImplementedError: [NOT_IMPLEMENTED] An endpoint of the
gRPC scheme |
| 'vsock:1:17839' | fails: details = "errors resolving vsock:1:17839:
[field:hostname lookup error:address lookup f | fails: details = "errors
resolving nohost.invalid:1: [field:hostname lookup error:address looku | raises
when made: ValueError: Port could not be cast to integer value as '1:17839' |
| 'LOCALHOST:17839' | count=2 | fails: details = "errors resolving
nohost.invalid:1: [field:hostname lookup error:address looku | count=2 |
| 'DNS:///localhost:17839' | count=2 | fails: details = "errors resolving
nohost.invalid:1: [field:hostname lookup error:address looku | count=2 |
| 'http://localhost:17839' | fails: details = "errors resolving
http://localhost:17839: [field:hostname lookup error:address | fails: details =
"errors resolving nohost.invalid:1: [field:hostname lookup error:address looku
| raises when made: PySparkValueError: [INVALID_CONNECT_URL] Invalid URL for
Spark Connect: The e |
| 'localhost:17839/x' | fails: details = "errors resolving
localhost:17839/x: [field:hostname lookup error:Failed to pa | fails: details =
"errors resolving nohost.invalid:1: [field:hostname lookup error:address looku
| raises when made: PySparkValueError: [INVALID_CONNECT_URL] Invalid URL for
Spark Connect: The e |
9 of 16 cases match PySpark now; 0 with drop-in before (master)
The forms that still differ are documented in the KD row: the transport
takes the first address of `ipv4:` and `ipv6:`, and the default port of one
without a port, where gRPC tries each address in turn and refuses an address
without a port at the first call; it resolves the address of `dns:` itself,
where gRPC's resolver asks the DNS server of the authority and refuses one
without a port at the first call; it raises `NOT_IMPLEMENTED` for `unix:`; and
it raises for a target that is not a `host[:port]` when the session is made,
where PySpark's channel fails its first call.
The credentials of the channel, against the plaintext server (a token of
`t`; "external" is an address of the host outside the loopback, of the same
server). Each line is the outcome of `range(2).count()`. Master connects to the
host of the URL and does not read `endpoint`, so its rows of an endpoint
override are of `localhost`:
| case | pyspark-client 4.3.0 | drop-in before (master) | drop-in now |
|---|---|---|---|
| token, URL localhost | count=2 | count=2 | count=2 |
| token, URL 127.0.0.1 | fails: TLS fails against the plaintext server |
fails: TLS fails against the plaintext server | fails: TLS fails against the
plaintext server |
| secure -> False, token, URL 127.0.0.1 | count=2 | fails: TLS fails against
the plaintext server | count=2 |
| secure -> False, URL 127.0.0.1 | count=2 | count=2 | count=2 |
| secure -> True, no token, URL localhost | count=2 | count=2 | count=2 |
| secure -> True, no token, URL 127.0.0.1 | fails: TLS fails against the
plaintext server | count=2 | fails: TLS fails against the plaintext server |
| secure -> True, use_ssl=true URL localhost | fails: TLS fails against the
plaintext server | fails: TLS fails against the plaintext server | fails: TLS
fails against the plaintext server |
| token, _host localhost, endpoint 127.0.0.1 | count=2 | count=2 | count=2 |
| token, _host localhost, endpoint [::1] | count=2 | count=2 | count=2 |
| token, _host localhost, endpoint external | fails: unreachable: details =
"failed to connect to all addresses; last error: UNKNOWN: ipv4:10 | count=2 |
fails: unreachable: details = "failed to connect to all addresses; last error:
UNKNOWN: ipv4:10 |
| no token, _host localhost, endpoint external | count=2 | count=2 | count=2
|
| token, _host 127.0.0.1, endpoint localhost | fails: TLS fails against the
plaintext server | fails: TLS fails against the plaintext server | fails: TLS
fails against the plaintext server |
| token, _host external, endpoint localhost | fails: TLS fails against the
plaintext server | fails: TLS fails against the plaintext server | fails: TLS
fails against the plaintext server |
| secure -> True, _host localhost, endpoint external | fails: unreachable:
details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:10 |
count=2 | fails: unreachable: details = "failed to connect to all addresses;
last error: UNKNOWN: ipv4:10 |
| env token, URL 127.0.0.1 | fails: TLS fails against the plaintext server |
fails: TLS fails against the plaintext server | fails: TLS fails against the
plaintext server |
| env token, secure -> False, URL 127.0.0.1 | count=2 | fails: TLS fails
against the plaintext server | count=2 |
| env token, secure -> False, URL localhost | count=2 | count=2 | count=2 |
| secure raises KeyError | raises when made: KeyError: 'secure' | count=2 |
raises when made: KeyError: 'secure' |
18 of 18 cases match PySpark now; 12 with drop-in before (master)
The token that reached a recording gRPC server of no service
(`authorization` of the calls; "not reached" is TLS against the plaintext
server):
| case | pyspark-client 4.3.0 | drop-in before (master) | drop-in now |
|---|---|---|---|
| token, URL localhost | reached, authorization ['Bearer t'] | reached,
authorization ['Bearer t'] | reached, authorization ['Bearer t'] |
| token, URL 127.0.0.1 | not reached: TLS fails against the plaintext server
| not reached: TLS fails against the plaintext server | not reached: TLS fails
against the plaintext server |
| token, secure -> False, URL localhost | reached, authorization ['None'] |
reached, authorization ['Bearer t'] | reached, authorization ['None'] |
| token, secure -> False, URL 127.0.0.1 | reached, authorization ['None'] |
not reached: TLS fails against the plaintext server | reached, authorization
['None'] |
| secure -> True, no token, URL localhost | reached, authorization ['None']
| reached, authorization ['None'] | reached, authorization ['None'] |
| token, _host localhost, endpoint 127.0.0.1 | reached, authorization
['Bearer t'] | reached, authorization ['Bearer t'] | reached, authorization
['Bearer t'] |
| token, _host localhost, endpoint 0.0.0.0 | reached, authorization ['Bearer
t'] | reached, authorization ['Bearer t'] | reached, authorization ['Bearer t']
|
| token -> 'p', URL localhost | reached, authorization ['Bearer p'] |
reached, authorization ['Bearer p'] | reached, authorization ['Bearer p'] |
| token -> 'p', secure -> False, URL localhost | reached, authorization
['None'] | reached, authorization ['Bearer p'] | reached, authorization
['None'] |
| token -> None, token=t URL localhost | reached, authorization ['None'] |
reached, authorization ['Bearer t'] | reached, authorization ['None'] |
| env token, URL localhost | reached, authorization ['Bearer e'] | reached,
authorization ['Bearer e'] | reached, authorization ['Bearer e'] |
| env token, URL 127.0.0.1 | not reached: TLS fails against the plaintext
server | not reached: TLS fails against the plaintext server | not reached: TLS
fails against the plaintext server |
| env token, secure -> False, URL localhost | reached, authorization
['None'] | reached, authorization ['Bearer e'] | reached, authorization
['None'] |
| env token, secure -> False, URL 127.0.0.1 | reached, authorization
['None'] | not reached: TLS fails against the plaintext server | reached,
authorization ['None'] |
| env token, token=t URL localhost | reached, authorization ['Bearer t'] |
reached, authorization ['Bearer t'] | reached, authorization ['Bearer t'] |
| no token, URL localhost | reached, authorization ['None'] | reached,
authorization ['None'] | reached, authorization ['None'] |
16 of 16 cases match PySpark now; 10 with drop-in before (master)
Local credentials (a token, `_host` `localhost`) of endpoints of the
loopback, whose connections have the local address `127.0.0.1` or `::1`:
| case | pyspark-client 4.3.0 | drop-in before (master) | drop-in now |
|---|---|---|---|
| 127.0.0.2:17839 | count=2 | count=2 | count=2 |
| 127.1.2.3:17839 | count=2 | count=2 | count=2 |
| 0.0.0.0:17839 | count=2 | count=2 | count=2 |
| [::]:17839 | count=2 | count=2 | count=2 |
| [::ffff:127.0.0.1]:17839 | count=2 | count=2 | count=2 |
| [::ffff:127.0.0.2]:17839 | count=2 | count=2 | count=2 |
| [::1]:17839 | count=2 | count=2 | count=2 |
| localhost:17839 | count=2 | count=2 | count=2 |
8 of 8 cases match PySpark now; 8 with drop-in before (master)
A connection of local credentials that is not of the loopback fails as
PySpark's, of both clients:
```
SparkConnectGrpcException details = "failed to connect to all addresses;
last error: UNKNOWN: ipv4:10.92.26.67:17839: Endpoint is neither UDS or TCP
loopback address."
```
The keys of the parameters of a builder, against a recorder of plaintext
gRPC on both clients (the outcome of a call, and the metadata keys that the
server saw). The `UNAVAILABLE` of master for `a=b;use_ssl` is the injection, a
TLS channel to the plaintext server. A key that gRPC does not take fails its
call (`INTERNAL`) in PySpark, and the session when it is made in the drop-in,
as it does on master of the same key of a connection string; this PR keeps
master's timing and text:
| case | pyspark-client 4.3.0 | master | e1 before (e14301b3) | e1 now |
|---|---|---|---|---|
| url key ok_key | UNIMPLEMENTED; server keys ['ok_key'] | UNIMPLEMENTED;
server keys ['ok_key'] | UNIMPLEMENTED; server keys ['ok_key'] | UNIMPLEMENTED;
server keys ['ok_key'] |
| url key x.y-z_0 | UNIMPLEMENTED; server keys ['x.y-z_0'] | UNIMPLEMENTED;
server keys ['x.y-z_0'] | UNIMPLEMENTED; server keys ['x.y-z_0'] |
UNIMPLEMENTED; server keys ['x.y-z_0'] |
| url key a%41 (not decoded) | INTERNAL; server keys [] | ValueError at
create: metadata was invalid: 'a%41' is not a gRPC metadata key, which is of
the characters [0-9; server keys [] | ValueError at create: metadata was
invalid: 'a%2541' is not a gRPC metadata key, which is of the characters [0;
server keys [] | ValueError at create: metadata was invalid: 'a%41' is not a
gRPC metadata key, which is of the characters [0-9; server keys [] |
| url key with space | INTERNAL; server keys [] | ValueError at create:
metadata was invalid: 'x hdr' is not a gRPC metadata key, which is of the
characters [0-; server keys [] | ValueError at create: metadata was invalid:
'x%20hdr' is not a gRPC metadata key, which is of the characters [; server keys
[] | ValueError at create: metadata was invalid: 'x hdr' is not a gRPC metadata
key, which is of the characters [0-; server keys [] |
| set 'Bad:Key' | INTERNAL; server keys [] | ValueError at create: metadata
was invalid: 'Bad:Key' is not a gRPC metadata key, which is of the characters
[; server keys [] | ValueError at create: metadata was invalid: 'Bad%3AKey' is
not a gRPC metadata key, which is of the characters; server keys [] |
ValueError at create: metadata was invalid: 'Bad:Key' is not a gRPC metadata
key, which is of the characters [; server keys [] |
| set 'a=b;use_ssl' = 'true' | INTERNAL; server keys [] | UNAVAILABLE;
server keys [] | ValueError at create: metadata was invalid: 'a%3Db%3Buse_ssl'
is not a gRPC metadata key, which is of the char; server keys [] | ValueError
at create: metadata was invalid: 'a=b;use_ssl' is not a gRPC metadata key,
which is of the characte; server keys [] |
| set 'x%2Dy' | INTERNAL; server keys [] | ValueError at create: metadata
was invalid: 'x%2Dy' is not a gRPC metadata key, which is of the characters
[0-; server keys [] | ValueError at create: metadata was invalid: 'x%252Dy' is
not a gRPC metadata key, which is of the characters [; server keys [] |
ValueError at create: metadata was invalid: 'x%2Dy' is not a gRPC metadata key,
which is of the characters [0-; server keys [] |
| set '' (empty key) | INTERNAL; server keys [] | ValueError at create:
metadata was invalid: '' is not a gRPC metadata key, which is of the characters
[0-9a-z_; server keys [] | ValueError at create: metadata was invalid: '' is
not a gRPC metadata key, which is of the characters [0-9a-z_; server keys [] |
ValueError at create: metadata was invalid: '' is not a gRPC metadata key,
which is of the characters [0-9a-z_; server keys [] |
| set 'ok' = 'v;w=1' | UNIMPLEMENTED; server keys ['ok'] | UNIMPLEMENTED;
server keys ['ok'] | UNIMPLEMENTED; server keys ['ok'] | UNIMPLEMENTED; server
keys ['ok'] |
### Why are the changes needed?
So that a session of a channel builder connects where PySpark's would, and
secures its channel as PySpark's `toChannel` does, which also covers subclasses
that override `endpoint`, `_host`, `_port`, `secure`, `use_ssl` or `token`.
### Does this PR introduce _any_ user-facing change?
Yes, for a session of a `DefaultChannelBuilder` or a subclass of it:
- it connects to the builder's `endpoint`, not to an overridden `host` or
`port`;
- its channel has the credentials of PySpark's `toChannel`: of no security
and no token unless the builder is `secure`, so `secure -> False` sends no
token, also of `SPARK_CONNECT_AUTHENTICATE_TOKEN`; else local credentials when
it is not `use_ssl` and `_host` is `localhost`, plaintext with the token over a
connection of the loopback only, where another fails with gRPC's `Endpoint is
neither UDS or TCP loopback address.`; else TLS with the token;
- an error of a subclass's `secure`, `use_ssl`, `_host` or `token` is raised
when the session is made;
- a URL with no port takes `DefaultChannelBuilder.default_port()`.
Sessions of an `sc://` URL, and the Rust API, are unchanged.
### How was this patch tested?
- **New offline tests** in `python/tests/test_dropin_offline.py`, with the
mock server, which now records the `authorization` of each execution:
-
`test_a_session_of_a_default_channel_builder_connects_to_its_endpoint_as_pyspark`:
the overrides of `host`, `endpoint`, `port`, `_host`, `_port`, `use_ssl` and
`default_port`; endpoints of bytes and of `dns:`, `dns://authority/`, `ipv4:`
and no port; the errors of an endpoint that is an int and of `unix:`.
-
`test_the_channel_of_a_default_channel_builder_is_secured_as_pysparks_to_channel`:
the token the server receives of the overrides of `secure`, `use_ssl`,
`_host`, `endpoint` (of `0.0.0.0` too) and `token`, and of the token of the
environment; the cases of TLS, which the plaintext server refuses; the
`KeyError` of a raising `secure` when the session is made; and gRPC's refusal
of local credentials to an address of the host outside the loopback, of a
listener of every address.
- `test_no_connection_string_nor_endpoint_sets_the_channel_of_a_builder`:
a parameter of the old reserved name in `remote()`,
`SparkSession(connection=str)`, `SPARK_REMOTE`, the URL of a
`DefaultChannelBuilder` and the `_params` of a builder of its own fails the
session when it is made (`metadata was invalid`), and sends nothing; a key of a
URL or of `set` outside `[0-9a-z_.-]` (`x hdr`, `a%41`, `Bad:Key`,
`a=b;use_ssl`, `x%2Dy`, an empty one) raises the transport's `ValueError` of
the key as it is, which fails on the previous revision (`'x%20hdr'`); an
endpoint of `?`, `?x=1`, `#`, `dns:///...?`, `/x`, `;a=b`, `user@` or a space
raises `INVALID_CONNECT_URL`, and sends nothing; and the order of the reads of
`toChannel`, of the token twice.
They fail on master, and the last one on the previous revision of this
change.
- **New Rust tests** in `spark-connect-core`:
-
`channel::tests::the_credentials_of_the_binding_decide_the_tls_and_the_token`:
the TLS and the token of each of the credentials, of a token of the environment
too;
- `channel::tests::a_connection_string_never_sets_the_credentials`: a
parameter of the old reserved name, or of another, is a parameter, of the rule
of the parameters and sent as metadata;
-
`connector::tests::a_connection_of_local_credentials_is_of_the_loopback_as_grpc_takes_it`:
the local addresses that gRPC's check takes (`127.0.0.1`, `::1`,
`::ffff:127.0.0.1`) and refuses (`127.0.0.2`, `0.0.0.0`, `::`, outside
addresses);
-
`connector::tests::a_target_of_local_credentials_connects_of_the_loopback_only`:
a listener of every address, connected of local credentials through
`127.0.0.1` and `0.0.0.0`, refused through an outside address of the host
(`Failure::NotLoopback`), which connects of no local credentials;
- the texts of `Failure::NotLoopback` in grpcio's dialect and the Rust
client's, in
`the_failures_have_grpc_core_s_texts_in_grpcio_s_dialect_and_the_rust_client_s_otherwise`.
-
`test_channel_builders_of_any_object_fail_when_the_session_is_made_as_pyspark`
and the other channel-builder tests pass unchanged.
- **Probes of both clients** against a Spark 4.3.0 server: the tables above.
- **`cargo test -p apache-spark-connect -p apache-spark-connect-core
--release`**, as `rust.yml`: 1,876 passed, 18 ignored, of 120 test binaries
(the core's unit tests: 346 passed).
- **The Rust and Python gates** (`gates.sh build rust py`):
- `cargo fmt --all --check`;
- `cargo +1.100.0 clippy -p apache-spark-connect-core -p
apache-spark-connect -p pyspark-rs --all-targets -- -D warnings`;
- `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps`;
- `cargo test -p pyspark-rs --lib`: 18 passed;
- ruff 0.14.0, `test_ruff_excludes.py`, `scripts/audit_no_stubs.sh`, the
stub and dispatch generators, the test-list guards and the license checks;
- `test_type_stubs_offline.py`: 15 passed, 4 skipped;
- the offline suite of `coverage.yml`: 7,037 passed, 114 skipped.
- **`scripts/check_vendored_upstream.sh`**: every vendored file matches
Apache Spark v4.3.0.
- **`test_dropin_e2e.py`** against a Spark 4.3.0 server: 352 passed.
### 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]