mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Introduce SYSTEM_USER
SYSTEM_USER is a reserved keyword of the SQL specification that, roughly described, is aimed at reporting some information about the system user who has connected to the database server. It may include implementation-specific information about the means by the user connected, like an authentication method. This commit implements SYSTEM_USER as of auth_method:identity, where "auth_method" is a keyword about the authentication method used to log into the server (like peer, md5, scram-sha-256, gss, etc.) and "identity" is the authentication identity as introduced by9afffcb
(peer sets authn to the OS user name, gss to the user principal, etc.). This format has been suggested by Tom Lane. Note that thanks tod951052
, SYSTEM_USER is available to parallel workers. Bump catalog version. Author: Bertrand Drouvot Reviewed-by: Jacob Champion, Joe Conway, Álvaro Herrera, Michael Paquier Discussion: https://postgr.es/m/7e692b8c-0b11-45db-1cad-3afc5b57409f@amazon.com
This commit is contained in:
@@ -72,6 +72,11 @@ $node->safe_psql('postgres',
|
||||
$node->safe_psql('postgres',
|
||||
"SET password_encryption='md5'; CREATE ROLE md5_role LOGIN PASSWORD 'pass';"
|
||||
);
|
||||
# Set up a table for tests of SYSTEM_USER.
|
||||
$node->safe_psql(
|
||||
'postgres',
|
||||
"CREATE TABLE sysuser_data (n) AS SELECT NULL FROM generate_series(1, 10);
|
||||
GRANT ALL ON sysuser_data TO md5_role;");
|
||||
$ENV{"PGPASSWORD"} = 'pass';
|
||||
|
||||
# For "trust" method, all users should be able to connect. These users are not
|
||||
@@ -82,6 +87,24 @@ test_role($node, 'scram_role', 'trust', 0,
|
||||
test_role($node, 'md5_role', 'trust', 0,
|
||||
log_unlike => [qr/connection authenticated:/]);
|
||||
|
||||
# SYSTEM_USER is null when not authenticated.
|
||||
my $res = $node->safe_psql('postgres', "SELECT SYSTEM_USER IS NULL;");
|
||||
is($res, 't', "users with trust authentication use SYSTEM_USER = NULL");
|
||||
|
||||
# Test SYSTEM_USER with parallel workers when not authenticated.
|
||||
$res = $node->safe_psql(
|
||||
'postgres', qq(
|
||||
SET min_parallel_table_scan_size TO 0;
|
||||
SET parallel_setup_cost TO 0;
|
||||
SET parallel_tuple_cost TO 0;
|
||||
SET max_parallel_workers_per_gather TO 2;
|
||||
|
||||
SELECT bool_and(SYSTEM_USER IS NOT DISTINCT FROM n) FROM sysuser_data;),
|
||||
connstr => "user=md5_role");
|
||||
is($res, 't',
|
||||
"users with trust authentication use SYSTEM_USER = NULL in parallel workers"
|
||||
);
|
||||
|
||||
# For plain "password" method, all users should also be able to connect.
|
||||
reset_pg_hba($node, 'password');
|
||||
test_role($node, 'scram_role', 'password', 0,
|
||||
@@ -120,6 +143,25 @@ test_role($node, 'md5_role', 'md5', 0,
|
||||
log_like =>
|
||||
[qr/connection authenticated: identity="md5_role" method=md5/]);
|
||||
|
||||
# Test SYSTEM_USER <> NULL with parallel workers.
|
||||
$node->safe_psql(
|
||||
'postgres',
|
||||
"TRUNCATE sysuser_data;
|
||||
INSERT INTO sysuser_data SELECT 'md5:md5_role' FROM generate_series(1, 10);",
|
||||
connstr => "user=md5_role");
|
||||
$res = $node->safe_psql(
|
||||
'postgres', qq(
|
||||
SET min_parallel_table_scan_size TO 0;
|
||||
SET parallel_setup_cost TO 0;
|
||||
SET parallel_tuple_cost TO 0;
|
||||
SET max_parallel_workers_per_gather TO 2;
|
||||
|
||||
SELECT bool_and(SYSTEM_USER IS NOT DISTINCT FROM n) FROM sysuser_data;),
|
||||
connstr => "user=md5_role");
|
||||
is($res, 't',
|
||||
"users with md5 authentication use SYSTEM_USER = md5:role in parallel workers"
|
||||
);
|
||||
|
||||
# Tests for channel binding without SSL.
|
||||
# Using the password authentication method; channel binding can't work
|
||||
reset_pg_hba($node, 'password');
|
||||
|
Reference in New Issue
Block a user