You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "roryqi (via GitHub)" <gi...@apache.org> on 2026/06/08 12:29:45 UTC

[PR] [#11501] test(iceberg-rest): Add Trino IT for Iceberg REST authorization in auxMode [gravitino]

roryqi opened a new pull request, #11502:
URL: https://github.com/apache/gravitino/pull/11502

   ### What changes were proposed in this pull request?
   
   Add a new test-only module `iceberg/iceberg-rest-trino-it` that verifies Gravitino's authorization is enforced when an Iceberg REST Catalog served in auxiliary mode (`auxMode`) is accessed through Trino's native `iceberg` REST connector. This is the Trino analog of the Spark-based `IcebergAuthorizationIT`.
   
   Specifically:
   - **`build.gradle.kts` + `settings.gradle.kts`** — scaffold the module on a Java 24 toolchain with `trino-iceberg:478` / `trino-testing:478`, mirroring `trino-connector-473-478` (Error Prone / JaCoCo disabled for JDK 24, JUnit aligned to Trino's 6.0.0 BOM, jjwt api+impl only).
   - **`MockOAuthTokenServer`** (+ `TestMockOAuthTokenServer`) — a minimal RS256 client-credentials OAuth2 token endpoint bound to `127.0.0.1`, used by the IRC dynamic config provider's service identity. Covered by a unit test asserting a valid signed JWT is returned.
   - **`TrinoIcebergRestAuthorizationITBase` / `TrinoIcebergRestAuthorizationIT` / `TrinoIcebergRestSmokeIT`** — boot the full Gravitino server in deploy mode with the `iceberg-rest` aux service + authorization + OAuth authenticator, and drive an in-process Trino query runner to assert privilege grant/deny.
   
   ### Why are the changes needed?
   
   The existing `IcebergAuthorizationIT` only covers the Spark path. Trino accesses the IRC over a different authentication path (OAuth2 bearer only, no Gravitino Basic auth), which was previously untested. This adds end-to-end coverage that Gravitino authorization is enforced for Trino IRC clients.
   
   Fix: #11501
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. Test-only changes; no new APIs or property keys.
   
   ### How was this patch tested?
   
   This change *is* an integration test. Run with the built distribution in deploy mode:
   
   ```
   ./gradlew compileDistribution
   ./gradlew :iceberg:iceberg-rest-trino-it:test -PskipDockerTests=false -DtestMode=deploy
   ```
   
   `MockOAuthTokenServer` is additionally covered by `TestMockOAuthTokenServer`.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11501] test(iceberg-rest): Add Trino IT for Iceberg REST authorization in auxMode [gravitino]

Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 merged PR #11502:
URL: https://github.com/apache/gravitino/pull/11502


-- 
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-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11501] test(iceberg-rest): Add Trino IT for Iceberg REST authorization in auxMode [gravitino]

Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 commented on code in PR #11502:
URL: https://github.com/apache/gravitino/pull/11502#discussion_r3386227953


