1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Support the same patterns for pg-user in pg_ident.conf as in pg_hba.conf

While pg_hba.conf has support for non-literal username matches, and
this commit extends the capabilities that are supported for the
PostgreSQL user listed in an ident entry part of pg_ident.conf, with
support for:
1. The "all" keyword, where all the requested users are allowed.
2. Membership checks using the + prefix.
3. Using a regex to match against multiple roles.

1. is a feature that has been requested by Jelte Fennema, 2. something
that has been mentioned independently by Andrew Dunstan, and 3. is
something I came up with while discussing how to extend the first one,
whose implementation is facilitated by 8fea868.

This allows matching certain system users against many different
postgres users with a single line in pg_ident.conf.  Without this, one
would need one line for each of the postgres users that a system user
can log in as, which can be cumbersome to maintain.

Tests are added to the TAP test of peer authentication to provide
coverage for all that.

Note that this introduces a set of backward-incompatible changes to be
able to detect the new patterns, for the following cases:
- A role named "all".
- A role prefixed with '+' characters, which is something that would not
have worked in HBA entries anyway.
- A role prefixed by a slash character, similarly to 8fea868.
Any of these can be still be handled by using quotes in the Postgres
role defined in an ident entry.

A huge advantage of this change is that the code applies the same checks
for the Postgres roles in HBA and ident entries, via the common routine
check_role().

**This compatibility change should be mentioned in the release notes.**

Author: Jelte Fennema
Discussion: https://postgr.es/m/DBBPR83MB0507FEC2E8965012990A80D0F7FC9@DBBPR83MB0507.EURPRD83.prod.outlook.com
This commit is contained in:
Michael Paquier
2023-01-20 11:21:55 +09:00
parent 74739d1d3f
commit efb6f4a4f9
3 changed files with 246 additions and 39 deletions

View File

@ -941,7 +941,22 @@ local db1,db2,@demodbs all md5
implying that they are equivalent. The connection will be allowed if
there is any map entry that pairs the user name obtained from the
external authentication system with the database user name that the
user has requested to connect as.
user has requested to connect as. The value <literal>all</literal>
can be used as the <replaceable>database-username</replaceable> to specify
that if the <replaceable>system-user</replaceable> matches, then this user
is allowed to log in as any of the existing database users. Quoting
<literal>all</literal> makes the keyword lose its special meaning.
</para>
<para>
If the <replaceable>database-username</replaceable> begins with a
<literal>+</literal> character, then the operating system user can login as
any user belonging to that role, similarly to how user names beginning with
<literal>+</literal> are treated in <literal>pg_hba.conf</literal>.
Thus, a <literal>+</literal> mark means <quote>match any of the roles that
are directly or indirectly members of this role</quote>, while a name
without a <literal>+</literal> mark matches only that specific role. Quoting
a username starting with a <literal>+</literal> makes the
<literal>+</literal> lose its special meaning.
</para>
<para>
If the <replaceable>system-username</replaceable> field starts with a slash (<literal>/</literal>),
@ -964,6 +979,16 @@ mymap /^(.*)@otherdomain\.com$ guest
<literal>\1</literal> <emphasis>does not</emphasis> make
<literal>\1</literal> lose its special meaning.
</para>
<para>
If the <replaceable>database-username</replaceable> field starts with
a slash (<literal>/</literal>), the remainder of the field is treated
as a regular expression (see <xref linkend="posix-syntax-details"/>
for details of <productname>PostgreSQL</productname>'s regular
expression syntax. It is not possible to use <literal>\1</literal>
to use a capture from regular expression on
<replaceable>system-username</replaceable> for a regular expression
on <replaceable>database-username</replaceable>.
</para>
<tip>
<para>