Vamsi-klu commented on code in PR #18975:
URL: https://github.com/apache/pinot/pull/18975#discussion_r3817447600


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/access/AuthenticationFilter.java:
##########
@@ -130,35 +142,70 @@ AccessType extractAccessType(Method endpointMethod) {
     return AccessType.READ;
   }
 
+  /// Resolves the table `endpointMethod` acts on, or `null` when the request 
addresses the cluster rather than a
+  /// table. `AccessControlUtils.validatePermission` picks the table-scoped or 
the cluster-wide check on that answer,
+  /// so it must not be steerable by the caller.
+  ///
+  /// Path parameters are template variables of the endpoint's own `@Path`, 
hence part of its declaration. Query
+  /// parameters are caller-supplied and JAX-RS surfaces every one present on 
the URI, so only those the endpoint
+  /// declares may name the table: otherwise a caller could append 
`?tableName=<a table it is scoped to>` to a cluster
+  /// endpoint and have it authorized as a table-scoped request.
+  @Nullable
   @VisibleForTesting
   static String extractTableName(Method endpointMethod, MultivaluedMap<String, 
String> pathParameters,
       MultivaluedMap<String, String> queryParameters) {
     Authorize authorize = endpointMethod.getAnnotation(Authorize.class);
     if (authorize != null && authorize.targetType() == TargetType.TABLE) {
-      return FineGrainedAuthUtils.findRawTargetId(authorize, pathParameters, 
queryParameters);
+      // The annotation names the parameter, but it is only trustworthy where 
the endpoint also binds it.
+      MultivaluedMap<String, String> trustedQueryParameters =
+          declaredQueryParams(endpointMethod).contains(authorize.paramName()) 
? queryParameters
+              : new MultivaluedHashMap<>();
+      return FineGrainedAuthUtils.findRawTargetId(authorize, pathParameters, 
trustedQueryParameters);
     }
-    return extractTableName(pathParameters, queryParameters);
-  }
-
-  @VisibleForTesting
-  static String extractTableName(MultivaluedMap<String, String> pathParameters,
-      MultivaluedMap<String, String> queryParameters) {
     String tableName = extractTableName(pathParameters);
     if (tableName != null) {
       return tableName;
     }
-    return extractTableName(queryParameters);
+    Set<String> declaredQueryParams = declaredQueryParams(endpointMethod);
+    for (String key : TABLE_NAME_KEYS) {
+      if (queryParameters.containsKey(key) && 
declaredQueryParams.contains(key)) {
+        return queryParameters.getFirst(key);
+      }
+    }
+    return null;
   }
 
-  private static String extractTableName(MultivaluedMap<String, String> mmap) {
-    if (mmap.containsKey(KEY_TABLE_NAME)) {
-      return mmap.getFirst(KEY_TABLE_NAME);
-    }
-    if (mmap.containsKey(KEY_TABLE_NAME_WITH_TYPE)) {
-      return mmap.getFirst(KEY_TABLE_NAME_WITH_TYPE);
+  /// Returns the names `endpointMethod` binds as [QueryParam]s.
+  ///
+  /// Only method-level `@QueryParam` binding is recognized; an endpoint 
binding parameters through `@BeanParam` or
+  /// resource-class field injection is treated as declaring none. That 
direction denies table scope rather than
+  /// granting it, so it fails closed — no controller resource uses either 
form today.
+  ///
+  /// Results are memoized because [Method#getParameterAnnotations()] 
re-parses the class-file annotation bytes on
+  /// every call, and this runs on every request before authentication. The 
key set is bounded by the number of
+  /// endpoints.

Review Comment:
   Yep, that was the common path. I dropped the empty map. Path param first, 
then a declared query param, same as you sketched. No allocation on GET 
/tables/{tableName} and friends.



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