Skip to content

Disable attaching new Postgres databases when enable external access is disabled #294

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

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 16 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@

# Download the PostgreSQL source code
message(STATUS "Downloading PostgreSQL source code")
file(DOWNLOAD
file(
DOWNLOAD
"https://github.com/postgres/postgres/archive/refs/tags/REL_15_2.tar.gz"
${CMAKE_CURRENT_SOURCE_DIR}/pg.tar.gz
SHOW_PROGRESS
Expand All @@ -132,13 +133,12 @@

# Extract the PostgreSQL source code
message(STATUS "Extracting PostgreSQL source code")
file(ARCHIVE_EXTRACT INPUT ${CMAKE_CURRENT_SOURCE_DIR}/pg.tar.gz
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp)
file(ARCHIVE_EXTRACT INPUT ${CMAKE_CURRENT_SOURCE_DIR}/pg.tar.gz DESTINATION
${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp)

# Move out of root directory
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp/postgres-REL_15_2
${CMAKE_CURRENT_SOURCE_DIR}/postgres
)
${CMAKE_CURRENT_SOURCE_DIR}/postgres)

# Remove the tmp directory
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp)
Expand All @@ -157,46 +157,32 @@

# Check if configuration was successful
if(NOT PG_MKVCBUILD_RESULT EQUAL 0)
file(REMOVE_RECURSE postgres)
message(FATAL_ERROR "Failed to configure PostgreSQL source code for windows")
file(REMOVE_RECURSE postgres)
message(
FATAL_ERROR "Failed to configure PostgreSQL source code for windows")
endif()
else()
# On other platforms, use the configure script to configure the source code
set(ENV{CC} gcc)
set(ENV{CXX} g++)
execute_process(
COMMAND ./configure
--without-llvm
--without-icu
--without-tcl
--without-perl
--without-python
--without-gssapi
--without-pam
--without-bsd-auth
--without-ldap
--without-bonjour
--without-selinux
--without-systemd
--without-readline
--without-libxml
--without-libxslt
--without-zlib
--without-lz4
--without-openssl
COMMAND
./configure --without-llvm --without-icu --without-tcl --without-perl
--without-python --without-gssapi --without-pam --without-bsd-auth
--without-ldap --without-bonjour --without-selinux --without-systemd
--without-readline --without-libxml --without-libxslt --without-zlib
--without-lz4 --without-openssl
RESULT_VARIABLE PG_CONFIGURE_RESULT
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/postgres
)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/postgres)
# Check if configuration was successful
if(NOT PG_CONFIGURE_RESULT EQUAL 0)
file(REMOVE_RECURSE postgres)
message(FATAL_ERROR "Failed to configure PostgreSQL source code")
endif ()
endif()
endif()
message(STATUS "Finished setting up PostgreSQL source code!")
endif()


set(PARAMETERS "-no-warnings")
build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${ALL_OBJECT_FILES}
${LIBPG_SOURCES_FULLPATH})
Expand All @@ -207,7 +193,7 @@
postgres/src/interfaces/libpq ${OPENSSL_INCLUDE_DIR})

if(WIN32)
target_include_directories(

Check warning on line 196 in CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_amd64, x86_64, x64-osx)

Not disabling vptr sanitizer on M1 Macbook - set DISABLE_VPTR_SANITIZER

Check warning on line 196 in CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_arm64, arm64, arm64-osx)

Not disabling vptr sanitizer on M1 Macbook - set DISABLE_VPTR_SANITIZER
${TARGET_NAME}_loadable_extension
PRIVATE postgres/src/include/port/win32 postgres/src/port
postgres/src/include/port/win32_msvc)
Expand Down
3 changes: 2 additions & 1 deletion src/include/storage/postgres_catalog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class PostgresSchemaEntry;

class PostgresCatalog : public Catalog {
public:
explicit PostgresCatalog(AttachedDatabase &db_p, string connection_string, string attach_path, AccessMode access_mode, string schema_to_load);
explicit PostgresCatalog(AttachedDatabase &db_p, string connection_string, string attach_path,
AccessMode access_mode, string schema_to_load);
~PostgresCatalog();

string connection_string;
Expand Down
4 changes: 4 additions & 0 deletions src/postgres_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace duckdb {
static unique_ptr<Catalog> PostgresAttach(StorageExtensionInfo *storage_info, ClientContext &context,
AttachedDatabase &db, const string &name, AttachInfo &info,
AccessMode access_mode) {
auto &config = DBConfig::GetConfig(context);
if (!config.options.enable_external_access) {
throw PermissionException("Attaching Postgres databases is disabled through configuration");
}
string attach_path = info.path;

string secret_name;
Expand Down
15 changes: 15 additions & 0 deletions test/sql/storage/attach_external_access.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# name: test/sql/storage/attach_external_access.test
# description: Test that we cannot attach new databases if external access is disabled
# group: [storage]

require postgres_scanner

require-env POSTGRES_TEST_DATABASE_AVAILABLE

statement ok
SET enable_external_access=false

statement error
ATTACH 'dbname=postgresscanner' AS simple (TYPE POSTGRES)
----
disabled through configuration
Loading