Repository navigation
Add definers for views - #54901
Add definers for views#54901
Conversation
|
This is an automated comment for commit a2a4657 with description of existing statuses. It's updated for the latest CI running ❌ Click here to open a full report in a separate page Successful checks
|
243aa99 to
bee2786
Compare
# Conflicts: # docs/en/operations/settings/settings.md # src/Core/Settings.h
| String getUserName() const; | ||
|
|
||
| /// WARNING: all requests with this context won't trigger any access checks. | ||
| void resetUser(); |
There was a problem hiding this comment.
Why do you need this? Just use the global context. It's nice that we have only one global context.
There was a problem hiding this comment.
I don't want to completely override the original local context. What if it had some other stuff in it?
There was a problem hiding this comment.
I think it's better to completely override the original context always when SQL_SECURITY is not INVOKER.
Because we want a context created for the definer, not kind of a mixture between contexts for two users. I mean all the settings should the definer's settings, and roles should be the definer's roles, and so on.
There was a problem hiding this comment.
Probably we need to keep the information about the initial query in the ClientInfo of the new context though.
| 178 | ||
| 188 | ||
| 198 | ||
| 02177_MV_3 20 0 1 |
# Conflicts: # src/Processors/Transforms/buildPushingToViewsChain.cpp
# Conflicts: # src/Core/SettingsChangesHistory.h # src/Processors/Transforms/buildPushingToViewsChain.cpp
e954148 to
50436ed
Compare
50436ed to
a2a4657
Compare
|
This PR will make an upgrade from 24.1 a bit difficult. If you have:
If you try to create a new normal/materialized view in Replica 1 ON CLUSTER, the following error will be returned: This is because the SQL syntax executed in Replica 2 already contains unsupported Full reproducer: CREATE DATABASE definer ON CLUSTER tinybird;
CREATE TABLE definer.landing ON CLUSTER tinybird (a UInt32) Engine=MergeTree() ORDER BY tuple();
CREATE TABLE definer.ds ON CLUSTER tinybird (a UInt32) Engine=MergeTree() ORDER BY tuple();
CREATE MATERIALIZED VIEW definer.mv ON CLUSTER tinybird TO definer.ds AS SELECT a FROM definer.landing; |
This reverts commit 5730670.
@pufit It seems we should add |
| } | ||
|
|
||
| if (!sql_security && !sql_security_p.parse(pos, sql_security, expected)) | ||
| sql_security = std::make_shared<ASTSQLSecurity>(); |
There was a problem hiding this comment.
It looks strange that after you failed to parse SQL security you're adding a default one to the query anyway. It seems better not to do that:
if (!sql_security)
sql_security_p.parse(pos, sql_security, expected);
| enum class SQLSecurityType | ||
| { | ||
| INVOKER, | ||
| DEFINER, |
| {"parallel_replicas_prefer_local_join", true, true, "If true, and JOIN can be executed with parallel replicas algorithm, and all storages of right JOIN part are *MergeTree, local JOIN will be used instead of GLOBAL JOIN."}, | ||
| {"extract_key_value_pairs_max_pairs_per_row", 0, 0, "Max number of pairs that can be produced by the `extractKeyValuePairs` function. Used as a safeguard against consuming too much memory."}, | ||
| }}, | ||
| {"async_insert_busy_timeout_decrease_rate", 0.2, 0.2, "The exponential growth rate at which the adaptive asynchronous insert timeout decreases"}, |
There was a problem hiding this comment.
async_insert_busy_timeout_decrease_rate - why is that here?
| }}, | ||
| {"async_insert_busy_timeout_decrease_rate", 0.2, 0.2, "The exponential growth rate at which the adaptive asynchronous insert timeout decreases"}, | ||
| {"default_view_definer", "", "CURRENT_USER", "Allows to set default `DEFINER` option while creating a view"}, | ||
| {"default_materialized_view_sql_security", "INVOKER", "DEFINER", "Allows to set a default value for SQL SECURITY option when creating a materialized view"}, |
There was a problem hiding this comment.
Do we support default_view_definer='' and default_materialized_view_sql_security='INVOKER'?
There is a problem: if we run a simple query with no SQL security specified, the default values must be resolved on the initiator side. Otherwise, we can get a different SQL security on the other replicas. The only solution I can see is to add a special setting for the migration period (a.k.a "I know what I'm doing"), which will forcefully disable the new SQL security syntax during DDL, assuming that default values are the same for all replicas. |
|
Good approach. Let's proceed with setting which will be disabled for a few releases and then made obsolete. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Added new syntax which allows to specify definer user in View/Materialized View. This allows to execute selects/inserts from views without explicit grants for underlying tables.
Documentation entry for user-facing changes
Closes #19228
TODO:
GRANT DEFINER ON anotheruser TO user