Skip to content

Commit a4ce138

Browse files
authored
Merge pull request #1256 from Altinity/backports/25.8.13/90761
25.8.13 Stable backport of ClickHouse#90761: Fix access validation for ALTER UPDATE with `remote` table function
2 parents 71096e1 + 5bc9370 commit a4ce138

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/TableFunctions/TableFunctionRemote.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <Core/Defines.h>
2222
#include <Core/Settings.h>
2323
#include <TableFunctions/registerTableFunctions.h>
24+
#include <Access/Common/AccessFlags.h>
2425

2526

2627
namespace DB
@@ -315,6 +316,22 @@ StoragePtr TableFunctionRemote::executeImpl(const ASTPtr & /*ast_function*/, Con
315316
cached_columns = getActualTableStructure(context, is_insert_query);
316317

317318
assert(cluster);
319+
320+
bool has_local_shard = false;
321+
for (const auto & shard_info : cluster->getShardsInfo())
322+
{
323+
if (shard_info.isLocal())
324+
{
325+
has_local_shard = true;
326+
break;
327+
}
328+
}
329+
330+
if (has_local_shard && !is_insert_query)
331+
context->checkAccess(AccessType::SELECT, remote_table_id);
332+
else if (has_local_shard)
333+
context->checkAccess(AccessType::INSERT, remote_table_id);
334+
318335
StoragePtr res = std::make_shared<StorageDistributed>(
319336
StorageID(getDatabaseName(), table_name),
320337
cached_columns,

tests/queries/0_stateless/03727_alter_with_localhost_remote.reference

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- Tags: no-replicated-database, no-parallel
2+
3+
DROP USER IF EXISTS test_03727;
4+
CREATE USER test_03727;
5+
6+
CREATE TABLE normal
7+
(
8+
n Int32,
9+
s String
10+
)
11+
ENGINE = MergeTree()
12+
ORDER BY n;
13+
14+
CREATE TABLE secret
15+
(
16+
s String
17+
)
18+
ENGINE = MergeTree()
19+
ORDER BY s;
20+
21+
INSERT INTO normal VALUES (1, '');
22+
INSERT INTO secret VALUES ('secret');
23+
24+
GRANT ALTER UPDATE ON normal TO test_03727;
25+
GRANT READ ON REMOTE to test_03727;
26+
GRANT CREATE TEMPORARY TABLE ON *.* TO test_03727;
27+
28+
EXECUTE AS test_03727 ALTER TABLE normal UPDATE s = (SELECT * FROM remote('localhost', currentDatabase(), 'secret') LIMIT 1) WHERE n=1; -- { serverError ACCESS_DENIED }
29+
30+
DROP USER IF EXISTS test_03727;

0 commit comments

Comments
 (0)