-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
feat(admin): Extend /run_clickhouse_system_query to support custom SQL queries #2296
Conversation
…m SQL queries You can now post custom SQL to /run_clickhouse_system_query in addition to requesting one of the predefined queries. This change includes some rudimentary validation to ensure that no attempt is made to insert, select or join on non system tables. Eventually this should be replaced by more robust parsing of the query into an AST. Depends on the API fixes included in #2294
Codecov Report
@@ Coverage Diff @@
## master #2296 +/- ##
==========================================
- Coverage 92.93% 92.83% -0.10%
==========================================
Files 556 557 +1
Lines 25494 25551 +57
==========================================
+ Hits 23692 23720 +28
- Misses 1802 1831 +29
Continue to review full report at Codecov.
|
# An incomplete list | ||
VALID_SYSTEM_TABLES = [ | ||
"clusters", | ||
"merges", | ||
"parts", | ||
] |
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.
You can allow all of them. There is nothing dangerous there.
But if you plan to keep it. Please add:
replication_queue
settings
metrics
columns
for kw in disallowed_keywords: | ||
if kw in select_statement.lower(): | ||
raise InvalidCustomQuery(f"{kw} is not allowed here") | ||
|
||
system_table_name = match.group("system_table_name") | ||
|
||
if system_table_name not in VALID_SYSTEM_TABLES: | ||
raise InvalidCustomQuery("Invalid table") | ||
|
||
extra = match.group("extra") | ||
|
||
# Unfortunately "extra" is pretty permissive right now, just ensure | ||
# there is no attempt to do a select, insert or join in there | ||
if extra is not None: | ||
for kw in disallowed_keywords: | ||
if kw in extra.lower(): | ||
raise InvalidCustomQuery(f"{kw} is not allowed 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.
Let's have a proper AST here asap.
You can now post custom SQL to /run_clickhouse_system_query in addition to requesting
one of the predefined ones. This change includes some rudimentary validation to
ensure that no attempt is made to insert, select or join on non system tables.
Eventually this should be replaced by more robust parsing of the query into an AST.
Depends on the API fixes included in #2294