forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add permission checking for kill queries. (vesoft-inc#3896)
* Add permission checking for kill queries. * Fix typo. * Add new line. * Fix typo. * Fix typo. Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
- Loading branch information
1 parent
49bfaf2
commit 6830651
Showing
7 changed files
with
122 additions
and
8 deletions.
There are no files selected for viewing
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,44 @@ | ||
# Copyright (c) 2022 vesoft inc. All rights reserved. | ||
# | ||
# This source code is licensed under Apache 2.0 License. | ||
Feature: Test kill queries permission from different services | ||
|
||
Scenario: Setup slow query in service 1 | ||
# Set up a slow query which will be killed later. | ||
Given a graph with space named "nba" | ||
When executing query via graph 1: | ||
""" | ||
USE nba; | ||
GO 100000 STEPS FROM "Tim Duncan" OVER like YIELD like._dst | ||
""" | ||
Then an ExecutionError should be raised at runtime: Execution had been killed | ||
|
||
Scenario: Test permisson of kill queries from service 0 | ||
Given a graph with space named "nba" | ||
When executing query: | ||
""" | ||
CREATE USER IF NOT EXISTS test_permission WITH PASSWORD 'test'; | ||
GRANT ROLE USER ON nba TO test_permission; | ||
""" | ||
Then the execution should be successful | ||
And wait 3 seconds | ||
When executing query with user test_permission with password test: | ||
""" | ||
USE nba; | ||
SHOW QUERIES | ||
| YIELD $-.SessionID AS sid, $-.ExecutionPlanID AS eid, $-.DurationInUSec AS dur | ||
WHERE $-.DurationInUSec > 1000000 AND $-.`Query` CONTAINS "GO" | ||
| ORDER BY $-.dur | ||
| KILL QUERY(session=$-.sid, plan=$-.eid) | ||
""" | ||
Then an PermissionError should be raised at runtime: Only GOD role could kill others' queries. | ||
When executing query with user root with password nebula: | ||
""" | ||
USE nba; | ||
SHOW QUERIES | ||
| YIELD $-.SessionID AS sid, $-.ExecutionPlanID AS eid, $-.DurationInUSec AS dur | ||
WHERE $-.DurationInUSec > 1000000 AND $-.`Query` CONTAINS "GO" | ||
| ORDER BY $-.dur | ||
| KILL QUERY(session=$-.sid, plan=$-.eid) | ||
""" | ||
Then the execution should be successful |
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,43 @@ | ||
# Copyright (c) 2022 vesoft inc. All rights reserved. | ||
# | ||
# This source code is licensed under Apache 2.0 License. | ||
Feature: Test kill queries from same service | ||
|
||
Scenario: Setup slow query | ||
# Set up a slow query which will be killed later. | ||
Given a graph with space named "nba" | ||
When executing query: | ||
""" | ||
GO 100000 STEPS FROM "Tim Duncan" OVER like YIELD like._dst | ||
""" | ||
Then an ExecutionError should be raised at runtime: Execution had been killed | ||
|
||
Scenario: Test permisson of kill queries | ||
Given a graph with space named "nba" | ||
When executing query: | ||
""" | ||
CREATE USER IF NOT EXISTS test_permission WITH PASSWORD 'test'; | ||
GRANT ROLE USER ON nba TO test_permission; | ||
""" | ||
Then the execution should be successful | ||
And wait 3 seconds | ||
When executing query with user test_permission with password test: | ||
""" | ||
USE nba; | ||
SHOW QUERIES | ||
| YIELD $-.SessionID AS sid, $-.ExecutionPlanID AS eid, $-.DurationInUSec AS dur | ||
WHERE $-.DurationInUSec > 1000000 AND $-.`Query` CONTAINS "GO" | ||
| ORDER BY $-.dur | ||
| KILL QUERY(session=$-.sid, plan=$-.eid) | ||
""" | ||
Then an PermissionError should be raised at runtime: Only GOD role could kill others' queries. | ||
When executing query with user root with password nebula: | ||
""" | ||
USE nba; | ||
SHOW QUERIES | ||
| YIELD $-.SessionID AS sid, $-.ExecutionPlanID AS eid, $-.DurationInUSec AS dur | ||
WHERE $-.DurationInUSec > 1000000 AND $-.`Query` CONTAINS "GO" | ||
| ORDER BY $-.dur | ||
| KILL QUERY(session=$-.sid, plan=$-.eid) | ||
""" | ||
Then the execution should be successful |
7 changes: 7 additions & 0 deletions
7
tests/tck/steps/test_kill_permission_via_different_service.py
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,7 @@ | ||
# Copyright (c) 2022 vesoft inc. All rights reserved. | ||
# | ||
# This source code is licensed under Apache 2.0 License. | ||
|
||
from pytest_bdd import scenarios | ||
|
||
scenarios('slowquery/permissionViaDifferentService.feature') |
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,7 @@ | ||
# Copyright (c) 2022 vesoft inc. All rights reserved. | ||
# | ||
# This source code is licensed under Apache 2.0 License. | ||
|
||
from pytest_bdd import scenarios | ||
|
||
scenarios('slowquery/permissionViaSameService.feature') |