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

Enterprise / PostgreSQL - Michael Paquier [] - 20 January 2023 02:21 UTC

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:

efb6f4a4f9 Support the same patterns for pg-user in pg_ident.conf as in pg_hba.conf
doc/src/sgml/client-auth.sgml | 27 +++++-
src/backend/libpq/hba.c | 98 ++++++++++++++-------
src/test/authentication/t/ | 160 ++++++++++++++++++++++++++++++++--
3 files changed, 246 insertions(+), 39 deletions(-)


  • Share