Skip to content

Commit cca7f5c

Browse files
authored
Merge pull request ClickHouse#89237 from ClickHouse/backport/25.8/88588
Backport ClickHouse#88588 to 25.8: Fix SQL SECURITY DEFINER with *cluster functions
2 parents 7438d7e + a69a4a6 commit cca7f5c

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/Storages/StorageView.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,15 @@ void StorageView::read(
178178

179179
if (context->getSettingsRef()[Setting::allow_experimental_analyzer])
180180
{
181-
InterpreterSelectQueryAnalyzer interpreter(current_inner_query, getViewContext(context, storage_snapshot), options, column_names);
181+
auto view_context = getViewContext(context, storage_snapshot);
182+
InterpreterSelectQueryAnalyzer interpreter(current_inner_query, view_context, options, column_names);
182183
interpreter.addStorageLimits(*query_info.storage_limits);
183184
query_plan = std::move(interpreter).extractQueryPlan();
184185
}
185186
else
186187
{
187-
InterpreterSelectWithUnionQuery interpreter(current_inner_query, getViewContext(context, storage_snapshot), options, column_names);
188+
auto view_context = getViewContext(context, storage_snapshot);
189+
InterpreterSelectWithUnionQuery interpreter(current_inner_query, view_context, options, column_names);
188190
interpreter.addStorageLimits(*query_info.storage_limits);
189191
interpreter.buildQueryPlan(query_plan);
190192
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
4
2+
4
3+
4
4+
4
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
# Tags: no-fasttest
3+
# Tag no-fasttest: Depends on AWS
4+
5+
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
6+
# shellcheck source=../shell_config.sh
7+
. "$CUR_DIR"/../shell_config.sh
8+
9+
other_user="user03667_${CLICKHOUSE_DATABASE}_$RANDOM"
10+
db=${CLICKHOUSE_DATABASE}
11+
12+
${CLICKHOUSE_CLIENT} <<EOF
13+
DROP USER IF EXISTS other_user;
14+
CREATE USER $other_user;
15+
GRANT SELECT ON $db.* TO $other_user;
16+
EOF
17+
18+
${CLICKHOUSE_CLIENT} <<EOF
19+
CREATE VIEW $db.test_view
20+
SQL SECURITY DEFINER
21+
AS SELECT * FROM s3Cluster('test_cluster_two_shards_localhost', 'http://localhost:11111/test/a.tsv');
22+
EOF
23+
24+
${CLICKHOUSE_CLIENT} --query "SELECT count() FROM $db.test_view"
25+
${CLICKHOUSE_CLIENT} --user $other_user --query "SELECT count() FROM $db.test_view"
26+
27+
${CLICKHOUSE_CLIENT} --query "SELECT count() FROM $db.test_view SETTINGS enable_analyzer=0"
28+
${CLICKHOUSE_CLIENT} --user $other_user --query "SELECT count() FROM $db.test_view SETTINGS enable_analyzer=0"
29+
30+
${CLICKHOUSE_CLIENT} <<EOF
31+
DROP VIEW IF EXISTS $db.test_view;
32+
DROP USER IF EXISTS $other_user;
33+
EOF

0 commit comments

Comments
 (0)