geyanggang commented on code in PR #14755:
URL: https://github.com/apache/gravitino/pull/14755#discussion_r4561068132
##########
docs/spark-connector/spark-rest-catalog-discovery.md:
##########
@@ -79,6 +79,39 @@ Set
`spark.sql.gravitino.lanceREST.catalogProperties.namespaceDelimiter` when th
server uses a namespace delimiter other than the default `$`. The property is
used for the
discovery request and is also copied to each discovered catalog.
+### User identity
+
+When `spark.sql.gravitino.authType` is `simple` (the default), the discovery
plugin uses
+`SparkContext.sparkUser()` as the Lance user. It sends an HTTP Basic header
with the UTF-8 encoded
+value `<user>:unused` for discovery and copies it to each automatically
registered Lance catalog.
+The password is a placeholder. Usernames containing a colon require explicit
credentials because
+HTTP Basic uses the colon to separate the username from the password.
+
+Set `spark.sql.gravitino.lanceREST.catalogProperties.headers.Authorization` to
use explicit
+credentials for discovery and as the default for registered catalogs. A
per-catalog
+`spark.sql.catalog.<name>.headers.Authorization` overrides the global header
for that catalog's
+operations. Header names are case-insensitive. Within each configuration
scope, equivalent keys
+with identical values are collapsed and conflicting values are rejected.
+
+The plugin generates a header only when `authType` is `simple`. This setting
selects the default
+for the Lance endpoint independently of Hadoop security, so a Kerberos-enabled
Spark application
+can use it to access an independent simple-auth Lance REST server. Configure
explicit credentials
+when the Lance endpoint uses a different authentication scheme. Manually
registered catalogs
+require their own configuration.
+
+#### Upgrading existing jobs
+
+Default-simple jobs now send a Basic header even if they previously sent no
authentication header.
+In auxiliary mode, requests that previously fell back to the Lance REST
service user may now
+execute as the Spark user. Before upgrading, register that user and grant the
permissions needed
+for discovery and subsequent operations. Missing grants can cause HTTP 403
responses, and objects
+created by the job may have a different creator or owner. Configure an
explicit global
Review Comment:
[Nit] "Configure an explicit global Authorization header ... to preserve its
previous identity" is slightly inaccurate: before this change the job sent no
Authorization header, so the server treated it as anonymous and fell back to
the service user. To get that back, the user would have to send a Basic header
for the service user name. I also noticed that setting `headers.Authorization`
to an empty value suppresses the generated header and nothing is sent on the
wire, which works as an opt-out but is neither documented nor tested. Could we
either document and test that as the supported way to keep the old behavior, or
reword this sentence?
##########
spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/plugin/restcatalog/lance/TestLanceRESTCatalogProvider.java:
##########
@@ -106,6 +107,36 @@ void testUsesConfiguredNamespaceDelimiter() {
assertTrue(rawQueries.get(0).contains("delimiter=%23"));
}
+ @Test
+ void testDiscoverySendsConfiguredHeadersOnEveryPage() {
+ List<String> authorizationHeaders = new CopyOnWriteArrayList<>();
+ List<String> customHeaders = new CopyOnWriteArrayList<>();
+ server.createContext(
+ "/lance/v1/namespace/$/list",
+ exchange -> {
+
authorizationHeaders.addAll(exchange.getRequestHeaders().get("Authorization"));
+
customHeaders.add(exchange.getRequestHeaders().getFirst("X-Test-User"));
+ if (authorizationHeaders.size() == 1) {
+ respond(exchange, 200,
"{\"namespaces\":[\"catalog_a\"],\"page_token\":\"next\"}");
+ } else {
+ respond(exchange, 200, "{\"namespaces\":[\"catalog_b\"]}");
+ }
+ });
+ server.start();
+ Map<String, String> properties = new LinkedHashMap<>();
+ properties.put("headers.authorization", "Basic ZXR1c2VyOnVudXNlZA==");
+ properties.put("Headers.Authorization", "Basic ZXR1c2VyOnVudXNlZA==");
Review Comment:
[Nit] `listCatalogs` now normalizes headers itself, but this test only
covers a single mixed-case key. The duplicate-collapse and conflict-rejection
paths are tested through the plugin, where `LanceAuthProvider` replaces
`listCatalogs`. Could we add a provider-level test with the embedded HTTP
server that checks (a) `headers.Authorization` + `headers.authorization` with
the same value sends exactly one value, and (b) different values throw without
echoing the credentials? I ran this manually and both behave correctly, so it's
only to guard against regressions.
--
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]