postgres_fdw: use_scram_passthrough on user mapping is ignored when also set on server

Started by Fujii Masao6 months ago9 messageshackers
Jump to latest
#1Fujii Masao
masao.fujii@gmail.com

Hi,

use_scram_passthrough can be specified both on a foreign server and
on a user mapping. I found that when both are specified, currently
the server-level setting overrides the user mapping setting. Is this
precedence intentional?

That seems inconsistent with the usual expectation that foreign server
options act as shared defaults, while user mapping options provide
per-user overrides. If the same option is specified in both places,
I would expect the user mapping setting to take precedence. Thoughts?

If the current behavior is intentional, I'd like to document the precedence
when use_scram_passthrough is specified in both a foreign server and
a user mapping. Otherwise, I'd like to change postgres_fdw to prefer
the user mapping setting and update the documentation accordingly.

Regards,

--
Fujii Masao

#2Matheus Alcantara
matheusssilv97@gmail.com
In reply to: Fujii Masao (#1)
Re: postgres_fdw: use_scram_passthrough on user mapping is ignored when also set on server

Hi,

On Thu May 14, 2026 at 2:57 PM -03, Fujii Masao wrote:

use_scram_passthrough can be specified both on a foreign server and
on a user mapping. I found that when both are specified, currently
the server-level setting overrides the user mapping setting. Is this
precedence intentional?

That seems inconsistent with the usual expectation that foreign server
options act as shared defaults, while user mapping options provide
per-user overrides. If the same option is specified in both places,
I would expect the user mapping setting to take precedence. Thoughts?

If the current behavior is intentional, I'd like to document the precedence
when use_scram_passthrough is specified in both a foreign server and
a user mapping. Otherwise, I'd like to change postgres_fdw to prefer
the user mapping setting and update the documentation accordingly.

I agree that that user mapping setting should take precedence. The
current behavior seems not correct since we are not able to
enable/disable the scram passthrough to a specific user mapping.

dblink also implement the same behavior, so I think that it should also
be changed as postgres_fdw.

The attached patches implement this change for postgres_fdw and dblink.

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

Attachments:

v1-0001-postgres_fdw-Allow-user-mapping-to-override-use_s.patchtext/plain; charset=utf-8; name=v1-0001-postgres_fdw-Allow-user-mapping-to-override-use_s.patchDownload+35-4
v1-0002-dblink-Allow-user-mapping-to-override-use_scram_p.patchtext/plain; charset=utf-8; name=v1-0002-dblink-Allow-user-mapping-to-override-use_scram_p.patchDownload+32-7
#3Fujii Masao
masao.fujii@gmail.com
In reply to: Matheus Alcantara (#2)
Re: postgres_fdw: use_scram_passthrough on user mapping is ignored when also set on server

On Fri, May 15, 2026 at 5:19 AM Matheus Alcantara
<matheusssilv97@gmail.com> wrote:

Hi,

On Thu May 14, 2026 at 2:57 PM -03, Fujii Masao wrote:

use_scram_passthrough can be specified both on a foreign server and
on a user mapping. I found that when both are specified, currently
the server-level setting overrides the user mapping setting. Is this
precedence intentional?

That seems inconsistent with the usual expectation that foreign server
options act as shared defaults, while user mapping options provide
per-user overrides. If the same option is specified in both places,
I would expect the user mapping setting to take precedence. Thoughts?

If the current behavior is intentional, I'd like to document the precedence
when use_scram_passthrough is specified in both a foreign server and
a user mapping. Otherwise, I'd like to change postgres_fdw to prefer
the user mapping setting and update the documentation accordingly.

I agree that that user mapping setting should take precedence. The
current behavior seems not correct since we are not able to
enable/disable the scram passthrough to a specific user mapping.

dblink also implement the same behavior, so I think that it should also
be changed as postgres_fdw.

The attached patches implement this change for postgres_fdw and dblink.

Thanks for the patches! They look good to me.

One minor comment: in UseScramPassthrough() in postgres_fdw/connection.c
and dblink.c, how about adding a comment like the following to clarify
the option precedence?

/*
* Return whether SCRAM pass-through is enabled.
*
* If use_scram_passthrough is specified in both the foreign server
* and the user mapping, the user mapping setting takes precedence.
*/

Also, while reviewing the use_scram_passthrough handling in dblink,
I found a separate issue: the option can be set via
ALTER FOREIGN DATA WRAPPER dblink_fdw, but that setting does not
seem to have any effect. Is this a bug? Like postgres_fdw, also in dblink,
we should disallow the option to be set at the foreign-data-wrapper level?
If yes, I think it would be better to address that as a separate patch.
Thought?

Regards,

--
Fujii Masao

#4Matheus Alcantara
matheusssilv97@gmail.com
In reply to: Fujii Masao (#3)
Re: postgres_fdw: use_scram_passthrough on user mapping is ignored when also set on server

On Fri May 15, 2026 at 1:29 AM -03, Fujii Masao wrote:

The attached patches implement this change for postgres_fdw and dblink.

Thanks for the patches! They look good to me.

One minor comment: in UseScramPassthrough() in postgres_fdw/connection.c
and dblink.c, how about adding a comment like the following to clarify
the option precedence?

/*
* Return whether SCRAM pass-through is enabled.
*
* If use_scram_passthrough is specified in both the foreign server
* and the user mapping, the user mapping setting takes precedence.
*/

Sounds good, fixed.

Also, while reviewing the use_scram_passthrough handling in dblink,
I found a separate issue: the option can be set via
ALTER FOREIGN DATA WRAPPER dblink_fdw, but that setting does not
seem to have any effect. Is this a bug? Like postgres_fdw, also in dblink,
we should disallow the option to be set at the foreign-data-wrapper level?
If yes, I think it would be better to address that as a separate patch.
Thought?

Yeah, good catch, this is from 3642df265d0. The problem is that
dblink_fdw_validator() was changed to call is_valid_dblink_fdw_option()
instead of is_valid_dblink_option() to make CRETE SERVER ... OPTIONS
(use_scram_passthrough '...'); works but I miss the fact that it's also
used by ALTER FOREIGN DATA WRAPPER. The new attached 0003 fix this by
only checking the fdw options when the validator context is from foreign
server or user mapping.

Are you considering backporting these patches? I think that 0003 is
good, not sure about 0001 and 0002.

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

Attachments:

v2-0001-postgres_fdw-Allow-user-mapping-to-override-use_s.patchtext/plain; charset=utf-8; name=v2-0001-postgres_fdw-Allow-user-mapping-to-override-use_s.patchDownload+41-4
v2-0002-dblink-Allow-user-mapping-to-override-use_scram_p.patchtext/plain; charset=utf-8; name=v2-0002-dblink-Allow-user-mapping-to-override-use_scram_p.patchDownload+38-7
v2-0003-dblink-Reject-use_scram_passthrough-option-on-for.patchtext/plain; charset=utf-8; name=v2-0003-dblink-Reject-use_scram_passthrough-option-on-for.patchDownload+22-3
#5Fujii Masao
masao.fujii@gmail.com
In reply to: Matheus Alcantara (#4)
Re: postgres_fdw: use_scram_passthrough on user mapping is ignored when also set on server

On Sat, May 16, 2026 at 12:46 AM Matheus Alcantara
<matheusssilv97@gmail.com> wrote:

/*
* Return whether SCRAM pass-through is enabled.
*
* If use_scram_passthrough is specified in both the foreign server
* and the user mapping, the user mapping setting takes precedence.
*/

Sounds good, fixed.

Thanks!

Yeah, good catch, this is from 3642df265d0. The problem is that
dblink_fdw_validator() was changed to call is_valid_dblink_fdw_option()
instead of is_valid_dblink_option() to make CRETE SERVER ... OPTIONS
(use_scram_passthrough '...'); works but I miss the fact that it's also
used by ALTER FOREIGN DATA WRAPPER. The new attached 0003 fix this by
only checking the fdw options when the validator context is from foreign
server or user mapping.

Thanks for the patches!

Neither dblink nor postgres_fdw seems to have tests checking whether options
are specified at the proper object level (foreign server, user mapping, etc.).
So adding the test for ALTER FOREIGN DATA WRAPPER ...
(use_scram_passthrough ...)
seems a bit overkill to me. Also, even if we decide to add such a test,
it might be simpler to put it in sql/dblink.sql rather than as a TAP test.
Thoughts?

Are you considering backporting these patches? I think that 0003 is
good, not sure about 0001 and 0002.

I assume your concern is that v18 was already released with the current
behavior, where the server-level use_scram_passthrough setting overrides
the user-mapping-level one. Backpatching the behavior change to v18 could
therefore affect existing users relying on that behavior, right?

If the documentation had clearly stated that the user-mapping-level setting
takes precedence, we could reasonably treat the current behavior as a bug
and change it even in v18. But since there is no such documentation,
I understand the hesitation.

That said, I'm feeling tempted to backpatch the change to v18, because having
only v18 behave differently seems odd and potentially confusing...

The issue addressed by patch 0003 may have a similar concern. However,
since use_scram_passthrough set on dblink_fdw currently has no effect
even if there are existing users depending on that, it seems acceptable to
change that behavior in v18. Is that your thinking?

Regards,

--
Fujii Masao

#6Matheus Alcantara
matheusssilv97@gmail.com
In reply to: Fujii Masao (#5)
Re: postgres_fdw: use_scram_passthrough on user mapping is ignored when also set on server

On Mon May 18, 2026 at 5:01 AM -03, Fujii Masao wrote:

Thanks for the patches!

Neither dblink nor postgres_fdw seems to have tests checking whether options
are specified at the proper object level (foreign server, user mapping, etc.).
So adding the test for ALTER FOREIGN DATA WRAPPER ...
(use_scram_passthrough ...)
seems a bit overkill to me. Also, even if we decide to add such a test,
it might be simpler to put it in sql/dblink.sql rather than as a TAP test.
Thoughts?

I think that the test is worth to have to avoid such issues in the
future again, but I agree that adding as a TAP test is overkill. I've
moved to sql/dblink.sql on the new attached version.

Do you think that we need to add such test for postgres_fdw too?

Are you considering backporting these patches? I think that 0003 is
good, not sure about 0001 and 0002.

I assume your concern is that v18 was already released with the current
behavior, where the server-level use_scram_passthrough setting overrides
the user-mapping-level one. Backpatching the behavior change to v18 could
therefore affect existing users relying on that behavior, right?

Yes, you are right, this was my main concern.

If the documentation had clearly stated that the user-mapping-level setting
takes precedence, we could reasonably treat the current behavior as a bug
and change it even in v18. But since there is no such documentation,
I understand the hesitation.

Yeah, we don't have any documentation about this on 18, but we do have
for sslkey and sslcert where in postgres-fdw.sgml we have the following:
sslkey and sslcert - these may appear in either or both a connection
and a user mapping. If both are present, the user mapping setting
overrides the connection setting.

So I think that is desirable to have the same behavior for
use_scram_passthrough.

That said, I'm feeling tempted to backpatch the change to v18, because having
only v18 behave differently seems odd and potentially confusing...

I agree with this.

The issue addressed by patch 0003 may have a similar concern. However,
since use_scram_passthrough set on dblink_fdw currently has no effect
even if there are existing users depending on that, it seems acceptable to
change that behavior in v18. Is that your thinking?

Yes, you are right. Even if there are users that are relying on this it's
not working, so we at lest make it explicitly and avoid confusions.

Thank you for reviewing the patches!

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

Attachments:

v3-0001-postgres_fdw-Allow-user-mapping-to-override-use_s.patchtext/plain; charset=utf-8; name=v3-0001-postgres_fdw-Allow-user-mapping-to-override-use_s.patchDownload+41-4
v3-0002-dblink-Allow-user-mapping-to-override-use_scram_p.patchtext/plain; charset=utf-8; name=v3-0002-dblink-Allow-user-mapping-to-override-use_scram_p.patchDownload+38-7
v3-0003-dblink-Reject-use_scram_passthrough-option-on-for.patchtext/plain; charset=utf-8; name=v3-0003-dblink-Reject-use_scram_passthrough-option-on-for.patchDownload+15-3
#7Fujii Masao
masao.fujii@gmail.com
In reply to: Matheus Alcantara (#6)
Re: postgres_fdw: use_scram_passthrough on user mapping is ignored when also set on server

On Mon, May 18, 2026 at 11:42 PM Matheus Alcantara
<matheusssilv97@gmail.com> wrote:

I think that the test is worth to have to avoid such issues in the
future again, but I agree that adding as a TAP test is overkill. I've
moved to sql/dblink.sql on the new attached version.

Do you think that we need to add such test for postgres_fdw too?

No, I don't think so.

In dblink, use_scram_passthrough is handled by a dblink-specific validation
path, and patch 0003 fixes that specific code path. So it might be worth
adding such test for dblink.

In postgres_fdw, however, this option is handled by the generic option/context
validation machinery, not by any special-case code. We already have tests for
context-sensitive option validation there. So adding such test for postgres_fdw
would be mostly redundant, I think. Thought?

Yeah, we don't have any documentation about this on 18, but we do have
for sslkey and sslcert where in postgres-fdw.sgml we have the following:
sslkey and sslcert - these may appear in either or both a connection
and a user mapping. If both are present, the user mapping setting
overrides the connection setting.

So I think that is desirable to have the same behavior for
use_scram_passthrough.

Agreed. I'm therefore thinking of backpatching patches 0001 and 0002 to v18.

Even in v18, this change is very narrow. It only affects cases where
use_scram_passthrough is specified at both the server and user-mapping levels
with conflicting values. In such cases, the natural interpretation is that
the user-mapping setting is intended to override the server-level setting;
otherwise, there would be little reason to specify conflicting values.

Given the limited impact, leaving v18 as the only branch with different
semantics for a feature introduced in v18 seems more undesirable and
potentially confusing. So I think backpatching to v18 makes sense.

Regards,

--
Fujii Masao

#8Matheus Alcantara
matheusssilv97@gmail.com
In reply to: Fujii Masao (#7)
Re: postgres_fdw: use_scram_passthrough on user mapping is ignored when also set on server

On 22/05/26 22:58, Fujii Masao wrote:

On Mon, May 18, 2026 at 11:42 PM Matheus Alcantara
<matheusssilv97@gmail.com> wrote:

I think that the test is worth to have to avoid such issues in the
future again, but I agree that adding as a TAP test is overkill. I've
moved to sql/dblink.sql on the new attached version.

Do you think that we need to add such test for postgres_fdw too?

No, I don't think so.

In dblink, use_scram_passthrough is handled by a dblink-specific validation
path, and patch 0003 fixes that specific code path. So it might be worth
adding such test for dblink.

In postgres_fdw, however, this option is handled by the generic option/context
validation machinery, not by any special-case code. We already have tests for
context-sensitive option validation there. So adding such test for postgres_fdw
would be mostly redundant, I think. Thought?

Agree, it make sense.

Yeah, we don't have any documentation about this on 18, but we do have
for sslkey and sslcert where in postgres-fdw.sgml we have the following:
sslkey and sslcert - these may appear in either or both a connection
and a user mapping. If both are present, the user mapping setting
overrides the connection setting.

So I think that is desirable to have the same behavior for
use_scram_passthrough.

Agreed. I'm therefore thinking of backpatching patches 0001 and 0002 to v18.

Even in v18, this change is very narrow. It only affects cases where
use_scram_passthrough is specified at both the server and user-mapping levels
with conflicting values. In such cases, the natural interpretation is that
the user-mapping setting is intended to override the server-level setting;
otherwise, there would be little reason to specify conflicting values.

Given the limited impact, leaving v18 as the only branch with different
semantics for a feature introduced in v18 seems more undesirable and
potentially confusing. So I think backpatching to v18 makes sense.

+1

Thank you for finding the issue and reviewing the patch.

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

#9Fujii Masao
masao.fujii@gmail.com
In reply to: Matheus Alcantara (#8)
Re: postgres_fdw: use_scram_passthrough on user mapping is ignored when also set on server

On Sun, May 24, 2026 at 1:46 AM Matheus Alcantara
<matheusssilv97@gmail.com> wrote:

Thank you for finding the issue and reviewing the patch.

I've pushed the patches. Thanks!

Regards,

--
Fujii Masao