Skip to content

Commit c2a5681

Browse files
authored
Merge pull request duckdb#116 from Mytherin/externalaccess
Disable attaching new MySQL databases when enable external access is disabled
2 parents 547bceb + ddf3136 commit c2a5681

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/mysql_storage.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ namespace duckdb {
99

1010
static unique_ptr<Catalog> MySQLAttach(StorageExtensionInfo *storage_info, ClientContext &context, AttachedDatabase &db,
1111
const string &name, AttachInfo &info, AccessMode access_mode) {
12+
auto &config = DBConfig::GetConfig(context);
13+
if (!config.options.enable_external_access) {
14+
throw PermissionException("Attaching MySQL databases is disabled through configuration");
15+
}
1216
// check if we have a secret provided
1317
string secret_name;
1418
for (auto &entry : info.options) {

src/storage/mysql_catalog.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
namespace duckdb {
1212

13-
MySQLCatalog::MySQLCatalog(AttachedDatabase &db_p, string connection_string_p, string attach_path_p, AccessMode access_mode)
14-
: Catalog(db_p), connection_string(std::move(connection_string_p)), attach_path(std::move(attach_path_p)), access_mode(access_mode), schemas(*this) {
13+
MySQLCatalog::MySQLCatalog(AttachedDatabase &db_p, string connection_string_p, string attach_path_p,
14+
AccessMode access_mode)
15+
: Catalog(db_p), connection_string(std::move(connection_string_p)), attach_path(std::move(attach_path_p)),
16+
access_mode(access_mode), schemas(*this) {
1517
default_schema = MySQLUtils::ParseConnectionParameters(connection_string).db;
1618
// try to connect
1719
auto connection = MySQLConnection::Open(connection_string);

test/sql/attach_external_access.test

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# name: test/sql/attach_external_access.test
2+
# description: Test that we cannot attach new databases if external access is disabled
3+
# group: [storage]
4+
5+
require mysql_scanner
6+
7+
require-env MYSQL_TEST_DATABASE_AVAILABLE
8+
9+
statement ok
10+
SET enable_external_access=false
11+
12+
statement error
13+
ATTACH 'host=localhost user=root port=0 database=mysqlscanner' AS s1 (TYPE MYSQL_SCANNER)
14+
----
15+
disabled through configuration

0 commit comments

Comments
 (0)