Copilot commented on code in PR #16475: URL: https://github.com/apache/pinot/pull/16475#discussion_r2258624012
########## pinot-query-runtime/src/main/java/org/apache/pinot/query/access/QueryAccessControlFactory.java: ########## @@ -0,0 +1,47 @@ +/** + * 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.query.access; + +import org.apache.pinot.spi.annotations.InterfaceAudience; +import org.apache.pinot.spi.annotations.InterfaceStability; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.plugin.PluginManager; + +import static org.apache.pinot.spi.utils.CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS; +import static org.apache.pinot.spi.utils.CommonConstants.Helix.DEFAULT_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS; + + [email protected] [email protected] +public abstract class QueryAccessControlFactory { + void init(PinotConfiguration configuration) { + } + + public abstract QueryAccessControl create(); + + public static QueryAccessControlFactory fromConfig(PinotConfiguration configuration) { + String configuredClass = configuration.getProperty(CONFIG_OF_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS, + DEFAULT_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS); + try { + return PluginManager.get().createInstance(configuredClass); + } catch (Exception ex) { + return null; Review Comment: Returning null when plugin creation fails could cause NullPointerException in calling code. Consider throwing a meaningful exception or returning a default implementation instead. ```suggestion throw new RuntimeException("Failed to create QueryAccessControlFactory instance for class: " + configuredClass, ex); ``` ########## pinot-query-runtime/src/main/java/org/apache/pinot/query/access/AuthorizationInterceptor.java: ########## @@ -0,0 +1,47 @@ +/** + * 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.query.access; + +import io.grpc.Metadata; +import io.grpc.ServerCall; +import io.grpc.ServerCallHandler; +import io.grpc.ServerInterceptor; +import io.grpc.Status; +import javax.annotation.Nullable; + +public class AuthorizationInterceptor implements ServerInterceptor { + private final QueryAccessControlFactory _accessControlFactory; + + public AuthorizationInterceptor(@Nullable QueryAccessControlFactory accessControlFactory) { + _accessControlFactory = accessControlFactory; + } + + @Override + public <T, R> ServerCall.Listener<T> interceptCall(ServerCall<T, R> call, Metadata headers, + ServerCallHandler<T, R> next) { + if (_accessControlFactory == null) { + return next.startCall(call, headers); + } + + if (!_accessControlFactory.create().hasAccess(call.getAttributes(), headers)) { Review Comment: Creating a new QueryAccessControl instance on every request via `_accessControlFactory.create()` could be inefficient. Consider caching the instance if it's stateless or reusing it across requests. ```suggestion if (!_accessControl.hasAccess(call.getAttributes(), headers)) { ``` ########## pinot-query-runtime/src/main/java/org/apache/pinot/query/access/QueryAccessControlFactory.java: ########## @@ -0,0 +1,47 @@ +/** + * 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.query.access; + +import org.apache.pinot.spi.annotations.InterfaceAudience; +import org.apache.pinot.spi.annotations.InterfaceStability; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.plugin.PluginManager; + +import static org.apache.pinot.spi.utils.CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS; Review Comment: The import references `CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS` but the constant is defined in `CommonConstants.Instance` based on the diff. This will cause a compilation error. ```suggestion import static org.apache.pinot.spi.utils.CommonConstants.Instance.CONFIG_OF_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS; ``` ########## pinot-query-runtime/src/main/java/org/apache/pinot/query/access/QueryAccessControlFactory.java: ########## @@ -0,0 +1,47 @@ +/** + * 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.query.access; + +import org.apache.pinot.spi.annotations.InterfaceAudience; +import org.apache.pinot.spi.annotations.InterfaceStability; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.plugin.PluginManager; + +import static org.apache.pinot.spi.utils.CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS; +import static org.apache.pinot.spi.utils.CommonConstants.Helix.DEFAULT_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS; Review Comment: The import references `CommonConstants.Helix.DEFAULT_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS` but the constant is defined in `CommonConstants.Instance` based on the diff. This will cause a compilation error. ```suggestion import static org.apache.pinot.spi.utils.CommonConstants.Instance.DEFAULT_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS; ``` ########## pinot-query-runtime/src/main/java/org/apache/pinot/query/access/AuthorizationInterceptor.java: ########## @@ -0,0 +1,47 @@ +/** + * 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.query.access; + +import io.grpc.Metadata; +import io.grpc.ServerCall; +import io.grpc.ServerCallHandler; +import io.grpc.ServerInterceptor; +import io.grpc.Status; +import javax.annotation.Nullable; + +public class AuthorizationInterceptor implements ServerInterceptor { + private final QueryAccessControlFactory _accessControlFactory; + + public AuthorizationInterceptor(@Nullable QueryAccessControlFactory accessControlFactory) { + _accessControlFactory = accessControlFactory; + } + + @Override + public <T, R> ServerCall.Listener<T> interceptCall(ServerCall<T, R> call, Metadata headers, + ServerCallHandler<T, R> next) { + if (_accessControlFactory == null) { + return next.startCall(call, headers); + } + + if (!_accessControlFactory.create().hasAccess(call.getAttributes(), headers)) { + call.close(Status.PERMISSION_DENIED.withDescription("MSE Access Denied"), headers); Review Comment: After calling `call.close()` for permission denied, the method continues to execute and calls `next.startCall()`. This should return early to prevent further processing. ```suggestion call.close(Status.PERMISSION_DENIED.withDescription("MSE Access Denied"), headers); return new ServerCall.Listener<T>() {}; ``` -- 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]
