geyanggang commented on code in PR #14755:
URL: https://github.com/apache/gravitino/pull/14755#discussion_r4559377879


##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/plugin/restcatalog/lance/LanceRESTCatalogProvider.java:
##########
@@ -63,6 +63,12 @@ public List<String> listCatalogs(String uri, Map<String, 
String> catalogProperti
 
     ApiClient apiClient = new ApiClient().setBasePath(normalizeUri(uri));
     try (Closeable httpClient = getHttpClient(apiClient)) {
+      catalogProperties.forEach(
+          (key, value) -> {
+            if (StringUtils.startsWithIgnoreCase(key, "headers.")) {
+              apiClient.addDefaultHeader(key.substring("headers.".length()), 
value);

Review Comment:
   Header names are case-sensitive in `ApiClient`, so `headers.Authorization` 
and `headers.authorization` both end up on the wire. I reproduced this locally: 
the server receives two `Authorization` values (`[Bearer A, Bearer B]`). The 
plugin already treats these keys case-insensitively, so could we dedupe 
case-insensitively here too (last one wins, or fail fast)? A test for it would 
help.



##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/plugin/restcatalog/GravitinoLakehouseRESTDiscoveryDriverPlugin.java:
##########
@@ -105,6 +116,18 @@ void initialize(SparkConf sparkConf, Map<String, String> 
providerClassNames) {
           validateProviderRuntime(provider, classLoader);
 
           Map<String, String> globalProperties = 
extractCatalogProperties(userConf, format);
+          if ("lance".equals(format)

Review Comment:
   This puts Lance-specific logic (the format name and `headers.Authorization`) 
into the generic discovery plugin. Would it be cleaner to add a default method 
on `LakehouseRESTCatalogProvider`, e.g. `defaultCatalogProperties(authType, 
sparkUser)`, and let the Lance provider decide? The case-insensitive 
`headers.Authorization` check is also repeated in three places and could be a 
shared constant/helper.



##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/plugin/restcatalog/GravitinoLakehouseRESTDiscoveryDriverPlugin.java:
##########
@@ -105,6 +116,18 @@ void initialize(SparkConf sparkConf, Map<String, String> 
providerClassNames) {
           validateProviderRuntime(provider, classLoader);
 
           Map<String, String> globalProperties = 
extractCatalogProperties(userConf, format);
+          if ("lance".equals(format)
+              && AuthProperties.isSimple(

Review Comment:
   `GravitinoDriverPlugin.createGravitinoClient` rejects simple auth when 
`UserGroupInformation.isSecurityEnabled()` is true, but this path doesn't. I 
verified that with Kerberos enabled the header is still generated and sent. Is 
that intentional? If not, could we align the two paths? Also, 
`SimpleTokenProvider` uses `dummy` as the placeholder password while this uses 
`unused`; reusing the shared encoding (and 
`AuthConstants.AUTHORIZATION_BASIC_HEADER`) would avoid drift.



##########
docs/spark-connector/spark-rest-catalog-discovery.md:
##########
@@ -79,6 +79,25 @@ 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 reuses

Review Comment:
   Since `authType` defaults to `simple`, this changes behavior for every 
existing Lance user: they will now send `Authorization: Basic ...` on discovery 
and on registered catalogs. For a standalone Lance REST server that expects 
another scheme (or rejects Basic), this could turn a working setup into a 401. 
Could we call this out explicitly in the docs/release note, and consider an 
opt-out (or at least document that setting an explicit `headers.Authorization` 
is the way to disable it)?



##########
spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/plugin/restcatalog/TestGravitinoLakehouseRESTDiscoveryDriverPlugin.java:
##########
@@ -94,6 +100,140 @@ void testGeneratedConfigurationAndPrecedence() {
         sparkConf.get(StaticSQLConf.SPARK_SESSION_EXTENSIONS().key()));
   }
 
+  @Test
+  void testLanceReusesSparkContextUser() {

Review Comment:
   The plugin tests use a fake provider and the provider tests use hand-written 
properties, so the contract between them (plugin-generated 
`headers.Authorization` consumed by the real `LanceRESTCatalogProvider`) isn't 
covered. I wrote a throwaway test with an embedded HTTP server and the real 
provider, and it passes. Could we add a similar test to lock this in? Edge 
cases worth covering: mixed-case duplicate headers, and a username containing 
`:` (the server's `SimpleAuthenticator` splits on `:`, so `a:b` authenticates 
as `a`).



-- 
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]

Reply via email to