commit efec9f040843d1de2fc52f5ce0d020478a5bc75d Author: Jacob Champion Date: Mon Feb 28 10:28:51 2022 -0800 squash! Add API to retrieve authn_id from SQL diff --git a/src/backend/utils/adt/name.c b/src/backend/utils/adt/name.c index b892d25c29..662a7943ed 100644 --- a/src/backend/utils/adt/name.c +++ b/src/backend/utils/adt/name.c @@ -258,7 +258,7 @@ namestrcmp(Name name, const char *str) /* - * SQL-functions CURRENT_USER, SESSION_USER, SESSION_AUTHN_ID + * SQL-functions CURRENT_USER, SESSION_USER, PG_SESSION_AUTHN_ID */ Datum current_user(PG_FUNCTION_ARGS) @@ -273,7 +273,7 @@ session_user(PG_FUNCTION_ARGS) } Datum -session_authn_id(PG_FUNCTION_ARGS) +pg_session_authn_id(PG_FUNCTION_ARGS) { if (!MyProcPort || !MyProcPort->authn_id) PG_RETURN_NULL(); diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 14194afe1c..3787b8edaf 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 202202251 +#define CATALOG_VERSION_NO 202202281 #endif diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 51e0d24f01..45326a2fe5 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -1509,8 +1509,8 @@ proname => 'session_user', provolatile => 's', prorettype => 'name', proargtypes => '', prosrc => 'session_user' }, { oid => '9774', descr => 'session authenticated identity', - proname => 'session_authn_id', provolatile => 's', prorettype => 'text', - proargtypes => '', prosrc => 'session_authn_id' }, + proname => 'pg_session_authn_id', provolatile => 's', proparallel => 'r', + prorettype => 'text', proargtypes => '', prosrc => 'pg_session_authn_id' }, { oid => '744', proname => 'array_eq', prorettype => 'bool', diff --git a/src/test/authentication/t/001_password.pl b/src/test/authentication/t/001_password.pl index 2aa28ed547..1edac8d588 100644 --- a/src/test/authentication/t/001_password.pl +++ b/src/test/authentication/t/001_password.pl @@ -83,7 +83,7 @@ test_role($node, 'md5_role', 'trust', 0, log_unlike => [qr/connection authenticated:/]); my $res = $node->safe_psql('postgres', - "SELECT session_authn_id() IS NULL;" + "SELECT pg_session_authn_id() IS NULL;" ); is($res, 't', "users with trust authentication have NULL authn_id"); @@ -97,7 +97,7 @@ test_role($node, 'md5_role', 'password', 0, [qr/connection authenticated: identity="md5_role" method=password/]); $res = $node->safe_psql('postgres', - "SELECT session_authn_id();", + "SELECT pg_session_authn_id();", connstr => "user=md5_role" ); is($res, 'md5_role', "users with md5 authentication have authn_id matching role name"); diff --git a/src/test/ssl/t/001_ssltests.pl b/src/test/ssl/t/001_ssltests.pl index 5c5b16fbe7..79ef7b46f1 100644 --- a/src/test/ssl/t/001_ssltests.pl +++ b/src/test/ssl/t/001_ssltests.pl @@ -443,6 +443,13 @@ $node->connect_ok( qr/connection authenticated: identity="CN=ssltestuser-dn,OU=Testing,OU=Engineering,O=PGDG" method=cert/ ],); +# Sanity-check pg_session_authn_id() for long ID strings +my $res = $node->safe_psql('postgres', + "SELECT pg_session_authn_id();", + connstr => "$dn_connstr user=ssltestuser sslcert=ssl/client-dn.crt sslkey=$key{'client-dn.key'}", +); +is($res, "CN=ssltestuser-dn,OU=Testing,OU=Engineering,O=PGDG", "users with cert authentication have entire DN as authn_id"); + # same thing but with a regex $dn_connstr = "$common_connstr dbname=certdb_dn_re";