mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Merge pull request #64320 from ClickHouse/backport/24.3/64079
Backport #64079 to 24.3: Fix SQL security access checks with analyzer
This commit is contained in:
commit
a11519a15b
@ -414,7 +414,8 @@ std::optional<Chain> generateViewChain(
|
|||||||
out.getInputHeader(),
|
out.getInputHeader(),
|
||||||
view_id,
|
view_id,
|
||||||
nullptr,
|
nullptr,
|
||||||
std::move(runtime_stats)});
|
std::move(runtime_stats),
|
||||||
|
insert_context});
|
||||||
|
|
||||||
if (type == QueryViewsLogElement::ViewType::MATERIALIZED)
|
if (type == QueryViewsLogElement::ViewType::MATERIALIZED)
|
||||||
{
|
{
|
||||||
@ -590,7 +591,7 @@ Chain buildPushingToViewsChain(
|
|||||||
|
|
||||||
static QueryPipeline process(Block block, ViewRuntimeData & view, const ViewsData & views_data)
|
static QueryPipeline process(Block block, ViewRuntimeData & view, const ViewsData & views_data)
|
||||||
{
|
{
|
||||||
const auto & context = views_data.context;
|
const auto & context = view.context;
|
||||||
|
|
||||||
/// We create a table with the same name as original table and the same alias columns,
|
/// We create a table with the same name as original table and the same alias columns,
|
||||||
/// but it will contain single block (that is INSERT-ed into main table).
|
/// but it will contain single block (that is INSERT-ed into main table).
|
||||||
|
@ -33,6 +33,9 @@ struct ViewRuntimeData
|
|||||||
/// Info which is needed for query views log.
|
/// Info which is needed for query views log.
|
||||||
std::unique_ptr<QueryViewsLogElement::ViewRuntimeStats> runtime_stats;
|
std::unique_ptr<QueryViewsLogElement::ViewRuntimeStats> runtime_stats;
|
||||||
|
|
||||||
|
/// An overridden context bounded to this view with the correct SQL security grants.
|
||||||
|
ContextPtr context;
|
||||||
|
|
||||||
void setException(std::exception_ptr e)
|
void setException(std::exception_ptr e)
|
||||||
{
|
{
|
||||||
exception = e;
|
exception = e;
|
||||||
|
@ -24,6 +24,9 @@ OK
|
|||||||
2
|
2
|
||||||
OK
|
OK
|
||||||
OK
|
OK
|
||||||
|
OK
|
||||||
|
100
|
||||||
|
100
|
||||||
===== TestGrants =====
|
===== TestGrants =====
|
||||||
OK
|
OK
|
||||||
OK
|
OK
|
||||||
|
@ -159,6 +159,45 @@ ${CLICKHOUSE_CLIENT} --query "REVOKE SELECT ON $db.test_table FROM $user1"
|
|||||||
(( $(${CLICKHOUSE_CLIENT} --user $user2 --query "SELECT * FROM $db.test_mv_4" 2>&1 | grep -c "Not enough privileges") >= 1 )) && echo "OK" || echo "UNEXPECTED"
|
(( $(${CLICKHOUSE_CLIENT} --user $user2 --query "SELECT * FROM $db.test_mv_4" 2>&1 | grep -c "Not enough privileges") >= 1 )) && echo "OK" || echo "UNEXPECTED"
|
||||||
(( $(${CLICKHOUSE_CLIENT} --query "INSERT INTO $db.test_table VALUES ('foo'), ('bar');" 2>&1 | grep -c "Not enough privileges") >= 1 )) && echo "OK" || echo "UNEXPECTED"
|
(( $(${CLICKHOUSE_CLIENT} --query "INSERT INTO $db.test_table VALUES ('foo'), ('bar');" 2>&1 | grep -c "Not enough privileges") >= 1 )) && echo "OK" || echo "UNEXPECTED"
|
||||||
|
|
||||||
|
${CLICKHOUSE_CLIENT} --multiquery <<EOF
|
||||||
|
CREATE TABLE $db.source
|
||||||
|
(
|
||||||
|
a UInt64
|
||||||
|
)
|
||||||
|
ENGINE = MergeTree
|
||||||
|
ORDER BY a;
|
||||||
|
|
||||||
|
CREATE TABLE $db.destination1
|
||||||
|
(
|
||||||
|
a UInt64
|
||||||
|
)
|
||||||
|
ENGINE = MergeTree
|
||||||
|
ORDER BY a;
|
||||||
|
|
||||||
|
CREATE TABLE $db.destination2
|
||||||
|
(
|
||||||
|
a UInt64
|
||||||
|
)
|
||||||
|
ENGINE = MergeTree
|
||||||
|
ORDER BY a;
|
||||||
|
|
||||||
|
CREATE MATERIALIZED VIEW $db.mv1 TO $db.destination1
|
||||||
|
AS SELECT *
|
||||||
|
FROM $db.source;
|
||||||
|
|
||||||
|
ALTER TABLE $db.mv1 MODIFY DEFINER=default SQL SECURITY DEFINER;
|
||||||
|
|
||||||
|
CREATE MATERIALIZED VIEW $db.mv2 TO $db.destination2
|
||||||
|
AS SELECT *
|
||||||
|
FROM $db.destination1;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
(( $(${CLICKHOUSE_CLIENT} --user $user2 --query "INSERT INTO source SELECT * FROM generateRandom() LIMIT 100" 2>&1 | grep -c "Not enough privileges") >= 1 )) && echo "OK" || echo "UNEXPECTED"
|
||||||
|
${CLICKHOUSE_CLIENT} --query "GRANT INSERT ON $db.source TO $user2"
|
||||||
|
${CLICKHOUSE_CLIENT} --user $user2 --query "INSERT INTO source SELECT * FROM generateRandom() LIMIT 100"
|
||||||
|
|
||||||
|
${CLICKHOUSE_CLIENT} --query "SELECT count() FROM destination1"
|
||||||
|
${CLICKHOUSE_CLIENT} --query "SELECT count() FROM destination2"
|
||||||
|
|
||||||
echo "===== TestGrants ====="
|
echo "===== TestGrants ====="
|
||||||
${CLICKHOUSE_CLIENT} --query "GRANT CREATE ON *.* TO $user1"
|
${CLICKHOUSE_CLIENT} --query "GRANT CREATE ON *.* TO $user1"
|
||||||
@ -192,7 +231,6 @@ ${CLICKHOUSE_CLIENT} --user $user1 --query "
|
|||||||
|
|
||||||
${CLICKHOUSE_CLIENT} --query "GRANT SET DEFINER ON $user2 TO $user1"
|
${CLICKHOUSE_CLIENT} --query "GRANT SET DEFINER ON $user2 TO $user1"
|
||||||
|
|
||||||
|
|
||||||
echo "===== TestRowPolicy ====="
|
echo "===== TestRowPolicy ====="
|
||||||
${CLICKHOUSE_CLIENT} --multiquery <<EOF
|
${CLICKHOUSE_CLIENT} --multiquery <<EOF
|
||||||
CREATE TABLE $db.test_row_t (x Int32, y Int32) ENGINE = MergeTree ORDER BY x;
|
CREATE TABLE $db.test_row_t (x Int32, y Int32) ENGINE = MergeTree ORDER BY x;
|
||||||
|
Loading…
Reference in New Issue
Block a user