yuqi1129 commented on code in PR #6141:
URL: https://github.com/apache/gravitino/pull/6141#discussion_r1906873510


##########
bundles/gcp/src/main/java/org/apache/gravitino/gcs/credential/GCSTokenProvider.java:
##########
@@ -99,6 +101,57 @@ private AccessToken getToken(Set<String> readLocations, 
Set<String> writeLocatio
     return downscopedCredentials.refreshAccessToken();
   }
 
+  private List<String> getReadExpressions(String bucketName, String 
resourcePath) {
+    List<String> readExpressions = new ArrayList<>();
+    readExpressions.add(
+        String.format(
+            "resource.name.startsWith('projects/_/buckets/%s/objects/%s')",
+            bucketName, resourcePath));
+    getAllResources(resourcePath)
+        .forEach(
+            parentResourcePath ->
+                readExpressions.add(
+                    String.format(
+                        "resource.name == 'projects/_/buckets/%s/objects/%s'",
+                        bucketName, parentResourcePath)));
+    return readExpressions;
+  }
+
+  @VisibleForTesting
+  // "a/b/c" will get ["a", "a/", "a/b", "a/b/", "a/b/c"]
+  static List<String> getAllResources(String resourcePath) {

Review Comment:
   I gave the user the list object privileges for the bucket and read 
permission for the exact path, then the user will got the privileges.
   
   <img width="1668" alt="image" 
src="https://github.com/user-attachments/assets/071777b5-f55b-46b0-b842-f4beedbf9123";
 />
   
   
   The following is the result:
   
   **Can't list objects in the bucket root**
   <img width="1665" alt="image" 
src="https://github.com/user-attachments/assets/e0ed0307-708c-4185-9294-022690940d43";
 />
   
   **Can't list objects in the xiaoyu123/gcs_catalog_with_organization**
   <img width="1423" alt="image" 
src="https://github.com/user-attachments/assets/b1d6486c-a81a-451d-9f03-690f1a97d250";
 />
   
   **Can't list objects in the xiaoyu123/gcs_catalog_with_organization/schema**
   <img width="1622" alt="image" 
src="https://github.com/user-attachments/assets/1a12ddf3-687a-479e-9b65-71a41b472fe2";
 />
   
   **Can list objects in the 
xiaoyu123/gcs_catalog_with_organization/schema/example**
   <img width="1471" alt="image" 
src="https://github.com/user-attachments/assets/bc890c12-6f77-4599-a3ad-692ce204511e";
 />
   
   **Can list objects in the 
xiaoyu123/gcs_catalog_with_organization/schema/example/people**
   <img width="1560" alt="image" 
src="https://github.com/user-attachments/assets/c5c599df-9509-44aa-9096-200a7d904f18";
 />



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

Reply via email to