MDEV-40323 CONNECT engine - add file access checks for JSON UDFs#5368
Open
vaintroub wants to merge 1 commit into
Open
MDEV-40323 CONNECT engine - add file access checks for JSON UDFs#5368vaintroub wants to merge 1 commit into
vaintroub wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements FILE privilege and secure_file_priv enforcement for CONNECT’s JSON/BSON file-based UDFs, aligning their file I/O behavior with server-side file access restrictions.
Changes:
- Introduces a shared helper (
connect_can_access_file) to validate FILE privilege andsecure_file_priv-allowed paths. - Applies the access check to JSON UDFs (
json_file,jfile_make,jbin_file) and BSON UDFs (bson_file,bfile_make,bbin_file). - Adds an MTR test to validate JSON UDF enforcement behavior under
--secure_file_priv=$MYSQL_TMP_DIR.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| storage/connect/jsonudf.cpp | Adds file access enforcement to JSON file UDF entry points. |
| storage/connect/bsonudf.cpp | Adds file access enforcement to BSON file UDF entry points. |
| storage/connect/filechk.cpp | Implements FILE privilege + secure_file_priv path validation helper. |
| storage/connect/filechk.h | Declares the new helper. |
| storage/connect/CMakeLists.txt | Adds filechk.cpp/.h to CONNECT build sources. |
| storage/connect/mysql-test/connect/t/json_file_priv.test | New MTR test covering JSON UDF enforcement scenarios. |
| storage/connect/mysql-test/connect/t/json_file_priv.opt | Runs the test with secure_file_priv set to $MYSQL_TMP_DIR. |
| storage/connect/mysql-test/connect/r/json_file_priv.result | Expected output for the new JSON UDF privilege test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+4559
to
+4563
| if (!connect_can_access_file(fn)) { | ||
| PUSH_WARNING("Access denied: FILE privilege or secure_file_priv violation"); | ||
| *is_null = 1; | ||
| return NULL; | ||
| } |
Comment on lines
+5817
to
+5821
| if (!connect_can_access_file(fn)) { | ||
| PUSH_WARNING("Access denied: FILE privilege or secure_file_priv violation"); | ||
| *error = 1; | ||
| goto fin; | ||
| } |
Comment on lines
+4478
to
+4482
| if (!connect_can_access_file(fn)) { | ||
| PUSH_WARNING("Access denied: FILE privilege or secure_file_priv violation"); | ||
| *is_null = 1; | ||
| return NULL; | ||
| } |
Comment on lines
+6074
to
+6078
| if (!connect_can_access_file(fn)) { | ||
| PUSH_WARNING("Access denied: FILE privilege or secure_file_priv violation"); | ||
| *error = 1; | ||
| goto fin; | ||
| } |
Comment on lines
+4478
to
+4482
| if (!connect_can_access_file(fn)) { | ||
| PUSH_WARNING("Access denied: FILE privilege or secure_file_priv violation"); | ||
| *is_null = 1; | ||
| return NULL; | ||
| } |
Comment on lines
+1
to
+4
| /* File access checks for CONNECT file UDFs */ | ||
| #pragma once | ||
| bool connect_can_access_file(const char *path); | ||
|
|
Comment on lines
+35
to
+37
| --echo # User without FILE privilege | ||
| create user unprivileged@localhost; | ||
| grant select ON *.* TO unprivileged@localhost; |
Contributor
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
Comment on lines
+4478
to
+4486
| if (!fn) { | ||
| PUSH_WARNING("Missing file name"); | ||
| *is_null = 1; | ||
| return NULL; | ||
| } else if (!connect_can_access_file(fn)) { | ||
| PUSH_WARNING("Access denied: FILE privilege or secure_file_priv violation"); | ||
| *is_null = 1; | ||
| return NULL; | ||
| } |
Comment on lines
+35
to
+38
| fn_format(real_path, path, mysql_real_data_home, "", | ||
| MY_RELATIVE_PATH | MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH); | ||
|
|
||
| return is_secure_file_path(real_path); |
Check FILE_ACL and secure_file_priv for the current user inside CONNECT file UDFs (json_file, jfile_make, jbin_file, bson_file, bfile_make, bbin_file). Fix NULL filename: guard GetFileLength in jbin_file_init and check for NULL fn in UDF bodies before the access check, so NULL arguments report "Missing file name" instead of "Access denied".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Check FILE_ACL privilege and secure_file_priv for the current user inside CONNECT file UDFs (json_file, jfile_make, jbin_file, bson_file, bfile_make, bbin_file).