sungwy commented on code in PR #3332:
URL: https://github.com/apache/polaris/pull/3332#discussion_r2646326511


##########
extensions/auth/opa/tests/src/intTest/java/org/apache/polaris/extension/auth/opa/test/OpaAdminServiceIT.java:
##########
@@ -0,0 +1,428 @@
+/*
+ * 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.polaris.extension.auth.opa.test;
+
+import static io.restassured.RestAssured.given;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.http.ContentType;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableMetadataParser;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * OPA authorization coverage for management endpoints:
+ *
+ * <ul>
+ *   <li>Catalog list/create
+ *   <li>Principal-role to catalog-role bindings
+ *   <li>Catalog-role grant management
+ *   <li>Catalog-role assignee listings
+ *   <li>Catalog-role grant listings
+ * </ul>
+ */
+@QuarkusTest
+@TestProfile(OpaIntegrationTest.StaticTokenOpaProfile.class)
+public class OpaAdminServiceIT extends OpaIntegrationTestBase {
+
+  private String baseCatalogName;
+  private String baseCatalogLocation;
+  private String baseRootToken;
+
+  @BeforeEach
+  void setupBaseCatalog() throws Exception {
+    baseRootToken = getRootToken();
+    baseCatalogName = "opa-base-cat-" + 
UUID.randomUUID().toString().replace("-", "");
+    baseCatalogLocation = 
Files.createTempDirectory("opa-base-cat").toUri().toString();
+    createFileCatalog(
+        baseRootToken, baseCatalogName, baseCatalogLocation, 
List.of(baseCatalogLocation));
+  }
+
+  @Test
+  void assignCatalogRoleToPrincipalRole() {
+    String rootToken = baseRootToken;
+    String strangerToken = createPrincipalAndGetToken("stranger-" + 
UUID.randomUUID());
+
+    String catalogRole = "opa-cat-role-" + 
UUID.randomUUID().toString().replace("-", "");
+    String principalRole = "opa-pr-role-" + 
UUID.randomUUID().toString().replace("-", "");
+
+    // create catalog role
+    given()
+        .contentType(ContentType.JSON)
+        .header("Authorization", "Bearer " + rootToken)
+        .body(toJson(Map.of("name", catalogRole, "properties", Map.of())))
+        .post("/api/management/v1/catalogs/{cat}/catalog-roles", 
baseCatalogName)
+        .then()
+        .statusCode(201);
+
+    // create principal role
+    given()
+        .contentType(ContentType.JSON)
+        .header("Authorization", "Bearer " + rootToken)
+        .body(toJson(Map.of("name", principalRole, "properties", Map.of())))
+        .post("/api/management/v1/principal-roles")
+        .then()
+        .statusCode(201);
+
+    Map<String, Object> grantRequest =
+        Map.of("catalogRole", Map.of("name", catalogRole, "properties", 
Map.of()));
+
+    // stranger cannot bind
+    given()
+        .contentType(ContentType.JSON)
+        .header("Authorization", "Bearer " + strangerToken)
+        .body(toJson(grantRequest))
+        .put(
+            "/api/management/v1/principal-roles/{pr}/catalog-roles/{cat}",
+            principalRole,
+            baseCatalogName)
+        .then()
+        .statusCode(403);
+
+    // root binds successfully
+    given()
+        .contentType(ContentType.JSON)
+        .header("Authorization", "Bearer " + rootToken)
+        .body(toJson(grantRequest))
+        .put(
+            "/api/management/v1/principal-roles/{pr}/catalog-roles/{cat}",

Review Comment:
   
   Yes — that’s actually one of the motivations for this PR. By explicitly 
encoding the current authorization outcomes in tests, we get a clear, 
executable snapshot of today’s behavior. Im hoping that'll help us:
   - refactor the authorization flow and RBAC resolution with confidence, and 
precisely see what behavior changes as a result
   - intentionally revisit (and potentially forbid) certain flows as RBAC 
resolution is removed from the Handlers — for example, whether operations like 
assigning catalog roles to principal roles should remain valid when 
authorization is fully externalized in OpaPolarisAuthorizer



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