yashmayya commented on code in PR #19234:
URL: https://github.com/apache/pinot/pull/19234#discussion_r3797529880


##########
pinot-common/src/main/java/org/apache/pinot/common/config/provider/AccessControlUserCache.java:
##########
@@ -87,6 +87,13 @@ public List<UserConfig> getAllControllerUserConfig() {
     return 
_userControllerConfigMap.values().stream().collect(Collectors.toList());
   }
 
+  /// Returns the cache-owned controller user config for the given raw 
username, or `null` when no such user exists.
+  /// Callers must treat the returned config as read-only.
+  @Nullable
+  public UserConfig getControllerUserConfigForUsername(String rawUsername) {
+    return _userControllerConfigMap.get(rawUsername + "_" + 
ComponentType.CONTROLLER);

Review Comment:
   The map is keyed by `UserConfig.getUsernameWithComponent()`, which uses the 
raw `getUserName()`. The map this replaces was keyed by 
`ZkBasicAuthPrincipal.getName()`, and `BasicAuthPrincipalUtils` trims that name.
   
   So a stored username with leading or trailing whitespace used to 
authenticate under its trimmed form and no longer will. Narrow, and it fails 
closed, but trimming here would keep the old behaviour.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/LLCSegmentCompletionHandlers.java:
##########
@@ -83,7 +83,8 @@ public static String getScheme() {
   // We don't want to document these in swagger since they are internal APIs
   @GET
   @Path(SegmentCompletionProtocol.MSG_TYPE_EXTEND_BUILD_TIME)
-  @Authorize(targetType = TargetType.CLUSTER, action = 
Actions.Cluster.GET_ADMIN_INFO)
+  @Authenticate(AccessType.CREATE)
+  @Authorize(targetType = TargetType.CLUSTER, action = 
Actions.Cluster.COMMIT_SEGMENT)

Review Comment:
   These five segment-completion GETs move from READ + `GetAdminInfo` to CREATE 
+ `CommitSegment`. They are mutations, so the new metadata is correct, but 
servers call them on every segment commit. A deployment whose 
server-to-controller credential carries only `read`, or whose fine-grained 
policy grants `GetAdminInfo`, starts failing segment commits as soon as the 
Controller is upgraded.
   
   Worth stating in the PR description as an ordering requirement: grant 
`create` and `CommitSegment` to the server identity before rolling the 
Controller.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/access/BaseBasicAuthAccessControl.java:
##########
@@ -0,0 +1,73 @@
+/**
+ * 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.util.Objects;
+import java.util.Optional;
+import javax.ws.rs.NotAuthorizedException;
+import javax.ws.rs.core.HttpHeaders;
+import org.apache.pinot.core.auth.BasicAuthPrincipal;
+import org.apache.pinot.core.auth.TargetType;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+
+
+/// Shared controller BasicAuth policy, independent of how principals are 
loaded and credentials are verified.
+/// This class is stateless and thread-safe; subclass principal resolution 
must also be thread-safe.
+abstract class BaseBasicAuthAccessControl<P extends BasicAuthPrincipal> 
implements AccessControl {
+  @Override
+  public final boolean protectAnnotatedOnly() {
+    return false;
+  }
+
+  @Override
+  public final boolean hasAccess(String tableName, AccessType accessType, 
HttpHeaders httpHeaders,
+      String endpointUrl) {
+    String rawTableName = TableNameBuilder.extractRawTableName(tableName);
+    return getPrincipal(httpHeaders)
+        .filter(p -> p.hasTable(rawTableName) && 
p.hasPermission(Objects.toString(accessType))).isPresent();

Review Comment:
   This applies `extractRawTableName` for the static implementation too, which 
did not normalize before — only the ZK one did. On the filter path the name 
already arrives raw from `AccessControlUtils.validatePermission`, so nothing 
changes there. But direct callers pass the parameter as-is: 
`PinotSegmentUploadDownloadRestletResource.downloadSegment` is one, so a 
static-BasicAuth principal with `tables=myTable` was denied `myTable_OFFLINE` 
before and is allowed now.
   
   This reads as the intended fix, since it matches the ZK implementation and 
the Server-side one. But the description says table-scoped behaviour is 
unchanged, which is not quite true here. `testTablePermissionsRemainUnchanged` 
would be a good place to pin it with a type-suffixed name.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotControllerLogger.java:
##########
@@ -141,7 +141,7 @@ public Set<String> getLocalLogFiles() {
   @Path("/loggers/download")
   @Authorize(targetType = TargetType.CLUSTER, action = 
Actions.Cluster.GET_LOG_FILE)
   @Produces(MediaType.APPLICATION_OCTET_STREAM)
-  @Authenticate(AccessType.DELETE)
+  @Authenticate(AccessType.READ)

Review Comment:
   Both log download endpoints move from DELETE to READ. DELETE was clearly 
wrong for a download, but READ is the widest bucket: under BasicAuth any 
read-only principal can now pull Controller and instance log files. 
Fine-grained implementations still gate on `GET_LOG_FILE`, so this only affects 
the CRUD path.
   
   Was READ the intent, or is UPDATE a closer fit given what log files can 
contain?



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