Skip to content

Commit 870fd2b

Browse files
Backport ClickHouse#89068 to 25.8: Fix clusterAllReplicas queries with external role when it was dropped
1 parent 13981dc commit 870fd2b

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/QueryPipeline/RemoteQueryExecutor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ void RemoteQueryExecutor::sendQueryUnlocked(ClientInfo::QueryKind query_kind, As
425425
const auto & access_control = context->getAccessControl();
426426
for (const auto & e : user->granted_roles.getElements())
427427
{
428-
auto names = access_control.readNames(e.ids);
428+
// `tryReadNames` instead of `readNames` because the original user might have a dropped role.
429+
auto names = access_control.tryReadNames(e.ids);
429430
granted_roles.insert(names.begin(), names.end());
430431
}
431432
}

tests/queries/0_stateless/03702_not_existing_role_on_cluster.reference

Whitespace-only changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
# Tags: no-replicated-database, no-parallel
3+
4+
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
5+
# shellcheck source=../shell_config.sh
6+
. "$CUR_DIR"/../shell_config.sh
7+
8+
user="user03702_${CLICKHOUSE_DATABASE}_$RANDOM"
9+
role="role03702_${CLICKHOUSE_DATABASE}_$RANDOM"
10+
db=${CLICKHOUSE_DATABASE}
11+
12+
${CLICKHOUSE_CLIENT} <<EOF
13+
DROP DATABASE IF EXISTS shard_0;
14+
DROP DATABASE IF EXISTS shard_1;
15+
16+
CREATE DATABASE IF NOT EXISTS shard_0;
17+
CREATE DATABASE IF NOT EXISTS shard_1;
18+
19+
SET distributed_ddl_output_mode = 'none';
20+
DROP USER IF EXISTS $user ON CLUSTER test_cluster_two_shards_different_databases;
21+
CREATE USER $user ON CLUSTER test_cluster_two_shards_different_databases;
22+
23+
DROP ROLE IF EXISTS $role ON CLUSTER test_cluster_two_shards_different_databases;
24+
CREATE ROLE $role ON CLUSTER test_cluster_two_shards_different_databases;
25+
26+
GRANT REMOTE ON *.* TO $user ON CLUSTER test_cluster_two_shards_different_databases;
27+
GRANT SELECT ON *.* TO $role ON CLUSTER test_cluster_two_shards_different_databases;
28+
29+
GRANT $role TO $user ON CLUSTER test_cluster_two_shards_different_databases;
30+
DROP ROLE $role ON CLUSTER test_cluster_two_shards_different_databases;
31+
EOF
32+
33+
${CLICKHOUSE_CLIENT} --user $user <<EOF
34+
SELECT
35+
hostName() AS h,
36+
count()
37+
FROM clusterAllReplicas('test_cluster_two_shards_different_databases', system.one)
38+
GROUP BY h
39+
FORMAT Null;
40+
EOF
41+
42+
${CLICKHOUSE_CLIENT} <<EOF
43+
SET distributed_ddl_output_mode = 'none';
44+
DROP USER IF EXISTS $user ON CLUSTER test_cluster_two_shards_different_databases;
45+
EOF

0 commit comments

Comments
 (0)