-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[enhance](auth)when assigning permissions, the current user must have…
… corresponding permissions (#32825) When authorizing other users or roles, not only need `grant_priv`, also need the priv want to grant for example : The user executes the following SQL ``` grant select_priv,load_priv on db1.table1 to u1; ``` he need have grant_priv, select_priv and load_priv on db1.table1 ``` grant usage_priv on resource r1 to u1; ``` he need to have grant_priv and usage_priv on u1
- Loading branch information
Showing
9 changed files
with
314 additions
and
113 deletions.
There are no files selected for viewing
198 changes: 96 additions & 102 deletions
198
fe/fe-core/src/main/java/org/apache/doris/analysis/GrantStmt.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// 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 org.junit.Assert; | ||
|
||
suite("test_grant_priv") { | ||
def user1 = 'test_grant_priv_user1' | ||
def user2 = 'test_grant_priv_user2' | ||
def role1 = 'test_grant_priv_role1' | ||
def pwd = '123456' | ||
def dbName = 'test_grant_priv_db' | ||
def tokens = context.config.jdbcUrl.split('/') | ||
def url=tokens[0] + "//" + tokens[2] + "/" + dbName + "?" | ||
|
||
sql """drop user if exists ${user1}""" | ||
sql """drop user if exists ${user2}""" | ||
sql """drop role if exists ${role1}""" | ||
sql """DROP DATABASE IF EXISTS ${dbName}""" | ||
|
||
sql """CREATE DATABASE ${dbName}""" | ||
sql """CREATE ROLE ${role1}""" | ||
sql """CREATE USER '${user1}' IDENTIFIED BY '${pwd}'""" | ||
sql """CREATE USER '${user2}' IDENTIFIED BY '${pwd}'""" | ||
|
||
// test only have select_priv, can not grant to other user | ||
sql """grant select_priv on ${dbName}.* to ${user1}""" | ||
connect(user=user1, password="${pwd}", url=url) { | ||
try { | ||
sql """grant select_priv on ${dbName}.* to ${user2}""" | ||
Assert.fail("can not grant to other user"); | ||
} catch (Exception e) { | ||
log.info(e.getMessage()) | ||
} | ||
} | ||
|
||
// test both have select_priv and grant_priv , can grant to other user | ||
sql """grant grant_priv on ${dbName}.* to ${user1}""" | ||
connect(user=user1, password="${pwd}", url=url) { | ||
try { | ||
sql """grant select_priv on ${dbName}.* to ${user2}""" | ||
} catch (Exception e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
// test have grant_priv,but not have load_priv, can not grant load_priv to other user | ||
try { | ||
sql """grant load_priv on ${dbName}.* to ${user2}""" | ||
Assert.fail("can not grant to other user"); | ||
} catch (Exception e) { | ||
log.info(e.getMessage()) | ||
} | ||
// test have grant_priv, can not grant role to other user | ||
try { | ||
sql """grant '${role1}' to ${user2}""" | ||
Assert.fail("can not grant to other user"); | ||
} catch (Exception e) { | ||
log.info(e.getMessage()) | ||
} | ||
} | ||
|
||
// test have global grant_priv, can grant role to other user | ||
sql """grant grant_priv on *.* to ${user1}""" | ||
try { | ||
sql """grant '${role1}' to ${user2}""" | ||
} catch (Exception e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
|
||
sql """drop user if exists ${user1}""" | ||
sql """drop user if exists ${user2}""" | ||
sql """drop role if exists ${role1}""" | ||
sql """DROP DATABASE IF EXISTS ${dbName}""" | ||
} |
57 changes: 57 additions & 0 deletions
57
regression-test/suites/account_p0/test_grant_priv_resource.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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 org.junit.Assert; | ||
|
||
suite("test_grant_priv_resource") { | ||
def user1 = 'test_grant_priv_resource_user1' | ||
def user2 = 'test_grant_priv_resource_user2' | ||
def pwd = '123456' | ||
def resource1 = 'test_grant_priv_resource_resource1' | ||
def tokens = context.config.jdbcUrl.split('/') | ||
def url=tokens[0] + "//" + tokens[2] + "/" + "information_schema" + "?" | ||
|
||
sql """drop user if exists ${user1}""" | ||
sql """drop user if exists ${user2}""" | ||
|
||
sql """CREATE USER '${user1}' IDENTIFIED BY '${pwd}'""" | ||
sql """CREATE USER '${user2}' IDENTIFIED BY '${pwd}'""" | ||
|
||
// test only have USAGE_PRIV, can not grant to other user | ||
sql """grant USAGE_PRIV on RESOURCE ${resource1} to ${user1}""" | ||
connect(user=user1, password="${pwd}", url=url) { | ||
try { | ||
sql """grant USAGE_PRIV on RESOURCE ${resource1} to ${user2}""" | ||
Assert.fail("can not grant to other user"); | ||
} catch (Exception e) { | ||
log.info(e.getMessage()) | ||
} | ||
} | ||
|
||
// test both have USAGE_PRIV and grant_priv , can grant to other user | ||
sql """grant grant_priv on RESOURCE * to ${user1}""" | ||
connect(user=user1, password="${pwd}", url=url) { | ||
try { | ||
sql """grant USAGE_PRIV on RESOURCE ${resource1} to ${user2}""" | ||
} catch (Exception e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
} | ||
|
||
sql """drop user if exists ${user1}""" | ||
sql """drop user if exists ${user2}""" | ||
} |
57 changes: 57 additions & 0 deletions
57
regression-test/suites/account_p0/test_grant_priv_workload.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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 org.junit.Assert; | ||
|
||
suite("test_grant_priv_workload") { | ||
def user1 = 'test_grant_priv_workload_user1' | ||
def user2 = 'test_grant_priv_workload_user2' | ||
def pwd = '123456' | ||
def workload1 = 'test_grant_priv_workload_workload1' | ||
def tokens = context.config.jdbcUrl.split('/') | ||
def url=tokens[0] + "//" + tokens[2] + "/" + "information_schema" + "?" | ||
|
||
sql """drop user if exists ${user1}""" | ||
sql """drop user if exists ${user2}""" | ||
|
||
sql """CREATE USER '${user1}' IDENTIFIED BY '${pwd}'""" | ||
sql """CREATE USER '${user2}' IDENTIFIED BY '${pwd}'""" | ||
|
||
// test only have USAGE_PRIV, can not grant to other user | ||
sql """grant USAGE_PRIV on WORKLOAD GROUP ${workload1} to ${user1}""" | ||
connect(user=user1, password="${pwd}", url=url) { | ||
try { | ||
sql """grant USAGE_PRIV on WORKLOAD GROUP ${workload1} to ${user2}""" | ||
Assert.fail("can not grant to other user"); | ||
} catch (Exception e) { | ||
log.info(e.getMessage()) | ||
} | ||
} | ||
|
||
// test both have USAGE_PRIV and grant_priv , can grant to other user | ||
sql """grant grant_priv on WORKLOAD GROUP ${workload1} to ${user1}""" | ||
connect(user=user1, password="${pwd}", url=url) { | ||
try { | ||
sql """grant USAGE_PRIV on WORKLOAD GROUP ${workload1} to ${user2}""" | ||
} catch (Exception e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
} | ||
|
||
sql """drop user if exists ${user1}""" | ||
sql """drop user if exists ${user2}""" | ||
} |