-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Better access validation in ON CLUSTER queries.
#71334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a91af70
User validation in `ON CLUSTER` queries.
pufit 23f9f24
Merge branch 'master' into pufit/fix-on-cluster-user
pufit 7a91ab7
Revert `distributed_ddl_entry_format_version` change
pufit af04abb
Merge branch 'master' into pufit/fix-on-cluster-user
pufit a4cf904
Store UUIDs instead of names
pufit 48489b2
Automatic style fix
robot-clickhouse 0533fe9
Update DDLTask.h
pufit f83a89a
Change log level
pufit a448333
Merge branch 'master' into pufit/fix-on-cluster-user
pufit 1935ac7
Fix test
pufit 7e821b0
Fix test
pufit b15c7cf
Fix test
pufit a329866
Fix test
pufit 5a423d0
Merge branch 'master' into pufit/fix-on-cluster-user
pufit d64f475
Fix test
pufit 64bc834
Merge branch 'master' into pufit/fix-on-cluster-user
pufit 9b0da05
Send user and role names instead of UUID.
pufit 3a916b8
Rename server setting
pufit bab4ec7
Update test config
pufit 29e4b4f
Add test for setting
pufit 3b7952a
Fix flaky test
pufit ad90db6
Merge branch 'master' into pufit/fix-on-cluster-user
pufit 1916d8e
Fix flaky test
pufit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Empty file.
23 changes: 23 additions & 0 deletions
23
tests/integration/test_replicated_access/configs/config.xml
This file contains hidden or 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,23 @@ | ||
| <clickhouse> | ||
| <distributed_ddl_use_initial_user_and_roles>1</distributed_ddl_use_initial_user_and_roles> | ||
| <remote_servers> | ||
| <default> | ||
| <shard> | ||
| <internal_replication>true</internal_replication> | ||
| <replica> | ||
| <host>node1</host> | ||
| <port>9000</port> | ||
| </replica> | ||
| <replica> | ||
| <host>node2</host> | ||
| <port>9000</port> | ||
| </replica> | ||
| </shard> | ||
| </default> | ||
| </remote_servers> | ||
| <user_directories replace="replace"> | ||
| <replicated> | ||
| <zookeeper_path>/clickhouse/access</zookeeper_path> | ||
| </replicated> | ||
| </user_directories> | ||
| </clickhouse> |
17 changes: 17 additions & 0 deletions
17
tests/integration/test_replicated_access/configs/zookeeper.xml
This file contains hidden or 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,17 @@ | ||
| <clickhouse> | ||
| <zookeeper> | ||
| <node index="1"> | ||
| <host>zoo1</host> | ||
| <port>2181</port> | ||
| </node> | ||
| <node index="2"> | ||
| <host>zoo2</host> | ||
| <port>2181</port> | ||
| </node> | ||
| <node index="3"> | ||
| <host>zoo3</host> | ||
| <port>2181</port> | ||
| </node> | ||
| <session_timeout_ms>20000</session_timeout_ms> | ||
| </zookeeper> | ||
| </clickhouse> |
This file contains hidden or 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,87 @@ | ||
| from os import path as p | ||
|
|
||
| import pytest | ||
|
|
||
| from helpers.cluster import ClickHouseCluster | ||
|
|
||
| default_zk_config = p.join(p.dirname(p.realpath(__file__)), "configs/zookeeper.xml") | ||
| cluster = ClickHouseCluster(__file__, zookeeper_config_path="configs/zookeeper.xml") | ||
|
|
||
| node1 = cluster.add_instance( | ||
| "node1", | ||
| main_configs=["configs/config.xml"], | ||
| with_zookeeper=True, | ||
| stay_alive=True, | ||
| ) | ||
|
|
||
| node2 = cluster.add_instance( | ||
| "node2", | ||
| main_configs=["configs/config.xml"], | ||
| with_zookeeper=True, | ||
| stay_alive=True, | ||
| ) | ||
|
|
||
| all_nodes = [node1, node2] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", autouse=True) | ||
| def started_cluster(): | ||
| try: | ||
| cluster.start() | ||
| yield cluster | ||
| finally: | ||
| cluster.shutdown() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function", autouse=True) | ||
| def prepare_test(): | ||
| node1.query("CREATE USER test") | ||
| node1.query("CREATE TABLE IF NOT EXISTS table ON CLUSTER default (x UInt64) ENGINE=MergeTree ORDER BY x") | ||
| node1.query("CREATE TABLE IF NOT EXISTS secret ON CLUSTER default (value String) ENGINE=MergeTree ORDER BY value") | ||
| try: | ||
| yield | ||
| finally: | ||
| node1.query("DROP USER IF EXISTS test") | ||
| node1.query("DROP TABLE IF EXISTS table ON CLUSTER default") | ||
| node1.query("DROP TABLE IF EXISTS secret ON CLUSTER default") | ||
|
|
||
|
|
||
| def test_initiator_user_in_ddl(started_cluster): | ||
pufit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| node1.query("INSERT INTO secret VALUES ('super_secret')") | ||
|
|
||
| node1.query("GRANT ALTER ON table TO test") | ||
| node1.query("GRANT CLUSTER ON *.* TO test") | ||
|
|
||
| query = """ | ||
| ALTER TABLE table ON CLUSTER default | ||
| ADD PROJECTION test ( | ||
| SELECT | ||
| x, | ||
| (SELECT * FROM secret LIMIT 1) as bar | ||
| ORDER BY x | ||
| ) | ||
| SETTINGS distributed_ddl_entry_format_version = 8 | ||
| """ | ||
|
|
||
| error = node1.query_and_get_error(query, user="test") | ||
| assert "Not enough privileges" in error | ||
pufit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| for node in all_nodes: | ||
| node.replace_in_config( | ||
| "/etc/clickhouse-server/config.d/config.xml", | ||
| "<distributed_ddl_use_initial_user_and_roles>1</distributed_ddl_use_initial_user_and_roles>", | ||
| "<distributed_ddl_use_initial_user_and_roles>0</distributed_ddl_use_initial_user_and_roles>", | ||
| ) | ||
| node.restart_clickhouse() | ||
|
|
||
| error = node1.query_and_get_error(query, user="test") | ||
| assert "Not enough privileges" not in error | ||
|
|
||
| for node in all_nodes: | ||
| node.replace_in_config( | ||
| "/etc/clickhouse-server/config.d/config.xml", | ||
| "<distributed_ddl_use_initial_user_and_roles>0</distributed_ddl_use_initial_user_and_roles>", | ||
| "<distributed_ddl_use_initial_user_and_roles>1</distributed_ddl_use_initial_user_and_roles>", | ||
| ) | ||
| node.restart_clickhouse() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.