From: aaron-congo (@aaron-congo) <noreply+aaron-congo@github.com>
To: aws/aws-advanced-jdbc-wrapper <noreply+aws-aws-advanced-jdbc-wrapper@github.com>
Subject: Re: [aws/aws-advanced-jdbc-wrapper] PR #2261: fix: use the built-in equality operator in KMS metadata and key SQL on PostgreSQL
Date: Thu, 19 Nov 2026 21:27:07 +0000
Message-ID: <gh-aws-aws-advanced-jdbc-wrapper-2261-rc4635339284@github.com> (raw)
In-Reply-To: <gh-aws-aws-advanced-jdbc-wrapper-2261-rc4634226809@github.com>
References: <gh-aws-aws-advanced-jdbc-wrapper-2261@github.com>
<gh-aws-aws-advanced-jdbc-wrapper-2261-rc4634226809@github.com>
(on wrapper/src/main/java/software/amazon/jdbc/plugin/encryption/metadata/MetadataManager.java:116)
Yes, that's intentional - the pin only happens on the connections the plugin opens for itself through `forceConnect`. For a `Connection` or `DataSource` the caller passes in (here and in `KeyManagementUtility`), we leave the session alone and rely on the SQL itself: every comparison uses `OPERATOR(pg_catalog.=)` / `OPERATOR(pg_catalog.>)` and every table name is schema-qualified. The casts, `ORDER BY` and `DISTINCT` come from the column types rather than the search_path, so there's nothing left in these statements for the session's search_path to change. On the plugin's own connections the pin is just defense in depth.
I don't think `SET LOCAL` works well for caller-owned connections:
- In autocommit mode, which is the usual case, `SET LOCAL` outside a transaction block has no effect (PostgreSQL just warns), so the next statement would still use the session's search_path.
- To make it stick we'd have to open a transaction on the caller's connection, set it, run the query and commit, which changes their transaction behavior.
- If the caller is already in a transaction, `SET LOCAL` would carry over to the rest of their statements in it, which is the session change we're trying to avoid.
On documentation: there's no gap for users to act on, so I'd rather guard it with tests. `MetadataManagerTest` and `KeyManagerTest` assert the qualified SQL, `FakeReencryptionDatabase` now fails on any plain `=` or `>` in PostgreSQL SQL from `KeyManagementUtility`, and the new integration test runs these lookups on a caller connection with a session-defined `=` and checks that the session's search_path is unchanged.