-
Notifications
You must be signed in to change notification settings - Fork 481
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(compute): Add pg_duckdb extension v0.2.0 #10350
Open
ololobus
wants to merge
12
commits into
main
Choose a base branch
from
alexk/add-pg_duckdb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+225
−2
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4056242
feat(compute): Add pg_duckdb extension v0.2.0
ololobus 1ae0ab2
in Neon we don't allow superuser so we need to grant some superuser o…
Bodobolero 3e84dfb
Merge branch 'main' into alexk/add-pg_duckdb
Bodobolero d6a4896
use correct contrib sql file
Bodobolero 1ffd697
forgot semicolon
Bodobolero b6c0100
patch for duckdb that allows to install extension httpfs even if disa…
Bodobolero a6a42c5
fix typo
Bodobolero 0654c03
try to statically link some important duckdb extensions
Bodobolero 7ab4755
remove unneeded tpch extension
Bodobolero aadbdf1
previous commit caused compile errors
Bodobolero 76a4654
need another patch foro pg_duckdb which has its own cached copy of ht…
Bodobolero fa2657d
to install extensions we need additional trusted context (use case: S…
Bodobolero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
diff --git a/src/common/virtual_file_system.cpp b/src/common/virtual_file_system.cpp | ||
index 74892a4e05..60e9e7af88 100644 | ||
--- a/src/common/virtual_file_system.cpp | ||
+++ b/src/common/virtual_file_system.cpp | ||
@@ -173,7 +173,9 @@ void VirtualFileSystem::SetDisabledFileSystems(const vector<string> &names) { | ||
|
||
FileSystem &VirtualFileSystem::FindFileSystem(const string &path) { | ||
auto &fs = FindFileSystemInternal(path); | ||
- if (!disabled_file_systems.empty() && disabled_file_systems.find(fs.GetName()) != disabled_file_systems.end()) { | ||
+ // we allow LocalFileSystem access to duckdb itself (by specifiying trustedContext=true) | ||
+ // but not to duckdb users if disabled_file_systems='LocalFileSystem' | ||
+ if (!isTrustedContext && !disabled_file_systems.empty() && disabled_file_systems.find(fs.GetName()) != disabled_file_systems.end()) { | ||
throw PermissionException("File system %s has been disabled by configuration", fs.GetName()); | ||
} | ||
return fs; | ||
diff --git a/src/include/duckdb/common/file_system.hpp b/src/include/duckdb/common/file_system.hpp | ||
index 0b83c4f393..58d70889cf 100644 | ||
--- a/src/include/duckdb/common/file_system.hpp | ||
+++ b/src/include/duckdb/common/file_system.hpp | ||
@@ -256,6 +256,30 @@ public: | ||
DynamicCastCheck<TARGET>(this); | ||
return reinterpret_cast<const TARGET &>(*this); | ||
} | ||
+public: | ||
+ DUCKDB_API virtual void setTrusted(){ | ||
+ this->isTrustedContext = true; | ||
+ } | ||
+ DUCKDB_API virtual void setUntrusted(){ | ||
+ this->isTrustedContext = false; | ||
+ } | ||
+ | ||
+public: | ||
+ class TrustedContext { | ||
+ public: | ||
+ TrustedContext(FileSystem &fs) : fileSystem(fs) { | ||
+ fileSystem.setTrusted(); | ||
+ } | ||
+ ~TrustedContext() { | ||
+ fileSystem.setUntrusted(); | ||
+ } | ||
+ | ||
+ private: | ||
+ FileSystem &fileSystem; | ||
+ }; | ||
+ | ||
+protected: | ||
+ bool isTrustedContext = false; | ||
}; | ||
|
||
} // namespace duckdb | ||
diff --git a/src/include/duckdb/common/opener_file_system.hpp b/src/include/duckdb/common/opener_file_system.hpp | ||
index 2d35512b21..d1597173ee 100644 | ||
--- a/src/include/duckdb/common/opener_file_system.hpp | ||
+++ b/src/include/duckdb/common/opener_file_system.hpp | ||
@@ -143,6 +143,18 @@ public: | ||
vector<string> ListSubSystems() override { | ||
return GetFileSystem().ListSubSystems(); | ||
} | ||
+ | ||
+private: | ||
+ | ||
+ virtual void setTrusted() override { | ||
+ this->isTrustedContext = true; | ||
+ GetFileSystem().setTrusted(); | ||
+ } | ||
+ | ||
+ virtual void setUntrusted() override { | ||
+ this->isTrustedContext = false; | ||
+ GetFileSystem().setUntrusted(); | ||
+ } | ||
}; | ||
|
||
} // namespace duckdb | ||
diff --git a/src/main/extension/extension_install.cpp b/src/main/extension/extension_install.cpp | ||
index 1258d95ead..fc9ce1c77d 100644 | ||
--- a/src/main/extension/extension_install.cpp | ||
+++ b/src/main/extension/extension_install.cpp | ||
@@ -57,6 +57,7 @@ const vector<string> ExtensionHelper::PathComponents() { | ||
} | ||
|
||
duckdb::string ExtensionHelper::DefaultExtensionFolder(FileSystem &fs) { | ||
+ FileSystem::TrustedContext trusted(fs); | ||
string home_directory = fs.GetHomeDirectory(); | ||
// exception if the home directory does not exist, don't create whatever we think is home | ||
if (!fs.DirectoryExists(home_directory)) { | ||
diff --git a/src/main/extension/extension_load.cpp b/src/main/extension/extension_load.cpp | ||
index b0282a7103..c2765f97c6 100644 | ||
--- a/src/main/extension/extension_load.cpp | ||
+++ b/src/main/extension/extension_load.cpp | ||
@@ -293,6 +293,7 @@ bool ExtensionHelper::TryInitialLoad(DatabaseInstance &db, FileSystem &fs, const | ||
if (!db.config.options.enable_external_access) { | ||
throw PermissionException("Loading external extensions is disabled through configuration"); | ||
} | ||
+ FileSystem::TrustedContext trusted(fs); | ||
auto filename = fs.ConvertSeparators(extension); | ||
|
||
bool direct_load; |
Oops, something went wrong.
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.
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.
I wonder, is it better to keep these grants as a patch for https://github.com/duckdb/pg_duckdb/blob/v0.2.0/sql/pg_duckdb--0.1.0--0.2.0.sql to have everything in one place?
Either way, is there anything else that blocks us from adding this into image? @Bodobolero (thanks for your fixes)
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.
if you set disabled_filesystems=‘LocalFileSystem’ which is necessary to fix the security hole S3 access still doesn’t work.
I will see if I find time today to continue working on the patch.