Skip to content

Commit 5e3b9b5

Browse files
authored
Merge pull request #1099 from Altinity/backport/24.8.14/88802
24.8.14 Backport of ClickHouse#88802 - Better access validation for `TableFunctionLoop`
2 parents 3b3df79 + 26b49de commit 5e3b9b5

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/TableFunctions/TableFunctionLoop.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "config.h"
2+
#include <Access/Common/AccessFlags.h>
23
#include <TableFunctions/ITableFunction.h>
34
#include <TableFunctions/TableFunctionFactory.h>
45
#include <Interpreters/Context.h>
@@ -118,6 +119,7 @@ namespace DB
118119
storage = database->tryGetTable(loop_table_name, context);
119120
if (!storage)
120121
throw Exception(ErrorCodes::UNKNOWN_TABLE, "Table '{}' not found in database '{}'", loop_table_name, database_name);
122+
context->checkAccess(AccessType::SELECT, database_name, loop_table_name);
121123
}
122124
else
123125
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
# Tags: long, no-replicated-database, no-async-insert
3+
4+
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
5+
# shellcheck source=../shell_config.sh
6+
. "$CURDIR"/../shell_config.sh
7+
8+
9+
user="user03631_${CLICKHOUSE_DATABASE}_$RANDOM"
10+
db=${CLICKHOUSE_DATABASE}
11+
12+
${CLICKHOUSE_CLIENT} <<EOF
13+
CREATE TABLE $db.test_table (s String) ENGINE = MergeTree ORDER BY s;
14+
INSERT INTO $db.test_table VALUES ('foo');
15+
16+
DROP USER IF EXISTS $user;
17+
CREATE USER $user;
18+
GRANT CREATE TEMPORARY TABLE ON *.* TO $user;
19+
EOF
20+
21+
${CLICKHOUSE_CLIENT} --user $user --query "SELECT * FROM loop('$db', 'test_table') LIMIT 1; -- { serverError ACCESS_DENIED }";
22+
${CLICKHOUSE_CLIENT} --query "GRANT SELECT ON $db.test_table TO $user";
23+
${CLICKHOUSE_CLIENT} --user $user --query "SELECT * FROM loop('$db', 'test_table') LIMIT 1";
24+
25+
${CLICKHOUSE_CLIENT} --query "DROP USER IF EXISTS $user";

0 commit comments

Comments
 (0)