Skip to content

Commit e626e8b

Browse files
authored
make with-grant-option optinal (apache#15854)
1 parent ddddbae commit e626e8b

File tree

10 files changed

+143
-1
lines changed

10 files changed

+143
-1
lines changed

integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppCommonConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ public CommonConfig setEncryptKeyPath(String encryptKeyPath) {
109109
return this;
110110
}
111111

112+
@Override
113+
public CommonConfig setEnableGrantOption(boolean enableGrantOption) {
114+
setProperty("enable_grant_option", String.valueOf(enableGrantOption));
115+
return this;
116+
}
117+
112118
@Override
113119
public CommonConfig setUdfMemoryBudgetInMB(float udfCollectorMemoryBudgetInMB) {
114120
// udf_memory_budget_in_mb

integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppSharedCommonConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ public CommonConfig setEncryptKeyPath(String encryptKeyPath) {
8989
return this;
9090
}
9191

92+
@Override
93+
public CommonConfig setEnableGrantOption(boolean enableGrantOption) {
94+
cnConfig.setEnableGrantOption(enableGrantOption);
95+
dnConfig.setEnableGrantOption(enableGrantOption);
96+
return this;
97+
}
98+
9299
@Override
93100
public CommonConfig setConfigRegionRatisRPCLeaderElectionTimeoutMaxMs(int maxMs) {
94101
cnConfig.setConfigRegionRatisRPCLeaderElectionTimeoutMaxMs(maxMs);

integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteCommonConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public CommonConfig setEncryptKeyPath(String encryptKeyPath) {
6464
return this;
6565
}
6666

67+
@Override
68+
public CommonConfig setEnableGrantOption(boolean enableGrantOption) {
69+
return this;
70+
}
71+
6772
@Override
6873
public CommonConfig setConfigRegionRatisRPCLeaderElectionTimeoutMaxMs(int maxMs) {
6974
return this;

integration-test/src/main/java/org/apache/iotdb/itbase/env/CommonConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public interface CommonConfig {
4040

4141
CommonConfig setEncryptKeyPath(String encryptKeyPath);
4242

43+
CommonConfig setEnableGrantOption(boolean enableGrantOption);
44+
4345
CommonConfig setConfigRegionRatisRPCLeaderElectionTimeoutMaxMs(int maxMs);
4446

4547
CommonConfig setUdfMemoryBudgetInMB(float udfCollectorMemoryBudgetInMB);
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.db.it.auth;
21+
22+
import org.apache.iotdb.it.env.EnvFactory;
23+
import org.apache.iotdb.it.framework.IoTDBTestRunner;
24+
import org.apache.iotdb.itbase.category.ClusterIT;
25+
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
26+
27+
import org.junit.After;
28+
import org.junit.Assert;
29+
import org.junit.Before;
30+
import org.junit.Ignore;
31+
import org.junit.Test;
32+
import org.junit.experimental.categories.Category;
33+
import org.junit.runner.RunWith;
34+
35+
import java.sql.Connection;
36+
import java.sql.SQLException;
37+
import java.sql.Statement;
38+
39+
@Ignore
40+
@RunWith(IoTDBTestRunner.class)
41+
@Category({LocalStandaloneIT.class, ClusterIT.class})
42+
public class IoTDBGrantOptionIT {
43+
@Before
44+
public void setUp() throws Exception {
45+
EnvFactory.getEnv().getConfig().getCommonConfig().setEnableGrantOption(false);
46+
EnvFactory.getEnv().initClusterEnvironment();
47+
}
48+
49+
@After
50+
public void tearDown() throws Exception {
51+
EnvFactory.getEnv().cleanClusterEnvironment();
52+
}
53+
54+
@Test
55+
public void grantTest() throws SQLException {
56+
try (Connection adminCon = EnvFactory.getEnv().getConnection();
57+
Statement adminStmt = adminCon.createStatement()) {
58+
adminStmt.execute("CREATE USER tempuser 'temppw'");
59+
adminStmt.execute("CREATE USER tempuser2 'temppw2'");
60+
// with grant option is disabled.
61+
Assert.assertThrows(
62+
SQLException.class,
63+
() -> adminStmt.execute("GRANT ALL ON root.** TO USER tempuser WITH GRANT OPTION"));
64+
adminStmt.execute("GRANT ALL ON root.** TO USER tempuser");
65+
try (Connection userCon = EnvFactory.getEnv().getConnection("tempuser", "temppw");
66+
Statement userStmt = userCon.createStatement()) {
67+
userStmt.execute("CREATE DATABASE root.a");
68+
userStmt.execute("CREATE TIMESERIES root.a.b WITH DATATYPE=INT32,ENCODING=PLAIN");
69+
userStmt.execute("INSERT INTO root.a(timestamp, b) VALUES (100, 100)");
70+
userStmt.execute("SELECT * from root.a");
71+
// tempuser can not grant privileges to other users
72+
Assert.assertThrows(
73+
SQLException.class, () -> userStmt.execute("GRANT ALL ON root.** TO USER tempuser2"));
74+
// with grant option is disabled
75+
Assert.assertThrows(
76+
SQLException.class,
77+
() -> userStmt.execute("GRANT ALL ON root.** TO USER tempuser2 WITH GRANT OPTION"));
78+
}
79+
}
80+
}
81+
}

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/SystemPropertiesUtils.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ public static void checkSystemProperties() throws IOException {
202202
COMMON_CONFIG.setTimePartitionInterval(timePartitionInterval);
203203
}
204204
}
205+
if (systemProperties.getProperty("enable_grant_option", null) != null) {
206+
boolean enableGrantOption =
207+
Boolean.parseBoolean(systemProperties.getProperty("enable_grant_option"));
208+
if (enableGrantOption != COMMON_CONFIG.getEnableGrantOption()) {
209+
LOGGER.warn(
210+
format, "enable_grant_option", COMMON_CONFIG.getEnableGrantOption(), enableGrantOption);
211+
COMMON_CONFIG.setEnableGrantOption(enableGrantOption);
212+
}
213+
}
205214
}
206215

207216
/**
@@ -273,7 +282,8 @@ public static void storeSystemParameters() throws IOException {
273282
systemProperties.setProperty("schema_engine_mode", COMMON_CONFIG.getSchemaEngineMode());
274283
systemProperties.setProperty(
275284
"tag_attribute_total_size", String.valueOf(COMMON_CONFIG.getTagAttributeTotalSize()));
276-
285+
systemProperties.setProperty(
286+
"enable_grant_option", String.valueOf(COMMON_CONFIG.getEnableGrantOption()));
277287
systemPropertiesHandler.overwrite(systemProperties);
278288
}
279289

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,13 @@ public Statement visitGrantUser(IoTDBSqlParser.GrantUserContext ctx) {
24772477
authorStatement.setUserName(parseIdentifier(ctx.userName.getText()));
24782478
authorStatement.setPrivilegeList(priviParsed);
24792479
authorStatement.setNodeNameList(nodeNameList);
2480+
if (!CommonDescriptor.getInstance().getConfig().getEnableGrantOption()
2481+
&& ctx.grantOpt() != null) {
2482+
throw new SemanticException(
2483+
"Grant Option is disabled, Please check the parameter enable_grant_option.");
2484+
}
24802485
authorStatement.setGrantOpt(ctx.grantOpt() != null);
2486+
24812487
return authorStatement;
24822488
}
24832489

@@ -2498,6 +2504,11 @@ public Statement visitGrantRole(IoTDBSqlParser.GrantRoleContext ctx) {
24982504
authorStatement.setRoleName(parseIdentifier(ctx.roleName.getText()));
24992505
authorStatement.setPrivilegeList(priviParsed);
25002506
authorStatement.setNodeNameList(nodeNameList);
2507+
if (!CommonDescriptor.getInstance().getConfig().getEnableGrantOption()
2508+
&& ctx.grantOpt() != null) {
2509+
throw new SemanticException(
2510+
"Grant Option is disabled, Please check the parameter enable_grant_option.");
2511+
}
25012512
authorStatement.setGrantOpt(ctx.grantOpt() != null);
25022513
return authorStatement;
25032514
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
2323
import org.apache.iotdb.commons.auth.entity.PrivilegeType;
2424
import org.apache.iotdb.commons.cluster.NodeStatus;
25+
import org.apache.iotdb.commons.conf.CommonDescriptor;
2526
import org.apache.iotdb.commons.path.PartialPath;
2627
import org.apache.iotdb.commons.schema.cache.CacheClearOptions;
2728
import org.apache.iotdb.commons.schema.table.InformationSchema;
@@ -1808,6 +1809,11 @@ public Node visitGrantStatement(RelationalSqlParser.GrantStatementContext ctx) {
18081809
String name;
18091810
toUser = ctx.holderType().getText().equalsIgnoreCase("user");
18101811
name = (((Identifier) visit(ctx.holderName)).getValue());
1812+
if (!CommonDescriptor.getInstance().getConfig().getEnableGrantOption()
1813+
&& ctx.grantOpt() != null) {
1814+
throw new SemanticException(
1815+
"Grant Option is disabled, Please check the parameter enable_grant_option.");
1816+
}
18111817
boolean grantOption = ctx.grantOpt() != null;
18121818
boolean toTable;
18131819
Set<PrivilegeType> privileges;

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public class CommonConfig {
6969

7070
private String adminPassword = "root";
7171

72+
private Boolean enableGrantOption = true;
73+
7274
private String oldUserFolder =
7375
IoTDBConstant.DN_DEFAULT_DATA_DIR
7476
+ File.separator
@@ -495,6 +497,14 @@ public String getOldUserFolder() {
495497
return oldUserFolder;
496498
}
497499

500+
public void setEnableGrantOption(Boolean enableGrantOption) {
501+
this.enableGrantOption = enableGrantOption;
502+
}
503+
504+
public Boolean getEnableGrantOption() {
505+
return enableGrantOption;
506+
}
507+
498508
public String getOldRoleFolder() {
499509
return oldRoleFolder;
500510
}

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ public void loadCommonProps(TrimProperties properties) throws IOException {
9090
"iotdb_server_encrypt_decrypt_provider_parameter",
9191
config.getEncryptDecryptProviderParameter()));
9292

93+
config.setEnableGrantOption(
94+
Boolean.parseBoolean(
95+
properties.getProperty("enable_grant_option", String.valueOf("true"))));
96+
9397
String[] tierTTLStr = new String[config.getTierTTLInMs().length];
9498
for (int i = 0; i < tierTTLStr.length; ++i) {
9599
tierTTLStr[i] = String.valueOf(config.getTierTTLInMs()[i]);

0 commit comments

Comments
 (0)