##########
iceberg/iceberg-rest-trino-it/src/test/java/org/apache/gravitino/iceberg/integration/test/trino/TrinoIcebergRESTAuthorizationIT.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.gravitino.iceberg.integration.test.trino;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import com.google.common.collect.ImmutableList;
+import java.util.HashMap;
+import org.apache.gravitino.authorization.Privileges;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.authorization.SecurableObjects;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+@Tag("gravitino-docker-test")
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+public class TrinoIcebergRESTAuthorizationIT extends TrinoIcebergRESTAuthorizationITBase {
+
+  private static final String ROLE = "trino_role";
+
+  @BeforeAll
+  public void setupTrino() throws Exception {
+    catalogAsSuper.asSchemas().createSchema("db1", "", new HashMap<>());
+    startTrino();
+    sql(SUPER_CATALOG, "CREATE TABLE db1.shared (id integer)");
+    sql(SUPER_CATALOG, "INSERT INTO db1.shared VALUES (1)");
+  }
+
+  @Test
+  @Order(1)
+  public void testNormalUserDeniedWithoutPrivileges() {
+    assertThrows(RuntimeException.class, () -> sql(NORMAL_CATALOG, "SELECT * FROM db1.shared"));

Review Comment:
   Can you check the specific error message instead of throwing a RuntimeException?



##########
iceberg/iceberg-rest-trino-it/build.gradle.kts:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  id("java")
+}
+
+configurations.configureEach {
+  resolutionStrategy.force(
+    "org.testcontainers:testcontainers:1.21.4",
+    "com.github.docker-java:docker-java-api:3.4.2",
+    "com.github.docker-java:docker-java-transport:3.4.2",
+    "com.github.docker-java:docker-java-transport-zerodep:3.4.2"
+  )
+  exclude(group = "io.jsonwebtoken", module = "jjwt-gson")
+  exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
+}
+
+// Test against the highest supported Trino version.
+val minTrinoVersion = 473
+val maxTrinoVersion = 478
+val trinoVersion = providers.gradleProperty("trinoVersion")
+  .map { it.trim().toInt() }
+  .orElse(maxTrinoVersion)
+  .get()
+
+check(trinoVersion in minTrinoVersion..maxTrinoVersion) {
+  "Module ${project.path} supports Trino versions $minTrinoVersion-$maxTrinoVersion, " +
+    "but trinoVersion=$trinoVersion was specified."
+}
+
+java {
+  toolchain.languageVersion.set(JavaLanguageVersion.of(24))
+}
+
+dependencies {
+  testImplementation(project(":api"))
+  testImplementation(project(":catalogs:catalog-common"))
+  testImplementation(project(":common"))
+  testImplementation(project(":clients:client-java"))
+  testImplementation(project(":core"))
+  testImplementation(project(":server-common"))
+
+  testImplementation("io.trino:trino-iceberg:$trinoVersion")
+  testImplementation("io.trino:trino-hdfs:$trinoVersion")
+  testImplementation("io.trino:trino-testing:$trinoVersion")
+  testImplementation("io.trino:trino-main:$trinoVersion")
+
+  testImplementation(project(":integration-test-common", "testArtifacts"))
+
+  testImplementation(libs.awaitility)
+  testImplementation(libs.postgresql.driver)
+  testImplementation(libs.testcontainers)
+  testImplementation(libs.testcontainers.postgresql)
+
+  // jjwt is resolved to 0.13.x on this module's test classpath (Trino forces it up). Only pull
+  // api + impl; the JSON serializer comes from jjwt-jackson:0.13.x which Trino already provides.
+  // Do NOT pull jjwt-gson:0.11.x (the bundle's default) — its stale 0.11.x serializer service is
+  // incompatible with the 0.13.x runtime and makes signWith().compact() fail.
+  testImplementation(libs.jwt.api)
+  testRuntimeOnly(libs.jwt.impl)
+  testRuntimeOnly("io.jsonwebtoken:jjwt-jackson:0.13.0")

Review Comment:
   Should this be placed in the libs directory?



##########
iceberg/iceberg-rest-trino-it/build.gradle.kts:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  id("java")
+}
+
+configurations.configureEach {
+  resolutionStrategy.force(
+    "org.testcontainers:testcontainers:1.21.4",
+    "com.github.docker-java:docker-java-api:3.4.2",
+    "com.github.docker-java:docker-java-transport:3.4.2",
+    "com.github.docker-java:docker-java-transport-zerodep:3.4.2"
+  )
+  exclude(group = "io.jsonwebtoken", module = "jjwt-gson")
+  exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
+}
+
+// Test against the highest supported Trino version.
+val minTrinoVersion = 473
+val maxTrinoVersion = 478

Review Comment:
   Do we need to support multiple versions here?



##########
iceberg/iceberg-rest-trino-it/build.gradle.kts:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  id("java")
+}
+
+configurations.configureEach {
+  resolutionStrategy.force(
+    "org.testcontainers:testcontainers:1.21.4",
+    "com.github.docker-java:docker-java-api:3.4.2",
+    "com.github.docker-java:docker-java-transport:3.4.2",
+    "com.github.docker-java:docker-java-transport-zerodep:3.4.2"
+  )
+  exclude(group = "io.jsonwebtoken", module = "jjwt-gson")
+  exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
+}
+
+// Test against the highest supported Trino version.
+val minTrinoVersion = 473
+val maxTrinoVersion = 478
+val trinoVersion = providers.gradleProperty("trinoVersion")
+  .map { it.trim().toInt() }
+  .orElse(maxTrinoVersion)
+  .get()
+
+check(trinoVersion in minTrinoVersion..maxTrinoVersion) {
+  "Module ${project.path} supports Trino versions $minTrinoVersion-$maxTrinoVersion, " +
+    "but trinoVersion=$trinoVersion was specified."
+}
+
+java {
+  toolchain.languageVersion.set(JavaLanguageVersion.of(24))
+}
+
+dependencies {
+  testImplementation(project(":api"))
+  testImplementation(project(":catalogs:catalog-common"))
+  testImplementation(project(":common"))
+  testImplementation(project(":clients:client-java"))
+  testImplementation(project(":core"))
+  testImplementation(project(":server-common"))

Review Comment:
   Some dependencies may not be used.



##########
iceberg/iceberg-rest-trino-it/src/test/java/org/apache/gravitino/iceberg/integration/test/trino/TrinoIcebergRESTAuthorizationITBase.java:
##########
@@ -0,0 +1,249 @@
+/*
+ * 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.gravitino.iceberg.integration.test.trino;
+
+import static io.trino.testing.TestingSession.testSessionBuilder;
+
+import com.google.common.collect.ImmutableMap;
+import io.jsonwebtoken.Jwts;
+import io.trino.plugin.iceberg.IcebergPlugin;
+import io.trino.testing.DistributedQueryRunner;
+import io.trino.testing.MaterializedResult;
+import io.trino.testing.QueryRunner;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.security.KeyPair;
+import java.util.Base64;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
+import org.apache.gravitino.client.GravitinoMetalake;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.integration.test.util.ITUtils;
+import org.apache.gravitino.integration.test.util.OAuthMockDataProvider;
+import org.apache.gravitino.integration.test.util.TestDatabaseName;
+import org.apache.gravitino.server.authentication.OAuthConfig;
+import org.apache.gravitino.server.authorization.jcasbin.JcasbinAuthorizer;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Boots a deploy-mode Gravitino server with the Iceberg REST auxiliary service, OAuth
+ * authentication, and authorization enabled.
+ */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public abstract class TrinoIcebergRESTAuthorizationITBase extends BaseIT {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(TrinoIcebergRESTAuthorizationITBase.class);
+  private static final String GRAVITINO_ICEBERG_REST_PREFIX = "gravitino.iceberg-rest.";
+
+  protected static final String METALAKE_NAME = "test_metalake";
+  protected static final String CATALOG_NAME = "iceberg";
+  protected static final String SERVICE_AUDIENCE = "gravitino-irc";
+  protected static final String SUPER_USER = "super";
+  protected static final String NORMAL_USER = "normal";
+  protected static final String SUPER_CATALOG = "iceberg_super";
+  protected static final String NORMAL_CATALOG = "iceberg_normal";
+
+  protected final KeyPair keyPair = MockOAuthTokenServer.newRsaKeyPair();
+  protected MockOAuthTokenServer tokenServer;
+  protected String warehouseDir;
+  protected GravitinoMetalake metalakeAsSuper;
+  protected Catalog catalogAsSuper;
+  protected QueryRunner queryRunner;
+
+  /**
+   * Mints a signed bearer token for a test user.
+   *
+   * @param user token subject
+   * @return an RS256-signed JWT
+   */
+  @SuppressWarnings("JavaUtilDate")
+  protected String mintToken(String user) {
+    return Jwts.builder()
+        .subject(user)
+        .audience()
+        .add(SERVICE_AUDIENCE)
+        .and()
+        .expiration(new Date(System.currentTimeMillis() + 60 * 60 * 1000))
+        .signWith(keyPair.getPrivate(), Jwts.SIG.RS256)
+        .compact();
+  }
+
+  @BeforeAll
+  @Override
+  public void startIntegrationTest() throws Exception {
+    // This IT boots the Gravitino server with the Iceberg REST auxiliary service and drives it
+    // through Trino's native REST connector, which only works against the packaged distribution in
+    // deploy mode. The Java 24 / Trino module does not carry the server on its classpath, so the
+    // embedded path would fail with NoClassDefFoundError; skip it when not running in deploy mode.
+    Assumptions.assumeFalse(
+        ITUtils.isEmbedded(), "Trino Iceberg REST authorization IT only runs in deploy mode");
+    containerSuite.startPostgreSQLContainer(TestDatabaseName.PG_ICEBERG_AUTHZ_IT);
+    tokenServer = new MockOAuthTokenServer(keyPair, SERVICE_AUDIENCE, SUPER_USER);
+    tokenServer.start();
+    warehouseDir = Files.createTempDirectory("trino-irc-warehouse").toString();
+
+    String publicKey =
+        new String(
+            Base64.getEncoder().encode(keyPair.getPublic().getEncoded()), StandardCharsets.UTF_8);
+
+    customConfigs.putAll(
+        ImmutableMap.of(
+            Configs.AUTHENTICATORS.getKey(),
+            "oauth",
+            OAuthConfig.SERVICE_AUDIENCE.getKey(),
+            SERVICE_AUDIENCE,
+            OAuthConfig.DEFAULT_SIGN_KEY.getKey(),
+            publicKey,
+            OAuthConfig.ALLOW_SKEW_SECONDS.getKey(),
+            "30",
+            OAuthConfig.DEFAULT_SERVER_URI.getKey(),
+            tokenServer.serverUri(),
+            OAuthConfig.DEFAULT_TOKEN_PATH.getKey(),
+            tokenServer.tokenPath()));
+    customConfigs.putAll(
+        ImmutableMap.of(
+            "gravitino.authorization.serviceAdmins",
+            SUPER_USER,
+            Configs.ENABLE_AUTHORIZATION.getKey(),
+            "true",
+            Configs.AUTHORIZATION_IMPL.getKey(),
+            JcasbinAuthorizer.class.getCanonicalName(),
+            Configs.CACHE_ENABLED.getKey(),
+            "false"));
+
+    ignoreIcebergAuxRestService = false;
+    Map<String, String> ircConfigs = new HashMap<>();
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.ICEBERG_REST_CATALOG_CONFIG_PROVIDER,
+        IcebergConstants.DYNAMIC_ICEBERG_CATALOG_CONFIG_PROVIDER_NAME);
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_METALAKE, METALAKE_NAME);
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.ICEBERG_REST_DEFAULT_DYNAMIC_CATALOG_NAME,
+        CATALOG_NAME);
+    ircConfigs.put(GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_AUTH_TYPE, "oauth");
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_OAUTH2_SERVER_URI,
+        tokenServer.serverUri());
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_OAUTH2_TOKEN_PATH,
+        tokenServer.tokenPath());
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_OAUTH2_CREDENTIAL,
+        "test-client:test-secret");
+    ircConfigs.put(GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_OAUTH2_SCOPE, "test");
+    customConfigs.putAll(ircConfigs);
+
+    OAuthMockDataProvider.getInstance()
+        .setTokenData(mintToken(SUPER_USER).getBytes(StandardCharsets.UTF_8));
+
+    super.startIntegrationTest();
+    initMetalakeAndCatalog();
+  }
+
+  private void initMetalakeAndCatalog() {
+    metalakeAsSuper = client.createMetalake(METALAKE_NAME, "", new HashMap<>());
+    metalakeAsSuper.addUser(NORMAL_USER);
+    Map<String, String> properties =
+        ImmutableMap.<String, String>builder()
+            .put(IcebergConstants.CATALOG_BACKEND, "jdbc")
+            .put(
+                IcebergConstants.URI,
+                containerSuite
+                    .getPostgreSQLContainer()
+                    .getJdbcUrl(TestDatabaseName.PG_ICEBERG_AUTHZ_IT))
+            .put(IcebergConstants.GRAVITINO_JDBC_DRIVER, "org.postgresql.Driver")
+            .put(
+                IcebergConstants.GRAVITINO_JDBC_USER,
+                containerSuite.getPostgreSQLContainer().getUsername())
+            .put(
+                IcebergConstants.GRAVITINO_JDBC_PASSWORD,
+                containerSuite.getPostgreSQLContainer().getPassword())
+            .put(IcebergConstants.ICEBERG_JDBC_INITIALIZE, "true")
+            .put("gravitino.bypass.jdbc.schema-version", "v1")
+            .put(IcebergConstants.WAREHOUSE, "file://" + warehouseDir)
+            .build();
+    catalogAsSuper =
+        metalakeAsSuper.createCatalog(
+            CATALOG_NAME, Catalog.Type.RELATIONAL, "lakehouse-iceberg", "comment", properties);
+    LOG.info("Created metalake {} and catalog {}", METALAKE_NAME, CATALOG_NAME);
+  }
+
+  /** Starts Trino with one native Iceberg REST catalog for each test identity. */
+  protected void startTrino() throws Exception {
+    queryRunner = DistributedQueryRunner.builder(testSessionBuilder().build()).build();
+    queryRunner.installPlugin(new IcebergPlugin());
+    queryRunner.createCatalog(
+        SUPER_CATALOG, "iceberg", icebergCatalogConfig(mintToken(SUPER_USER)));
+    queryRunner.createCatalog(
+        NORMAL_CATALOG, "iceberg", icebergCatalogConfig(mintToken(NORMAL_USER)));
+  }
+
+  /** Executes SQL through the selected Trino Iceberg REST catalog. */
+  protected MaterializedResult sql(String catalog, String query) {
+    return queryRunner.execute(testSessionBuilder().setCatalog(catalog).build(), query);
+  }
+
+  private Map<String, String> icebergCatalogConfig(String bearerToken) {
+    Map<String, String> config = new HashMap<>();
+    config.put("iceberg.catalog.type", "rest");
+    config.put("iceberg.rest-catalog.uri", getIcebergRestServiceUri());
+    config.put("iceberg.rest-catalog.security", "OAUTH2");
+    config.put("iceberg.rest-catalog.oauth2.token", bearerToken);
+    config.put("fs.hadoop.enabled", "true");
+    return config;
+  }
+
+  @AfterAll
+  @Override
+  public void stopIntegrationTest() throws IOException, InterruptedException {
+    try {
+      if (queryRunner != null) {
+        queryRunner.close();
+      }
+      try {
+        if (client != null) {
+          client.dropMetalake(METALAKE_NAME, true);
+        }
+      } catch (Exception e) {
+        LOG.warn("Failed to drop test metalake", e);
+      }
+    } finally {
+      if (tokenServer != null) {
+        tokenServer.close();
+      }
+      try {
+        super.stopIntegrationTest();
+      } finally {
+        containerSuite.close();

Review Comment:
   Closing ContainerSuite might affect other tests 



##########
iceberg/iceberg-rest-trino-it/build.gradle.kts:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  id("java")
+}
+
+configurations.configureEach {
+  resolutionStrategy.force(
+    "org.testcontainers:testcontainers:1.21.4",
+    "com.github.docker-java:docker-java-api:3.4.2",
+    "com.github.docker-java:docker-java-transport:3.4.2",
+    "com.github.docker-java:docker-java-transport-zerodep:3.4.2"
+  )
+  exclude(group = "io.jsonwebtoken", module = "jjwt-gson")
+  exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
+}
+
+// Test against the highest supported Trino version.
+val minTrinoVersion = 473
+val maxTrinoVersion = 478
+val trinoVersion = providers.gradleProperty("trinoVersion")
+  .map { it.trim().toInt() }
+  .orElse(maxTrinoVersion)
+  .get()
+
+check(trinoVersion in minTrinoVersion..maxTrinoVersion) {
+  "Module ${project.path} supports Trino versions $minTrinoVersion-$maxTrinoVersion, " +
+    "but trinoVersion=$trinoVersion was specified."
+}
+
+java {
+  toolchain.languageVersion.set(JavaLanguageVersion.of(24))
+}
+
+dependencies {
+  testImplementation(project(":api"))
+  testImplementation(project(":catalogs:catalog-common"))
+  testImplementation(project(":common"))
+  testImplementation(project(":clients:client-java"))
+  testImplementation(project(":core"))
+  testImplementation(project(":server-common"))
+
+  testImplementation("io.trino:trino-iceberg:$trinoVersion")
+  testImplementation("io.trino:trino-hdfs:$trinoVersion")
+  testImplementation("io.trino:trino-testing:$trinoVersion")
+  testImplementation("io.trino:trino-main:$trinoVersion")
+
+  testImplementation(project(":integration-test-common", "testArtifacts"))
+
+  testImplementation(libs.awaitility)
+  testImplementation(libs.postgresql.driver)
+  testImplementation(libs.testcontainers)
+  testImplementation(libs.testcontainers.postgresql)
+
+  // jjwt is resolved to 0.13.x on this module's test classpath (Trino forces it up). Only pull
+  // api + impl; the JSON serializer comes from jjwt-jackson:0.13.x which Trino already provides.
+  // Do NOT pull jjwt-gson:0.11.x (the bundle's default) — its stale 0.11.x serializer service is
+  // incompatible with the 0.13.x runtime and makes signWith().compact() fail.
+  testImplementation(libs.jwt.api)
+  testRuntimeOnly(libs.jwt.impl)
+  testRuntimeOnly("io.jsonwebtoken:jjwt-jackson:0.13.0")
+  testImplementation(libs.guava)
+  testImplementation(libs.commons.lang3)
+  testImplementation(libs.slf4j.api)
+  // Trino 478's test stack forces JUnit to 6.0.0; pin the BOM to match so the platform launcher,
+  // engine and commons jars stay on the same version (a mismatch makes Gradle's TagFilter crash
+  // with NoSuchMethodError on CollectionUtils.toUnmodifiableList).
+  testImplementation(platform("org.junit:junit-bom:6.0.0"))
+  testImplementation("org.junit.jupiter:junit-jupiter")
+  testRuntimeOnly("org.junit.platform:junit-platform-launcher")
+}
+
+tasks.withType<JavaCompile>().configureEach {
+  // Error Prone (2.10.0) is incompatible with the JDK 24 toolchain required by this Trino range.
+  options.errorprone.isEnabled.set(false)
+}
+
+tasks.withType<Test>().configureEach {
+  // JaCoCo 0.8.9 cannot instrument classes compiled for the JDK 24 toolchain used here.
+  extensions
+    .findByType(org.gradle.testing.jacoco.plugins.JacocoTaskExtension::class.java)
+    ?.isEnabled = false
+}
+
+tasks.test {
+  useJUnitPlatform()
+  // These ITs require the built distribution (deploy mode) and a server subprocess.
+  val skipITs = providers.gradleProperty("skipITs").map(String::toBoolean).orElse(false)
+  val skipTests = providers.gradleProperty("skipTests").map(String::toBoolean).orElse(false)
+  onlyIf { !skipITs.get() && !skipTests.get() }
+}

Review Comment:
   Skipping here is inconsistent with other modules, which use project.hasProperty("skipITs").



-- 
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-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11501] test(iceberg-rest): Add Trino IT for Iceberg REST authorization in auxMode [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11502:
URL: https://github.com/apache/gravitino/pull/11502#discussion_r3394392327


##########
iceberg/iceberg-rest-trino-it/build.gradle.kts:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  id("java")
+}
+
+configurations.configureEach {
+  resolutionStrategy.force(
+    "org.testcontainers:testcontainers:1.21.4",
+    "com.github.docker-java:docker-java-api:3.4.2",
+    "com.github.docker-java:docker-java-transport:3.4.2",
+    "com.github.docker-java:docker-java-transport-zerodep:3.4.2"
+  )
+  exclude(group = "io.jsonwebtoken", module = "jjwt-gson")
+  exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
+}
+
+// Test against the highest supported Trino version.
+val minTrinoVersion = 473
+val maxTrinoVersion = 478
+val trinoVersion = providers.gradleProperty("trinoVersion")
+  .map { it.trim().toInt() }
+  .orElse(maxTrinoVersion)
+  .get()
+
+check(trinoVersion in minTrinoVersion..maxTrinoVersion) {
+  "Module ${project.path} supports Trino versions $minTrinoVersion-$maxTrinoVersion, " +
+    "but trinoVersion=$trinoVersion was specified."
+}
+
+java {
+  toolchain.languageVersion.set(JavaLanguageVersion.of(24))
+}
+
+dependencies {
+  testImplementation(project(":api"))
+  testImplementation(project(":catalogs:catalog-common"))
+  testImplementation(project(":common"))
+  testImplementation(project(":clients:client-java"))
+  testImplementation(project(":core"))
+  testImplementation(project(":server-common"))
+
+  testImplementation("io.trino:trino-iceberg:$trinoVersion")
+  testImplementation("io.trino:trino-hdfs:$trinoVersion")
+  testImplementation("io.trino:trino-testing:$trinoVersion")
+  testImplementation("io.trino:trino-main:$trinoVersion")
+
+  testImplementation(project(":integration-test-common", "testArtifacts"))
+
+  testImplementation(libs.awaitility)
+  testImplementation(libs.postgresql.driver)
+  testImplementation(libs.testcontainers)
+  testImplementation(libs.testcontainers.postgresql)
+
+  // jjwt is resolved to 0.13.x on this module's test classpath (Trino forces it up). Only pull
+  // api + impl; the JSON serializer comes from jjwt-jackson:0.13.x which Trino already provides.
+  // Do NOT pull jjwt-gson:0.11.x (the bundle's default) — its stale 0.11.x serializer service is
+  // incompatible with the 0.13.x runtime and makes signWith().compact() fail.
+  testImplementation(libs.jwt.api)
+  testRuntimeOnly(libs.jwt.impl)
+  testRuntimeOnly("io.jsonwebtoken:jjwt-jackson:0.13.0")

Review Comment:
   Good catch. It turned out the explicit declaration was redundant: `jjwt-jackson:0.13.0` is already provided transitively by `trino-iceberg`/`trino-main`/`trino-testing` (verified with `dependencyInsight` that it stays on the test runtime classpath). So I removed the line entirely — no hardcoded version and no new catalog entry needed. Separately, the remaining version literals in this module (`testcontainers`, `docker-java`, and the Trino version) are now centrally managed in `gradle/libs.versions.toml`.



##########
iceberg/iceberg-rest-trino-it/src/test/java/org/apache/gravitino/iceberg/integration/test/trino/TrinoIcebergRESTAuthorizationIT.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.gravitino.iceberg.integration.test.trino;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import com.google.common.collect.ImmutableList;
+import java.util.HashMap;
+import org.apache.gravitino.authorization.Privileges;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.authorization.SecurableObjects;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+@Tag("gravitino-docker-test")
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+public class TrinoIcebergRESTAuthorizationIT extends TrinoIcebergRESTAuthorizationITBase {
+
+  private static final String ROLE = "trino_role";
+
+  @BeforeAll
+  public void setupTrino() throws Exception {
+    catalogAsSuper.asSchemas().createSchema("db1", "", new HashMap<>());
+    startTrino();
+    sql(SUPER_CATALOG, "CREATE TABLE db1.shared (id integer)");
+    sql(SUPER_CATALOG, "INSERT INTO db1.shared VALUES (1)");
+  }
+
+  @Test
+  @Order(1)
+  public void testNormalUserDeniedWithoutPrivileges() {
+    assertThrows(RuntimeException.class, () -> sql(NORMAL_CATALOG, "SELECT * FROM db1.shared"));

Review Comment:
   Done. Added `assertAuthorizationDenied`, which walks the exception cause chain and asserts the IRC 403 message `"is not authorized to perform operation"` (produced by `BaseMetadataAuthorizationMethodInterceptor`), applied to both denial tests.



##########
iceberg/iceberg-rest-trino-it/src/test/java/org/apache/gravitino/iceberg/integration/test/trino/TrinoIcebergRESTAuthorizationITBase.java:
##########
@@ -0,0 +1,249 @@
+/*
+ * 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.gravitino.iceberg.integration.test.trino;
+
+import static io.trino.testing.TestingSession.testSessionBuilder;
+
+import com.google.common.collect.ImmutableMap;
+import io.jsonwebtoken.Jwts;
+import io.trino.plugin.iceberg.IcebergPlugin;
+import io.trino.testing.DistributedQueryRunner;
+import io.trino.testing.MaterializedResult;
+import io.trino.testing.QueryRunner;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.security.KeyPair;
+import java.util.Base64;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
+import org.apache.gravitino.client.GravitinoMetalake;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.integration.test.util.ITUtils;
+import org.apache.gravitino.integration.test.util.OAuthMockDataProvider;
+import org.apache.gravitino.integration.test.util.TestDatabaseName;
+import org.apache.gravitino.server.authentication.OAuthConfig;
+import org.apache.gravitino.server.authorization.jcasbin.JcasbinAuthorizer;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Boots a deploy-mode Gravitino server with the Iceberg REST auxiliary service, OAuth
+ * authentication, and authorization enabled.
+ */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public abstract class TrinoIcebergRESTAuthorizationITBase extends BaseIT {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(TrinoIcebergRESTAuthorizationITBase.class);
+  private static final String GRAVITINO_ICEBERG_REST_PREFIX = "gravitino.iceberg-rest.";
+
+  protected static final String METALAKE_NAME = "test_metalake";
+  protected static final String CATALOG_NAME = "iceberg";
+  protected static final String SERVICE_AUDIENCE = "gravitino-irc";
+  protected static final String SUPER_USER = "super";
+  protected static final String NORMAL_USER = "normal";
+  protected static final String SUPER_CATALOG = "iceberg_super";
+  protected static final String NORMAL_CATALOG = "iceberg_normal";
+
+  protected final KeyPair keyPair = MockOAuthTokenServer.newRsaKeyPair();
+  protected MockOAuthTokenServer tokenServer;
+  protected String warehouseDir;
+  protected GravitinoMetalake metalakeAsSuper;
+  protected Catalog catalogAsSuper;
+  protected QueryRunner queryRunner;
+
+  /**
+   * Mints a signed bearer token for a test user.
+   *
+   * @param user token subject
+   * @return an RS256-signed JWT
+   */
+  @SuppressWarnings("JavaUtilDate")
+  protected String mintToken(String user) {
+    return Jwts.builder()
+        .subject(user)
+        .audience()
+        .add(SERVICE_AUDIENCE)
+        .and()
+        .expiration(new Date(System.currentTimeMillis() + 60 * 60 * 1000))
+        .signWith(keyPair.getPrivate(), Jwts.SIG.RS256)
+        .compact();
+  }
+
+  @BeforeAll
+  @Override
+  public void startIntegrationTest() throws Exception {
+    // This IT boots the Gravitino server with the Iceberg REST auxiliary service and drives it
+    // through Trino's native REST connector, which only works against the packaged distribution in
+    // deploy mode. The Java 24 / Trino module does not carry the server on its classpath, so the
+    // embedded path would fail with NoClassDefFoundError; skip it when not running in deploy mode.
+    Assumptions.assumeFalse(
+        ITUtils.isEmbedded(), "Trino Iceberg REST authorization IT only runs in deploy mode");
+    containerSuite.startPostgreSQLContainer(TestDatabaseName.PG_ICEBERG_AUTHZ_IT);
+    tokenServer = new MockOAuthTokenServer(keyPair, SERVICE_AUDIENCE, SUPER_USER);
+    tokenServer.start();
+    warehouseDir = Files.createTempDirectory("trino-irc-warehouse").toString();
+
+    String publicKey =
+        new String(
+            Base64.getEncoder().encode(keyPair.getPublic().getEncoded()), StandardCharsets.UTF_8);
+
+    customConfigs.putAll(
+        ImmutableMap.of(
+            Configs.AUTHENTICATORS.getKey(),
+            "oauth",
+            OAuthConfig.SERVICE_AUDIENCE.getKey(),
+            SERVICE_AUDIENCE,
+            OAuthConfig.DEFAULT_SIGN_KEY.getKey(),
+            publicKey,
+            OAuthConfig.ALLOW_SKEW_SECONDS.getKey(),
+            "30",
+            OAuthConfig.DEFAULT_SERVER_URI.getKey(),
+            tokenServer.serverUri(),
+            OAuthConfig.DEFAULT_TOKEN_PATH.getKey(),
+            tokenServer.tokenPath()));
+    customConfigs.putAll(
+        ImmutableMap.of(
+            "gravitino.authorization.serviceAdmins",
+            SUPER_USER,
+            Configs.ENABLE_AUTHORIZATION.getKey(),
+            "true",
+            Configs.AUTHORIZATION_IMPL.getKey(),
+            JcasbinAuthorizer.class.getCanonicalName(),
+            Configs.CACHE_ENABLED.getKey(),
+            "false"));
+
+    ignoreIcebergAuxRestService = false;
+    Map<String, String> ircConfigs = new HashMap<>();
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.ICEBERG_REST_CATALOG_CONFIG_PROVIDER,
+        IcebergConstants.DYNAMIC_ICEBERG_CATALOG_CONFIG_PROVIDER_NAME);
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_METALAKE, METALAKE_NAME);
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.ICEBERG_REST_DEFAULT_DYNAMIC_CATALOG_NAME,
+        CATALOG_NAME);
+    ircConfigs.put(GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_AUTH_TYPE, "oauth");
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_OAUTH2_SERVER_URI,
+        tokenServer.serverUri());
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_OAUTH2_TOKEN_PATH,
+        tokenServer.tokenPath());
+    ircConfigs.put(
+        GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_OAUTH2_CREDENTIAL,
+        "test-client:test-secret");
+    ircConfigs.put(GRAVITINO_ICEBERG_REST_PREFIX + IcebergConstants.GRAVITINO_OAUTH2_SCOPE, "test");
+    customConfigs.putAll(ircConfigs);
+
+    OAuthMockDataProvider.getInstance()
+        .setTokenData(mintToken(SUPER_USER).getBytes(StandardCharsets.UTF_8));
+
+    super.startIntegrationTest();
+    initMetalakeAndCatalog();
+  }
+
+  private void initMetalakeAndCatalog() {
+    metalakeAsSuper = client.createMetalake(METALAKE_NAME, "", new HashMap<>());
+    metalakeAsSuper.addUser(NORMAL_USER);
+    Map<String, String> properties =
+        ImmutableMap.<String, String>builder()
+            .put(IcebergConstants.CATALOG_BACKEND, "jdbc")
+            .put(
+                IcebergConstants.URI,
+                containerSuite
+                    .getPostgreSQLContainer()
+                    .getJdbcUrl(TestDatabaseName.PG_ICEBERG_AUTHZ_IT))
+            .put(IcebergConstants.GRAVITINO_JDBC_DRIVER, "org.postgresql.Driver")
+            .put(
+                IcebergConstants.GRAVITINO_JDBC_USER,
+                containerSuite.getPostgreSQLContainer().getUsername())
+            .put(
+                IcebergConstants.GRAVITINO_JDBC_PASSWORD,
+                containerSuite.getPostgreSQLContainer().getPassword())
+            .put(IcebergConstants.ICEBERG_JDBC_INITIALIZE, "true")
+            .put("gravitino.bypass.jdbc.schema-version", "v1")
+            .put(IcebergConstants.WAREHOUSE, "file://" + warehouseDir)
+            .build();
+    catalogAsSuper =
+        metalakeAsSuper.createCatalog(
+            CATALOG_NAME, Catalog.Type.RELATIONAL, "lakehouse-iceberg", "comment", properties);
+    LOG.info("Created metalake {} and catalog {}", METALAKE_NAME, CATALOG_NAME);
+  }
+
+  /** Starts Trino with one native Iceberg REST catalog for each test identity. */
+  protected void startTrino() throws Exception {
+    queryRunner = DistributedQueryRunner.builder(testSessionBuilder().build()).build();
+    queryRunner.installPlugin(new IcebergPlugin());
+    queryRunner.createCatalog(
+        SUPER_CATALOG, "iceberg", icebergCatalogConfig(mintToken(SUPER_USER)));
+    queryRunner.createCatalog(
+        NORMAL_CATALOG, "iceberg", icebergCatalogConfig(mintToken(NORMAL_USER)));
+  }
+
+  /** Executes SQL through the selected Trino Iceberg REST catalog. */
+  protected MaterializedResult sql(String catalog, String query) {
+    return queryRunner.execute(testSessionBuilder().setCatalog(catalog).build(), query);
+  }
+
+  private Map<String, String> icebergCatalogConfig(String bearerToken) {
+    Map<String, String> config = new HashMap<>();
+    config.put("iceberg.catalog.type", "rest");
+    config.put("iceberg.rest-catalog.uri", getIcebergRestServiceUri());
+    config.put("iceberg.rest-catalog.security", "OAUTH2");
+    config.put("iceberg.rest-catalog.oauth2.token", bearerToken);
+    config.put("fs.hadoop.enabled", "true");
+    return config;
+  }
+
+  @AfterAll
+  @Override
+  public void stopIntegrationTest() throws IOException, InterruptedException {
+    try {
+      if (queryRunner != null) {
+        queryRunner.close();
+      }
+      try {
+        if (client != null) {
+          client.dropMetalake(METALAKE_NAME, true);
+        }
+      } catch (Exception e) {
+        LOG.warn("Failed to drop test metalake", e);
+      }
+    } finally {
+      if (tokenServer != null) {
+        tokenServer.close();
+      }
+      try {
+        super.stopIntegrationTest();
+      } finally {
+        containerSuite.close();

Review Comment:
   Agreed. Removed `containerSuite.close()` from teardown — it is a process-wide singleton whose PostgreSQL container may be reused by other tests in the same JVM. This matches the Spark analog `IcebergAuthorizationIT`, which does not close it either.



##########
iceberg/iceberg-rest-trino-it/build.gradle.kts:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  id("java")
+}
+
+configurations.configureEach {
+  resolutionStrategy.force(
+    "org.testcontainers:testcontainers:1.21.4",
+    "com.github.docker-java:docker-java-api:3.4.2",
+    "com.github.docker-java:docker-java-transport:3.4.2",
+    "com.github.docker-java:docker-java-transport-zerodep:3.4.2"
+  )
+  exclude(group = "io.jsonwebtoken", module = "jjwt-gson")
+  exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
+}
+
+// Test against the highest supported Trino version.
+val minTrinoVersion = 473
+val maxTrinoVersion = 478

Review Comment:
   No — this is a test-only module that boots an in-process Trino query runner, so it only needs a single version. Removed the min/max range + `-PtrinoVersion` machinery and pinned the version, now sourced from the catalog (`libs.versions.trino-iceberg-it`).



##########
iceberg/iceberg-rest-trino-it/build.gradle.kts:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  id("java")
+}
+
+configurations.configureEach {
+  resolutionStrategy.force(
+    "org.testcontainers:testcontainers:1.21.4",
+    "com.github.docker-java:docker-java-api:3.4.2",
+    "com.github.docker-java:docker-java-transport:3.4.2",
+    "com.github.docker-java:docker-java-transport-zerodep:3.4.2"
+  )
+  exclude(group = "io.jsonwebtoken", module = "jjwt-gson")
+  exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
+}
+
+// Test against the highest supported Trino version.
+val minTrinoVersion = 473
+val maxTrinoVersion = 478
+val trinoVersion = providers.gradleProperty("trinoVersion")
+  .map { it.trim().toInt() }
+  .orElse(maxTrinoVersion)
+  .get()
+
+check(trinoVersion in minTrinoVersion..maxTrinoVersion) {
+  "Module ${project.path} supports Trino versions $minTrinoVersion-$maxTrinoVersion, " +
+    "but trinoVersion=$trinoVersion was specified."
+}
+
+java {
+  toolchain.languageVersion.set(JavaLanguageVersion.of(24))
+}
+
+dependencies {
+  testImplementation(project(":api"))
+  testImplementation(project(":catalogs:catalog-common"))
+  testImplementation(project(":common"))
+  testImplementation(project(":clients:client-java"))
+  testImplementation(project(":core"))
+  testImplementation(project(":server-common"))

Review Comment:
   Removed `awaitility` and `commons-lang3` (no references). I also checked `:common`, but it is required at compile time (`ConfigEntry`/`MetalakeDTO` show up in the signatures of `Configs`/`createMetalake`), so it is kept.



##########
iceberg/iceberg-rest-trino-it/build.gradle.kts:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  id("java")
+}
+
+configurations.configureEach {
+  resolutionStrategy.force(
+    "org.testcontainers:testcontainers:1.21.4",
+    "com.github.docker-java:docker-java-api:3.4.2",
+    "com.github.docker-java:docker-java-transport:3.4.2",
+    "com.github.docker-java:docker-java-transport-zerodep:3.4.2"
+  )
+  exclude(group = "io.jsonwebtoken", module = "jjwt-gson")
+  exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
+}
+
+// Test against the highest supported Trino version.
+val minTrinoVersion = 473
+val maxTrinoVersion = 478
+val trinoVersion = providers.gradleProperty("trinoVersion")
+  .map { it.trim().toInt() }
+  .orElse(maxTrinoVersion)
+  .get()
+
+check(trinoVersion in minTrinoVersion..maxTrinoVersion) {
+  "Module ${project.path} supports Trino versions $minTrinoVersion-$maxTrinoVersion, " +
+    "but trinoVersion=$trinoVersion was specified."
+}
+
+java {
+  toolchain.languageVersion.set(JavaLanguageVersion.of(24))
+}
+
+dependencies {
+  testImplementation(project(":api"))
+  testImplementation(project(":catalogs:catalog-common"))
+  testImplementation(project(":common"))
+  testImplementation(project(":clients:client-java"))
+  testImplementation(project(":core"))
+  testImplementation(project(":server-common"))
+
+  testImplementation("io.trino:trino-iceberg:$trinoVersion")
+  testImplementation("io.trino:trino-hdfs:$trinoVersion")
+  testImplementation("io.trino:trino-testing:$trinoVersion")
+  testImplementation("io.trino:trino-main:$trinoVersion")
+
+  testImplementation(project(":integration-test-common", "testArtifacts"))
+
+  testImplementation(libs.awaitility)
+  testImplementation(libs.postgresql.driver)
+  testImplementation(libs.testcontainers)
+  testImplementation(libs.testcontainers.postgresql)
+
+  // jjwt is resolved to 0.13.x on this module's test classpath (Trino forces it up). Only pull
+  // api + impl; the JSON serializer comes from jjwt-jackson:0.13.x which Trino already provides.
+  // Do NOT pull jjwt-gson:0.11.x (the bundle's default) — its stale 0.11.x serializer service is
+  // incompatible with the 0.13.x runtime and makes signWith().compact() fail.
+  testImplementation(libs.jwt.api)
+  testRuntimeOnly(libs.jwt.impl)
+  testRuntimeOnly("io.jsonwebtoken:jjwt-jackson:0.13.0")
+  testImplementation(libs.guava)
+  testImplementation(libs.commons.lang3)
+  testImplementation(libs.slf4j.api)
+  // Trino 478's test stack forces JUnit to 6.0.0; pin the BOM to match so the platform launcher,
+  // engine and commons jars stay on the same version (a mismatch makes Gradle's TagFilter crash
+  // with NoSuchMethodError on CollectionUtils.toUnmodifiableList).
+  testImplementation(platform("org.junit:junit-bom:6.0.0"))
+  testImplementation("org.junit.jupiter:junit-jupiter")
+  testRuntimeOnly("org.junit.platform:junit-platform-launcher")
+}
+
+tasks.withType<JavaCompile>().configureEach {
+  // Error Prone (2.10.0) is incompatible with the JDK 24 toolchain required by this Trino range.
+  options.errorprone.isEnabled.set(false)
+}
+
+tasks.withType<Test>().configureEach {
+  // JaCoCo 0.8.9 cannot instrument classes compiled for the JDK 24 toolchain used here.
+  extensions
+    .findByType(org.gradle.testing.jacoco.plugins.JacocoTaskExtension::class.java)
+    ?.isEnabled = false
+}
+
+tasks.test {
+  useJUnitPlatform()
+  // These ITs require the built distribution (deploy mode) and a server subprocess.
+  val skipITs = providers.gradleProperty("skipITs").map(String::toBoolean).orElse(false)
+  val skipTests = providers.gradleProperty("skipTests").map(String::toBoolean).orElse(false)
+  onlyIf { !skipITs.get() && !skipTests.get() }
+}

Review Comment:
   Done. Switched to `project.hasProperty("skipITs")` + `exclude("**/integration/test/**")`, consistent with `iceberg-rest-server`. This also fixes a latent issue: the old `onlyIf` skipped these ITs under `-PskipTests`, when they should still run.



-- 
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-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11501] test(iceberg-rest): Add Trino IT for Iceberg REST authorization in auxMode [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11502:
URL: https://github.com/apache/gravitino/pull/11502#discussion_r3394723379


##########
iceberg/iceberg-rest-trino-it/build.gradle.kts:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  id("java")
+}
+
+configurations.configureEach {
+  resolutionStrategy.force(
+    "org.testcontainers:testcontainers:1.21.4",
+    "com.github.docker-java:docker-java-api:3.4.2",
+    "com.github.docker-java:docker-java-transport:3.4.2",
+    "com.github.docker-java:docker-java-transport-zerodep:3.4.2"
+  )
+  exclude(group = "io.jsonwebtoken", module = "jjwt-gson")
+  exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
+}
+
+// Test against the highest supported Trino version.
+val minTrinoVersion = 473
+val maxTrinoVersion = 478
+val trinoVersion = providers.gradleProperty("trinoVersion")
+  .map { it.trim().toInt() }
+  .orElse(maxTrinoVersion)
+  .get()
+
+check(trinoVersion in minTrinoVersion..maxTrinoVersion) {
+  "Module ${project.path} supports Trino versions $minTrinoVersion-$maxTrinoVersion, " +
+    "but trinoVersion=$trinoVersion was specified."
+}
+
+java {
+  toolchain.languageVersion.set(JavaLanguageVersion.of(24))
+}
+
+dependencies {
+  testImplementation(project(":api"))
+  testImplementation(project(":catalogs:catalog-common"))
+  testImplementation(project(":common"))
+  testImplementation(project(":clients:client-java"))
+  testImplementation(project(":core"))
+  testImplementation(project(":server-common"))

Review Comment:
   Correction: CI showed `awaitility` and `commons-lang3` are actually **not** unused — the inherited `BaseIT`/`ITUtils` harness (from the `integration-test-common` testArtifacts dep) uses them at runtime, and `testArtifacts` does not carry transitive runtime deps, so removing them failed the ITs with `NoClassDefFoundError: org/awaitility/Awaitility`. I restored both (as `testRuntimeOnly`, since this module's own sources do not reference them) in 63ac498. `:common` remains required at compile time. Net result: the declared dependencies are all needed.



-- 
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-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11501] test(iceberg-rest): Add Trino IT for Iceberg REST authorization in auxMode [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11502:
URL: https://github.com/apache/gravitino/pull/11502#issuecomment-4656292846

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|67.04%|:green_circle:|
   |:-|:-|:-:|
   |Files changed|No Java source files changed|-|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|46.8%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|3.66%|:red_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|10.42%|:red_circle:|
   |catalog-fileset|80.35%|:green_circle:|
   |catalog-glue|67.41%|:green_circle:|
   |catalog-hive|79.35%|:green_circle:|
   |catalog-jdbc-clickhouse|80.02%|:green_circle:|
   |catalog-jdbc-common|45.31%|:green_circle:|
   |catalog-jdbc-doris|80.28%|:green_circle:|
   |catalog-jdbc-hologres|54.03%|:green_circle:|
   |catalog-jdbc-mysql|79.23%|:green_circle:|
   |catalog-jdbc-oceanbase|78.38%|:green_circle:|
   |catalog-jdbc-postgresql|82.29%|:green_circle:|
   |catalog-jdbc-starrocks|78.51%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|58.53%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.94%|:green_circle:|
   |catalog-lakehouse-paimon|79.29%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.51%|:green_circle:|
   |client-java|77.91%|:green_circle:|
   |common|50.17%|:green_circle:|
   |core|82.51%|:green_circle:|
   |filesystem-hadoop3|76.97%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|46.3%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-common|10.39%|:red_circle:|
   |hive-metastore-common|53.9%|:green_circle:|
   |iceberg-common|57.41%|:green_circle:|
   |iceberg-rest-server|73.88%|:green_circle:|
   |idp-basic|86.07%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|66.17%|:green_circle:|
   |lance-common|20.81%|:red_circle:|
   |lance-rest-server|60.54%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|82.95%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|85.73%|:green_circle:|
   |server-common|73.28%|:green_circle:|
   |spark|28.57%|:red_circle:|
   |spark-common|41.01%|:green_circle:|
   |trino-connector|39.97%|:red_circle:|
   


-- 
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-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11501] test(iceberg-rest): Add Trino IT for Iceberg REST authorization in auxMode [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11502:
URL: https://github.com/apache/gravitino/pull/11502#discussion_r3394288369


##########
iceberg/iceberg-rest-trino-it/build.gradle.kts:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  id("java")
+}
+
+configurations.configureEach {
+  resolutionStrategy.force(
+    "org.testcontainers:testcontainers:1.21.4",
+    "com.github.docker-java:docker-java-api:3.4.2",
+    "com.github.docker-java:docker-java-transport:3.4.2",
+    "com.github.docker-java:docker-java-transport-zerodep:3.4.2"
+  )
+  exclude(group = "io.jsonwebtoken", module = "jjwt-gson")
+  exclude(group = "org.apache.logging.log4j", module = "log4j-to-slf4j")
+}
+
+// Test against the highest supported Trino version.
+val minTrinoVersion = 473
+val maxTrinoVersion = 478
+val trinoVersion = providers.gradleProperty("trinoVersion")
+  .map { it.trim().toInt() }
+  .orElse(maxTrinoVersion)
+  .get()
+
+check(trinoVersion in minTrinoVersion..maxTrinoVersion) {
+  "Module ${project.path} supports Trino versions $minTrinoVersion-$maxTrinoVersion, " +
+    "but trinoVersion=$trinoVersion was specified."
+}
+
+java {
+  toolchain.languageVersion.set(JavaLanguageVersion.of(24))
+}
+
+dependencies {
+  testImplementation(project(":api"))
+  testImplementation(project(":catalogs:catalog-common"))
+  testImplementation(project(":common"))
+  testImplementation(project(":clients:client-java"))
+  testImplementation(project(":core"))
+  testImplementation(project(":server-common"))

Review Comment:
   Some dependencies are required for BaseIT.



-- 
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-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org