yashmayya commented on code in PR #16043: URL: https://github.com/apache/pinot/pull/16043#discussion_r2163372929
########## pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/RlsFiltersRewriter.java: ########## @@ -0,0 +1,62 @@ +/** + * 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.sql.parsers.rewriter; + +import java.util.List; +import java.util.Map; +import org.apache.commons.collections4.MapUtils; +import org.apache.logging.log4j.util.Strings; +import org.apache.pinot.common.request.Expression; +import org.apache.pinot.common.request.PinotQuery; +import org.apache.pinot.common.utils.request.RequestUtils; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; +import org.apache.pinot.sql.FilterKind; +import org.apache.pinot.sql.parsers.CalciteSqlParser; + + +public class RlsFiltersRewriter implements QueryRewriter { + + private static final String ROW_FILTERS = "rowFilters"; Review Comment: Unused? ########## pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseSingleStageBrokerRequestHandler.java: ########## @@ -434,6 +437,26 @@ protected BrokerResponse doHandleRequest(long requestId, String query, SqlNodeAn throwAccessDeniedError(requestId, query, requestContext, tableName, authorizationResult); } + TableRowColAuthResult rlsFilters = accessControl.getRowColFilters(requesterIdentity, tableName); + + //rewrite query + Map<String, String> queryOptions = + pinotQuery.getQueryOptions() == null ? new HashMap<>() : pinotQuery.getQueryOptions(); + + rlsFilters.getRLSFilters().ifPresent(rowFilters -> { + String combinedFilters = + rowFilters.stream().map(filter -> "( " + filter + " )").collect(Collectors.joining(" AND ")); + queryOptions.put(tableName, combinedFilters); Review Comment: What if the table name collides with some existing query option name (possible since these aren't reserved words)? ########## pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/RlsFiltersRewriter.java: ########## @@ -0,0 +1,62 @@ +/** + * 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.sql.parsers.rewriter; + +import java.util.List; +import java.util.Map; +import org.apache.commons.collections4.MapUtils; +import org.apache.logging.log4j.util.Strings; +import org.apache.pinot.common.request.Expression; +import org.apache.pinot.common.request.PinotQuery; +import org.apache.pinot.common.utils.request.RequestUtils; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; +import org.apache.pinot.sql.FilterKind; +import org.apache.pinot.sql.parsers.CalciteSqlParser; + + +public class RlsFiltersRewriter implements QueryRewriter { Review Comment: Can we add a Javadoc to this class describing its intended usage? ########## pinot-spi/src/main/java/org/apache/pinot/spi/auth/TableRowColAuthResult.java: ########## @@ -0,0 +1,36 @@ +/** + * 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.spi.auth; + +import java.util.List; +import java.util.Optional; + + +/** + * This interfaces carries the RLS/CLS filter for a particular table + */ +public interface TableRowColAuthResult { + /** + * Returns the RLS filters associated with a particular table. RLS filters are defined as a list. + * @return optional of the RLS filters. Empty optional is there are no RLS filters defined on this table Review Comment: ```suggestion * @return optional of the RLS filters. Empty optional if there are no RLS filters defined on this table ``` ########## pinot-spi/src/main/java/org/apache/pinot/spi/auth/TableRowColAuthResult.java: ########## @@ -0,0 +1,36 @@ +/** + * 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.spi.auth; + +import java.util.List; +import java.util.Optional; + + +/** + * This interfaces carries the RLS/CLS filter for a particular table + */ +public interface TableRowColAuthResult { + /** + * Returns the RLS filters associated with a particular table. RLS filters are defined as a list. + * @return optional of the RLS filters. Empty optional is there are no RLS filters defined on this table + */ + Optional<List<String>> getRLSFilters(); + + TableRowColAuthResult setRLSFilters(List<String> rlsFilters); Review Comment: Why does this method need to return `TableRowColAuthResult`? ########## pinot-broker/src/main/java/org/apache/pinot/broker/api/AccessControl.java: ########## @@ -120,4 +122,15 @@ default TableAuthorizationResult authorize(RequesterIdentity requesterIdentity, return hasAccess(requesterIdentity, tables) ? TableAuthorizationResult.success() : new TableAuthorizationResult(tables); } + + + /** + * Returns RLS/CLS filters for a particular table. By default, there are no RLS/CLS filters on any table. Review Comment: We're using these terms RLS / CLS in various classes but I don't see anywhere they're actually being defined? Can we add the full name (presumably row / col level security) to some of these comments? -- 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: commits-unsubscr...@pinot.apache.org 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