Skip to content

Commit 50531bf

Browse files
authored
Merge pull request #383 from Mytherin/dontleaksecret
Fix #368: display only attach path in connection error message, instead of the full DSN that is used to connect
2 parents 6dabd95 + b128535 commit 50531bf

File tree

10 files changed

+28
-12
lines changed

10 files changed

+28
-12
lines changed

.github/workflows/Linux.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ jobs:
2727
VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake
2828

2929
steps:
30+
- name: Free disk space 1
31+
uses: endersonmenezes/[email protected]
32+
continue-on-error: true
33+
with:
34+
# remove_android: true # ~9.5GB in #52s
35+
# remove_dotnet: true
36+
remove_haskell: true # ~6.5GB in ~3s
37+
remove_tool_cache: true # ~4.8GB in ~17s
38+
# remove_swap: true
39+
# remove_packages_one_command: true # ~7.5 GB in ~94s
40+
testing: false
41+
3042
- name: Install required ubuntu packages
3143
run: |
3244
sudo apt-get update -y -qq

src/include/postgres_connection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class PostgresConnection {
4444
PostgresConnection &operator=(PostgresConnection &&) noexcept;
4545

4646
public:
47-
static PostgresConnection Open(const string &connection_string);
47+
static PostgresConnection Open(const string &dsn, const string &attach_path);
4848
void Execute(const string &query);
4949
unique_ptr<PostgresResult> TryQuery(const string &query, optional_ptr<string> error_message = nullptr);
5050
unique_ptr<PostgresResult> Query(const string &query);

src/include/postgres_scanner.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct PostgresBindData : public FunctionData {
3838

3939
idx_t pages_per_task = DEFAULT_PAGES_PER_TASK;
4040
string dsn;
41+
string attach_path;
4142

4243
bool requires_materialization = true;
4344
bool can_use_main_thread = true;

src/include/postgres_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ enum class PostgresIsolationLevel { READ_COMMITTED, REPEATABLE_READ, SERIALIZABL
5858

5959
class PostgresUtils {
6060
public:
61-
static PGconn *PGConnect(const string &dsn);
61+
static PGconn *PGConnect(const string &dsn, const string &attach_path);
6262

6363
static LogicalType ToPostgresType(const LogicalType &input);
6464
static LogicalType TypeToLogicalType(optional_ptr<PostgresTransaction> transaction,

src/postgres_attach.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void AttachFunction(ClientContext &context, TableFunctionInput &data_p, D
4747
return;
4848
}
4949

50-
auto conn = PostgresConnection::Open(data.dsn);
50+
auto conn = PostgresConnection::Open(data.dsn, data.dsn);
5151
auto dconn = Connection(context.db->GetDatabase(context));
5252
auto fetch_table_query = StringUtil::Format(
5353
R"(

src/postgres_connection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ PostgresConnection &PostgresConnection::operator=(PostgresConnection &&other) no
4040
return *this;
4141
}
4242

43-
PostgresConnection PostgresConnection::Open(const string &connection_string) {
43+
PostgresConnection PostgresConnection::Open(const string &dsn, const string &attach_path) {
4444
PostgresConnection result;
45-
result.connection = make_shared_ptr<OwnedPostgresConnection>(PostgresUtils::PGConnect(connection_string));
46-
result.dsn = connection_string;
45+
result.connection = make_shared_ptr<OwnedPostgresConnection>(PostgresUtils::PGConnect(dsn, attach_path));
46+
result.dsn = dsn;
4747
return result;
4848
}
4949

src/postgres_scanner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ static unique_ptr<FunctionData> PostgresBind(ClientContext &context, TableFuncti
177177
bind_data->dsn = input.inputs[0].GetValue<string>();
178178
bind_data->schema_name = input.inputs[1].GetValue<string>();
179179
bind_data->table_name = input.inputs[2].GetValue<string>();
180+
bind_data->attach_path = bind_data->dsn;
180181

181-
auto con = PostgresConnection::Open(bind_data->dsn);
182+
auto con = PostgresConnection::Open(bind_data->dsn, bind_data->attach_path);
182183
auto version = con.GetPostgresVersion();
183184
// query the table schema so we can interpret the bits in the pages
184185
auto info = PostgresTableSet::GetTableInfo(con, bind_data->schema_name, bind_data->table_name);
@@ -317,7 +318,7 @@ static unique_ptr<GlobalTableFunctionState> PostgresInitGlobalState(ClientContex
317318
bind_data.use_transaction ? transaction.GetConnection() : transaction.GetConnectionWithoutTransaction();
318319
result->SetConnection(con.GetConnection());
319320
} else {
320-
auto con = PostgresConnection::Open(bind_data.dsn);
321+
auto con = PostgresConnection::Open(bind_data.dsn, bind_data.attach_path);
321322
if (bind_data.use_transaction) {
322323
PostgresScanConnect(con, string());
323324
}
@@ -401,7 +402,7 @@ bool PostgresGlobalState::TryOpenNewConnection(ClientContext &context, PostgresL
401402
}
402403
lstate.connection = PostgresConnection(lstate.pool_connection.GetConnection().GetConnection());
403404
} else {
404-
lstate.connection = PostgresConnection::Open(bind_data.dsn);
405+
lstate.connection = PostgresConnection::Open(bind_data.dsn, bind_data.attach_path);
405406
}
406407
PostgresScanConnect(lstate.connection, snapshot);
407408
return true;

src/postgres_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ namespace duckdb {
88
static void PGNoticeProcessor(void *arg, const char *message) {
99
}
1010

11-
PGconn *PostgresUtils::PGConnect(const string &dsn) {
11+
PGconn *PostgresUtils::PGConnect(const string &dsn, const string &attach_path) {
1212
PGconn *conn = PQconnectdb(dsn.c_str());
1313

1414
// both PQStatus and PQerrorMessage check for nullptr
1515
if (PQstatus(conn) == CONNECTION_BAD) {
16-
throw IOException("Unable to connect to Postgres at %s: %s", dsn, string(PQerrorMessage(conn)));
16+
throw IOException("Unable to connect to Postgres at \"%s\": %s", attach_path, string(PQerrorMessage(conn)));
1717
}
1818
PQsetNoticeProcessor(conn, PGNoticeProcessor, nullptr);
1919
return conn;

src/storage/postgres_connection_pool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ PostgresPoolConnection PostgresConnectionPool::GetConnectionInternal() {
5454
}
5555

5656
// no cached connections left but there is space to open a new one - open it
57-
return PostgresPoolConnection(this, PostgresConnection::Open(postgres_catalog.connection_string));
57+
return PostgresPoolConnection(
58+
this, PostgresConnection::Open(postgres_catalog.connection_string, postgres_catalog.attach_path));
5859
}
5960

6061
PostgresPoolConnection PostgresConnectionPool::ForceGetConnection() {

src/storage/postgres_table_entry.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ TableFunction PostgresTableEntry::GetScanFunction(ClientContext &context, unique
4545
result->schema_name = schema.name;
4646
result->table_name = name;
4747
result->dsn = transaction.GetDSN();
48+
result->attach_path = pg_catalog.attach_path;
4849
result->SetCatalog(pg_catalog);
4950
result->SetTable(*this);
5051
for (auto &col : columns.Logical()) {

0 commit comments

Comments
 (0)