-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ALTER QUERY MODIFY SQL SECURITY #61480
Conversation
This is an automated comment for commit 1bafdf3 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
|
@pufit Could you explain please how |
@@ -92,6 +90,7 @@ ${CLICKHOUSE_CLIENT} --user $user2 --query "SELECT count() FROM $db.test_view_10 | |||
|
|||
${CLICKHOUSE_CLIENT} --query "ALTER TABLE $db.test_view_10 MODIFY SQL SECURITY INVOKER" | |||
(( $(${CLICKHOUSE_CLIENT} --user $user2 --query "SELECT * FROM $db.test_view_10" 2>&1 | grep -c "Not enough privileges") >= 1 )) && echo "OK" || echo "UNEXPECTED" | |||
${CLICKHOUSE_CLIENT} --query "SHOW CREATE TABLE $db.test_view_10" | grep -c "SQL SECURITY INVOKER" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will this line show if we run this test without this your fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0, because ALTER hadn't overridden the table's DDL properly. I missed it in the test because the table itself behaved correctly (see test on the line above), but all ALTER
's changes were lost after restart.
src/Parsers/ParserAlterQuery.cpp
Outdated
else if (s_modify_definer.ignore(pos, expected)) | ||
{ | ||
/// Same hack here | ||
pos -= 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this hack here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s_modify_definer
moves the current position to
ALTER TABLE MODIFY DEFINER = pufit
/\
but the ParserSQLSecurity
takes AST DEFINER = ... [SQL SECURITY ...]
or SQL SECURITY ... [DEFINER = ...]
So, in order to reuse this parser, we need to move the current position one step back.
ALTER TABLE MODIFY DEFINER = pufit
/\
The crash in the linked issue happened because ASTSQLSecurity::formatImpl
returns a canonical form DEFINER = ... SQL SECURITY DEFINER
, so the ALTER
query ALTER TABLE ... MODIFY SQL SECURITY DEFINER = pufit
changes after format into ALTER TABLE ... MODIFY DEFINER = pufit SQL SECURITY DEFINER
and can't be parsed again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit too hacky, it seems better to modify ParserSQLSecurity
and add there a parameter to its constructor which would allow to disable parsing either the DEFINER
or SQL SECURITY
keyword.
Please resolve the conflict. |
# Conflicts: # src/Parsers/ParserAlterQuery.cpp
@pufit check this:
|
The problem with a replicated database is that we can't create users on all instances in our stateless tests. |
Backport #61480 to 24.2: Fix ALTER QUERY MODIFY SQL SECURITY
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix the
ALTER QUERY MODIFY SQL SECURITY
queries to override the table's DDL correctly.Closes #61245
Documentation entry for user-facing changes