apucher commented on a change in pull request #6507:
URL: https://github.com/apache/incubator-pinot/pull/6507#discussion_r568197551



##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/api/access/AccessControl.java
##########
@@ -30,9 +30,38 @@
   /**
    * Return whether the client has data access to the given table.
    *
-   * @param httpHeaders Http headers
+   * Note: This method is only used fore read access. It's being deprecated 
and its usage will be replaced by
+   * `hasAccess` method with AccessType.READ.
+   *
+   * @param httpHeaders HTTP headers containing requester identity
    * @param tableName Name of the table to be accessed
    * @return Whether the client has data access to the table
    */
+  @Deprecated
   boolean hasDataAccess(HttpHeaders httpHeaders, String tableName);
+
+  /**
+   * Return whether the client has permission to the given table
+   *
+   * @param tableName name of the table to be accessed
+   * @param accessType type of the access
+   * @param httpHeaders HTTP headers containing requester identity
+   * @param endpointUrl the request url for which this access control is called
+   * @return whether the client has permission
+   */
+  default boolean hasAccess(String tableName, AccessType accessType, 
HttpHeaders httpHeaders, String endpointUrl) {

Review comment:
       I wonder if we should stay away from a default implementation for access 
control. Then again, there's an argument to be made for facilitating a smooth 
transition. @Jackie-Jiang thoughts?

##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/api/ControllerAdminApiApplication.java
##########
@@ -124,4 +141,64 @@ public void filter(ContainerRequestContext 
containerRequestContext,
       containerResponseContext.getHeaders().add("Access-Control-Allow-Origin", 
"*");
     }
   }
+
+  @javax.ws.rs.ext.Provider
+  public static class AuthFilter implements ContainerRequestFilter {

Review comment:
       Would you mind extracting this to a separate class file?

##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/api/access/AccessControlUtils.java
##########
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pinot.controller.api.access;
+
+import java.lang.reflect.Method;
+import java.util.Optional;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import 
org.apache.pinot.controller.api.resources.ControllerApplicationException;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Utility class to simplify access control validation. This class is simple 
wrapper around AccessControl class.
+ */
+public class AccessControlUtils {

Review comment:
       imo this could be a static singleton with static methods - though I 
might be missing some subtle details here.

##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/api/access/AccessType.java
##########
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pinot.controller.api.access;
+
+/**
+ * Different access types used in access control of the rest endpoints
+ */
+public enum AccessType {
+  CREATE, READ, UPDATE, DELETE

Review comment:
       I wonder if there's a way of combining CREATE and UPDATE into one. I can 
see a case for update without create, but create without update seems tricky 
(e.g. create vs update with instance partitions)

##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTaskRestletResource.java
##########
@@ -289,6 +291,7 @@ public StringResultResponse getTaskStateDeprecated(
 
   @POST
   @Path("/tasks/schedule")
+  @Authenticate(AccessType.UPDATE)

Review comment:
       create? another one of these create/update cases




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to