You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "hdygxsj (via GitHub)" <gi...@apache.org> on 2025/08/14 13:59:19 UTC
[PR] [#6791] improvement(authz): Add IT for metadata authorization and use spark connector [gravitino]
hdygxsj opened a new pull request, #8100:
URL: https://github.com/apache/gravitino/pull/8100
Add IT for metadata authorization and use spark connector
### What changes were proposed in this pull request?
(Please outline the changes and how this PR fixes the issue.)
### Why are the changes needed?
(Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, describe the bug.)
Fix: #6791
### Does this PR introduce _any_ user-facing change?
None
### How was this patch tested?
org.apache.gravitino.spark.connector.integration.test.authorization.SparkAuthorizationIT35
org.apache.gravitino.spark.connector.integration.test.authorization.SparkAuthorizationIT34
org.apache.gravitino.spark.connector.integration.test.authorization.SparkAuthorizationIT33
--
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] [#6791] improvement(authz): Add IT for metadata authorization and use spark connector [gravitino]
Posted by "hdygxsj (via GitHub)" <gi...@apache.org>.
hdygxsj commented on PR #8100:
URL: https://github.com/apache/gravitino/pull/8100#issuecomment-3230798221
> Could you fix the integration tests?
fixed
--
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] [#6791] improvement(authz): Add IT for metadata authorization and use spark connector [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on PR #8100:
URL: https://github.com/apache/gravitino/pull/8100#issuecomment-3227279692
Could you fix the integration tests?
--
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] [#6791] improvement(authz): Add IT for metadata authorization and use spark connector [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi merged PR #8100:
URL: https://github.com/apache/gravitino/pull/8100
--
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] [#6791] improvement(authz): Add IT for metadata authorization and use spark connector [gravitino]
Posted by "hdygxsj (via GitHub)" <gi...@apache.org>.
hdygxsj commented on code in PR #8100:
URL: https://github.com/apache/gravitino/pull/8100#discussion_r2278526519
##########
spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkAuthorizationIT.java:
##########
@@ -0,0 +1,260 @@
+/*
+ * 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.spark.connector.integration.test.authorization;
+
+import static org.apache.gravitino.integration.test.util.TestDatabaseName.MYSQL_CATALOG_MYSQL_IT;
+import static org.junit.Assert.assertThrows;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.MetadataObjects;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.SupportsSchemas;
+import org.apache.gravitino.auth.AuthConstants;
+import org.apache.gravitino.authorization.Privileges;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.authorization.SecurableObjects;
+import org.apache.gravitino.client.GravitinoMetalake;
+import org.apache.gravitino.exceptions.ForbiddenException;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.integration.test.util.TestDatabaseName;
+import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.TableCatalog;
+import org.apache.gravitino.rel.types.Types;
+import org.apache.gravitino.spark.connector.GravitinoSparkConfig;
+import org.apache.gravitino.spark.connector.jdbc.JdbcPropertiesConstants;
+import org.apache.gravitino.spark.connector.plugin.GravitinoSparkPlugin;
+import org.apache.spark.SparkConf;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.RowFactory;
+import org.apache.spark.sql.SparkSession;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+@Tag("gravitino-docker-test")
+public abstract class SparkAuthorizationIT extends BaseIT {
+
+ private static final String METALAKE = "metalake";
+
+ private static final String ADMIN_USER = "tester";
+
+ private static final String NORMAL_USER = "tester2";
+
+ private static final String JDBC_CATALOG = "jdbcCatalog";
+
+ private static final String JDBC_DATABASE = "jdbcDatabase";
+
+ private static final String ROLE = "role";
+
+ private String gravitinoUri;
+
+ protected String mysqlUrl;
+
+ protected String mysqlUsername;
+
+ protected String mysqlPassword;
+
+ protected String mysqlDriver;
+
+ private SparkSession normalUserSparkSession;
+
+ protected final String TIME_ZONE_UTC = "UTC";
+
+ @BeforeAll
+ @Override
+ public void startIntegrationTest() throws Exception {
+ // Enable authorization
+ customConfigs.putAll(
+ ImmutableMap.of(
+ "SimpleAuthUserName",
+ ADMIN_USER,
+ Configs.ENABLE_AUTHORIZATION.getKey(),
+ "true",
+ Configs.CACHE_ENABLED.getKey(),
+ "false",
+ Configs.AUTHENTICATORS.getKey(),
+ "simple"));
+ putServiceAdmin();
+ initMysqlContainer();
+ super.startIntegrationTest();
+ gravitinoUri = String.format("http://127.0.0.1:%d", getGravitinoServerPort());
+ initTables();
+ initSparkEnv();
+ }
+
+ @AfterAll
+ @Override
+ public void stopIntegrationTest() throws IOException, InterruptedException {
+ containerSuite.close();
+ client.dropMetalake(METALAKE);
+ setEnv("HADOOP_USER_NAME", AuthConstants.ANONYMOUS_USER);
+ normalUserSparkSession.close();
+ super.stopIntegrationTest();
+ }
+
+ private void initMysqlContainer() throws SQLException {
+ containerSuite.startMySQLContainer(TestDatabaseName.MYSQL_CATALOG_MYSQL_IT);
+ mysqlUrl = containerSuite.getMySQLContainer().getJdbcUrl();
+ mysqlUsername = containerSuite.getMySQLContainer().getUsername();
+ mysqlPassword = containerSuite.getMySQLContainer().getPassword();
+ mysqlDriver = containerSuite.getMySQLContainer().getDriverClassName(MYSQL_CATALOG_MYSQL_IT);
+ }
+
+ private void initTables() {
+ client.createMetalake(METALAKE, "", new HashMap<>());
+ GravitinoMetalake gravitinoMetalake = client.loadMetalake(METALAKE);
+ gravitinoMetalake.addUser(NORMAL_USER);
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(JdbcPropertiesConstants.GRAVITINO_JDBC_URL, mysqlUrl);
+ properties.put(JdbcPropertiesConstants.GRAVITINO_JDBC_USER, mysqlUsername);
+ properties.put(JdbcPropertiesConstants.GRAVITINO_JDBC_PASSWORD, mysqlPassword);
+ properties.put(JdbcPropertiesConstants.GRAVITINO_JDBC_DRIVER, mysqlDriver);
+ Catalog catalog =
+ client
+ .loadMetalake(METALAKE)
+ .createCatalog(
+ JDBC_CATALOG, Catalog.Type.RELATIONAL, "jdbc-mysql", "comment", properties);
+ SupportsSchemas schemas = catalog.asSchemas();
+ schemas.createSchema(JDBC_DATABASE, "", new HashMap<>());
+ SecurableObject securableObject =
+ SecurableObjects.ofCatalog(
+ JDBC_CATALOG,
+ ImmutableList.of(
+ Privileges.UseCatalog.allow(),
+ Privileges.UseSchema.allow(),
+ Privileges.SelectTable.allow(),
+ Privileges.CreateTable.allow()));
+ gravitinoMetalake.createRole(ROLE, new HashMap<>(), ImmutableList.of(securableObject));
+ gravitinoMetalake.grantRolesToUser(ImmutableList.of(ROLE), NORMAL_USER);
+ }
+
+ protected void putServiceAdmin() {
+ customConfigs.put(Configs.SERVICE_ADMINS.getKey(), ADMIN_USER);
+ }
+
+ private void initSparkEnv() {
+ SparkConf sparkConf =
+ new SparkConf()
+ .set("spark.plugins", GravitinoSparkPlugin.class.getName())
+ .set(GravitinoSparkConfig.GRAVITINO_URI, gravitinoUri)
+ .set(GravitinoSparkConfig.GRAVITINO_METALAKE, METALAKE)
+ .set("spark.sql.session.timeZone", TIME_ZONE_UTC);
+ setEnv("HADOOP_USER_NAME", NORMAL_USER);
+ normalUserSparkSession =
+ SparkSession.builder()
+ .master("local[1]")
+ .appName("Spark connector integration test")
+ .config(sparkConf)
+ .getOrCreate();
+ }
+
+ @Test
+ public void testTable() {
Review Comment:
fixed
--
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] [#6791] improvement(authz): Add IT for metadata authorization and use spark connector [gravitino]
Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #8100:
URL: https://github.com/apache/gravitino/pull/8100#discussion_r2278171573
##########
spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkAuthorizationIT.java:
##########
@@ -0,0 +1,260 @@
+/*
+ * 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.spark.connector.integration.test.authorization;
+
+import static org.apache.gravitino.integration.test.util.TestDatabaseName.MYSQL_CATALOG_MYSQL_IT;
+import static org.junit.Assert.assertThrows;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.MetadataObjects;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.SupportsSchemas;
+import org.apache.gravitino.auth.AuthConstants;
+import org.apache.gravitino.authorization.Privileges;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.authorization.SecurableObjects;
+import org.apache.gravitino.client.GravitinoMetalake;
+import org.apache.gravitino.exceptions.ForbiddenException;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.integration.test.util.TestDatabaseName;
+import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.TableCatalog;
+import org.apache.gravitino.rel.types.Types;
+import org.apache.gravitino.spark.connector.GravitinoSparkConfig;
+import org.apache.gravitino.spark.connector.jdbc.JdbcPropertiesConstants;
+import org.apache.gravitino.spark.connector.plugin.GravitinoSparkPlugin;
+import org.apache.spark.SparkConf;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.RowFactory;
+import org.apache.spark.sql.SparkSession;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+@Tag("gravitino-docker-test")
+public abstract class SparkAuthorizationIT extends BaseIT {
+
+ private static final String METALAKE = "metalake";
+
+ private static final String ADMIN_USER = "tester";
+
+ private static final String NORMAL_USER = "tester2";
+
+ private static final String JDBC_CATALOG = "jdbcCatalog";
+
+ private static final String JDBC_DATABASE = "jdbcDatabase";
+
+ private static final String ROLE = "role";
+
+ private String gravitinoUri;
+
+ protected String mysqlUrl;
+
+ protected String mysqlUsername;
+
+ protected String mysqlPassword;
+
+ protected String mysqlDriver;
+
+ private SparkSession normalUserSparkSession;
+
+ protected final String TIME_ZONE_UTC = "UTC";
+
+ @BeforeAll
+ @Override
+ public void startIntegrationTest() throws Exception {
+ // Enable authorization
+ customConfigs.putAll(
+ ImmutableMap.of(
+ "SimpleAuthUserName",
+ ADMIN_USER,
+ Configs.ENABLE_AUTHORIZATION.getKey(),
+ "true",
+ Configs.CACHE_ENABLED.getKey(),
+ "false",
+ Configs.AUTHENTICATORS.getKey(),
+ "simple"));
+ putServiceAdmin();
+ initMysqlContainer();
+ super.startIntegrationTest();
+ gravitinoUri = String.format("http://127.0.0.1:%d", getGravitinoServerPort());
+ initTables();
+ initSparkEnv();
+ }
+
+ @AfterAll
+ @Override
+ public void stopIntegrationTest() throws IOException, InterruptedException {
+ containerSuite.close();
+ client.dropMetalake(METALAKE);
+ setEnv("HADOOP_USER_NAME", AuthConstants.ANONYMOUS_USER);
+ normalUserSparkSession.close();
+ super.stopIntegrationTest();
+ }
+
+ private void initMysqlContainer() throws SQLException {
+ containerSuite.startMySQLContainer(TestDatabaseName.MYSQL_CATALOG_MYSQL_IT);
+ mysqlUrl = containerSuite.getMySQLContainer().getJdbcUrl();
+ mysqlUsername = containerSuite.getMySQLContainer().getUsername();
+ mysqlPassword = containerSuite.getMySQLContainer().getPassword();
+ mysqlDriver = containerSuite.getMySQLContainer().getDriverClassName(MYSQL_CATALOG_MYSQL_IT);
+ }
+
+ private void initTables() {
+ client.createMetalake(METALAKE, "", new HashMap<>());
+ GravitinoMetalake gravitinoMetalake = client.loadMetalake(METALAKE);
+ gravitinoMetalake.addUser(NORMAL_USER);
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(JdbcPropertiesConstants.GRAVITINO_JDBC_URL, mysqlUrl);
+ properties.put(JdbcPropertiesConstants.GRAVITINO_JDBC_USER, mysqlUsername);
+ properties.put(JdbcPropertiesConstants.GRAVITINO_JDBC_PASSWORD, mysqlPassword);
+ properties.put(JdbcPropertiesConstants.GRAVITINO_JDBC_DRIVER, mysqlDriver);
+ Catalog catalog =
+ client
+ .loadMetalake(METALAKE)
+ .createCatalog(
+ JDBC_CATALOG, Catalog.Type.RELATIONAL, "jdbc-mysql", "comment", properties);
+ SupportsSchemas schemas = catalog.asSchemas();
+ schemas.createSchema(JDBC_DATABASE, "", new HashMap<>());
+ SecurableObject securableObject =
+ SecurableObjects.ofCatalog(
+ JDBC_CATALOG,
+ ImmutableList.of(
+ Privileges.UseCatalog.allow(),
+ Privileges.UseSchema.allow(),
+ Privileges.SelectTable.allow(),
+ Privileges.CreateTable.allow()));
+ gravitinoMetalake.createRole(ROLE, new HashMap<>(), ImmutableList.of(securableObject));
+ gravitinoMetalake.grantRolesToUser(ImmutableList.of(ROLE), NORMAL_USER);
+ }
+
+ protected void putServiceAdmin() {
+ customConfigs.put(Configs.SERVICE_ADMINS.getKey(), ADMIN_USER);
+ }
+
+ private void initSparkEnv() {
+ SparkConf sparkConf =
+ new SparkConf()
+ .set("spark.plugins", GravitinoSparkPlugin.class.getName())
+ .set(GravitinoSparkConfig.GRAVITINO_URI, gravitinoUri)
+ .set(GravitinoSparkConfig.GRAVITINO_METALAKE, METALAKE)
+ .set("spark.sql.session.timeZone", TIME_ZONE_UTC);
+ setEnv("HADOOP_USER_NAME", NORMAL_USER);
+ normalUserSparkSession =
+ SparkSession.builder()
+ .master("local[1]")
+ .appName("Spark connector integration test")
+ .config(sparkConf)
+ .getOrCreate();
+ }
+
+ @Test
+ public void testTable() {
Review Comment:
Could you split the test to make the test purpose more clear?
--
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