mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Invent pg_hba_file_rules view to show the content of pg_hba.conf.
This view is designed along the same lines as pg_file_settings, to wit it shows what is currently in the file, not what the postmaster has loaded as the active settings. That allows it to be used to pre-vet edits before issuing SIGHUP. As with the earlier view, go out of our way to allow errors in the file to be reflected in the view, to assist that use-case. (We might at some point invent a view to show the current active settings, but this is not that patch; and it's not trivial to do.) Haribabu Kommi, reviewed by Ashutosh Bapat, Michael Paquier, Simon Riggs, and myself Discussion: https://postgr.es/m/CAJrrPGerH4jiwpcXT1-46QXUDmNp2QDrG9+-Tek_xC8APHShYw@mail.gmail.com
This commit is contained in:
@ -7808,6 +7808,11 @@
|
|||||||
<entry>groups of database users</entry>
|
<entry>groups of database users</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
|
<row>
|
||||||
|
<entry><link linkend="view-pg-hba-file-rules"><structname>pg_hba_file_rules</structname></link></entry>
|
||||||
|
<entry>summary of client authentication configuration file contents</entry>
|
||||||
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><link linkend="view-pg-indexes"><structname>pg_indexes</structname></link></entry>
|
<entry><link linkend="view-pg-indexes"><structname>pg_indexes</structname></link></entry>
|
||||||
<entry>indexes</entry>
|
<entry>indexes</entry>
|
||||||
@ -8408,6 +8413,114 @@
|
|||||||
|
|
||||||
</sect1>
|
</sect1>
|
||||||
|
|
||||||
|
<sect1 id="view-pg-hba-file-rules">
|
||||||
|
<title><structname>pg_hba_file_rules</structname></title>
|
||||||
|
|
||||||
|
<indexterm zone="view-pg-hba-file-rules">
|
||||||
|
<primary>pg_hba_file_rules</primary>
|
||||||
|
</indexterm>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
The view <structname>pg_hba_file_rules</structname> provides a summary of
|
||||||
|
the contents of the client authentication configuration
|
||||||
|
file, <filename>pg_hba.conf</>. A row appears in this view for each
|
||||||
|
non-empty, non-comment line in the file, with annotations indicating
|
||||||
|
whether the rule could be applied successfully.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
This view can be helpful for checking whether planned changes in the
|
||||||
|
authentication configuration file will work, or for diagnosing a previous
|
||||||
|
failure. Note that this view reports on the <emphasis>current</> contents
|
||||||
|
of the file, not on what was last loaded by the server.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
By default, the <structname>pg_hba_file_rules</structname> view can be read
|
||||||
|
only by superusers.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<title><structname>pg_hba_file_rules</> Columns</title>
|
||||||
|
|
||||||
|
<tgroup cols="3">
|
||||||
|
<thead>
|
||||||
|
<row>
|
||||||
|
<entry>Name</entry>
|
||||||
|
<entry>Type</entry>
|
||||||
|
<entry>Description</entry>
|
||||||
|
</row>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<row>
|
||||||
|
<entry><structfield>line_number</structfield></entry>
|
||||||
|
<entry><structfield>integer</structfield></entry>
|
||||||
|
<entry>
|
||||||
|
Line number of this rule in <filename>pg_hba.conf</>
|
||||||
|
</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><structfield>type</structfield></entry>
|
||||||
|
<entry><structfield>text</structfield></entry>
|
||||||
|
<entry>Type of connection</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><structfield>database</structfield></entry>
|
||||||
|
<entry><structfield>text[]</structfield></entry>
|
||||||
|
<entry>List of database name(s) to which this rule applies</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><structfield>user_name</structfield></entry>
|
||||||
|
<entry><structfield>text[]</structfield></entry>
|
||||||
|
<entry>List of user and group name(s) to which this rule applies</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><structfield>address</structfield></entry>
|
||||||
|
<entry><structfield>text</structfield></entry>
|
||||||
|
<entry>
|
||||||
|
Host name or IP address, or one
|
||||||
|
of <literal>all</literal>, <literal>samehost</literal>,
|
||||||
|
or <literal>samenet</literal>, or null for local connections
|
||||||
|
</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><structfield>netmask</structfield></entry>
|
||||||
|
<entry><structfield>text</structfield></entry>
|
||||||
|
<entry>IP address mask, or null if not applicable</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><structfield>auth_method</structfield></entry>
|
||||||
|
<entry><type>text</type></entry>
|
||||||
|
<entry>Authentication method</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><structfield>options</structfield></entry>
|
||||||
|
<entry><type>text[]</type></entry>
|
||||||
|
<entry>Options specified for authentication method, if any</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><structfield>error</structfield></entry>
|
||||||
|
<entry><structfield>text</structfield></entry>
|
||||||
|
<entry>
|
||||||
|
If not null, an error message indicating why this
|
||||||
|
line could not be processed
|
||||||
|
</entry>
|
||||||
|
</row>
|
||||||
|
</tbody>
|
||||||
|
</tgroup>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
Usually, a row reflecting an incorrect entry will have values for only
|
||||||
|
the <structfield>line_number</> and <structfield>error</> fields.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
See <xref linkend="client-authentication"> for more information about
|
||||||
|
client authentication configuration.
|
||||||
|
</para>
|
||||||
|
</sect1>
|
||||||
|
|
||||||
<sect1 id="view-pg-indexes">
|
<sect1 id="view-pg-indexes">
|
||||||
<title><structname>pg_indexes</structname></title>
|
<title><structname>pg_indexes</structname></title>
|
||||||
|
|
||||||
|
@ -597,6 +597,24 @@ hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable>
|
|||||||
re-read the file.
|
re-read the file.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<note>
|
||||||
|
<para>
|
||||||
|
The preceding statement is not true on Microsoft Windows: there, any
|
||||||
|
changes in the <filename>pg_hba.conf</filename> file are immediately
|
||||||
|
applied by subsequent new connections.
|
||||||
|
</para>
|
||||||
|
</note>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
The system view
|
||||||
|
<link linkend="view-pg-hba-file-rules"><structname>pg_hba_file_rules</structname></link>
|
||||||
|
can be helpful for pre-testing changes to the <filename>pg_hba.conf</>
|
||||||
|
file, or for diagnosing problems if loading of the file did not have the
|
||||||
|
desired effects. Rows in the view with
|
||||||
|
non-null <structfield>error</structfield> fields indicate problems in the
|
||||||
|
corresponding lines of the file.
|
||||||
|
</para>
|
||||||
|
|
||||||
<tip>
|
<tip>
|
||||||
<para>
|
<para>
|
||||||
To connect to a particular database, a user must not only pass the
|
To connect to a particular database, a user must not only pass the
|
||||||
|
@ -459,6 +459,12 @@ CREATE VIEW pg_file_settings AS
|
|||||||
REVOKE ALL on pg_file_settings FROM PUBLIC;
|
REVOKE ALL on pg_file_settings FROM PUBLIC;
|
||||||
REVOKE EXECUTE ON FUNCTION pg_show_all_file_settings() FROM PUBLIC;
|
REVOKE EXECUTE ON FUNCTION pg_show_all_file_settings() FROM PUBLIC;
|
||||||
|
|
||||||
|
CREATE VIEW pg_hba_file_rules AS
|
||||||
|
SELECT * FROM pg_hba_file_rules() AS A;
|
||||||
|
|
||||||
|
REVOKE ALL on pg_hba_file_rules FROM PUBLIC;
|
||||||
|
REVOKE EXECUTE ON FUNCTION pg_hba_file_rules() FROM PUBLIC;
|
||||||
|
|
||||||
CREATE VIEW pg_timezone_abbrevs AS
|
CREATE VIEW pg_timezone_abbrevs AS
|
||||||
SELECT * FROM pg_timezone_abbrevs();
|
SELECT * FROM pg_timezone_abbrevs();
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -53,6 +53,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* yyyymmddN */
|
/* yyyymmddN */
|
||||||
#define CATALOG_VERSION_NO 201701251
|
#define CATALOG_VERSION_NO 201701301
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3076,6 +3076,8 @@ DATA(insert OID = 2084 ( pg_show_all_settings PGNSP PGUID 12 1 1000 0 0 f f f f
|
|||||||
DESCR("SHOW ALL as a function");
|
DESCR("SHOW ALL as a function");
|
||||||
DATA(insert OID = 3329 ( pg_show_all_file_settings PGNSP PGUID 12 1 1000 0 0 f f f f t t v s 0 0 2249 "" "{25,23,23,25,25,16,25}" "{o,o,o,o,o,o,o}" "{sourcefile,sourceline,seqno,name,setting,applied,error}" _null_ _null_ show_all_file_settings _null_ _null_ _null_ ));
|
DATA(insert OID = 3329 ( pg_show_all_file_settings PGNSP PGUID 12 1 1000 0 0 f f f f t t v s 0 0 2249 "" "{25,23,23,25,25,16,25}" "{o,o,o,o,o,o,o}" "{sourcefile,sourceline,seqno,name,setting,applied,error}" _null_ _null_ show_all_file_settings _null_ _null_ _null_ ));
|
||||||
DESCR("show config file settings");
|
DESCR("show config file settings");
|
||||||
|
DATA(insert OID = 3401 ( pg_hba_file_rules PGNSP PGUID 12 1 1000 0 0 f f f f t t v s 0 0 2249 "" "{23,25,1009,1009,25,25,25,1009,25}" "{o,o,o,o,o,o,o,o,o}" "{line_number,type,database,user_name,address,netmask,auth_method,options,error}" _null_ _null_ pg_hba_file_rules _null_ _null_ _null_ ));
|
||||||
|
DESCR("show pg_hba.conf rules");
|
||||||
DATA(insert OID = 1371 ( pg_lock_status PGNSP PGUID 12 1 1000 0 0 f f f f t t v s 0 0 2249 "" "{25,26,26,23,21,25,28,26,26,21,25,23,25,16,16}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{locktype,database,relation,page,tuple,virtualxid,transactionid,classid,objid,objsubid,virtualtransaction,pid,mode,granted,fastpath}" _null_ _null_ pg_lock_status _null_ _null_ _null_ ));
|
DATA(insert OID = 1371 ( pg_lock_status PGNSP PGUID 12 1 1000 0 0 f f f f t t v s 0 0 2249 "" "{25,26,26,23,21,25,28,26,26,21,25,23,25,16,16}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{locktype,database,relation,page,tuple,virtualxid,transactionid,classid,objid,objsubid,virtualtransaction,pid,mode,granted,fastpath}" _null_ _null_ pg_lock_status _null_ _null_ _null_ ));
|
||||||
DESCR("view system lock information");
|
DESCR("view system lock information");
|
||||||
DATA(insert OID = 2561 ( pg_blocking_pids PGNSP PGUID 12 1 0 0 0 f f f f t f v s 1 0 1007 "23" _null_ _null_ _null_ _null_ _null_ pg_blocking_pids _null_ _null_ _null_ ));
|
DATA(insert OID = 2561 ( pg_blocking_pids PGNSP PGUID 12 1 0 0 0 f f f f t f v s 1 0 1007 "23" _null_ _null_ _null_ _null_ _null_ pg_blocking_pids _null_ _null_ _null_ ));
|
||||||
|
@ -16,10 +16,16 @@
|
|||||||
#include "regex/regex.h"
|
#include "regex/regex.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following enum represents the authentication methods that
|
||||||
|
* are supported by PostgreSQL.
|
||||||
|
*
|
||||||
|
* Note: keep this in sync with the UserAuthName array in hba.c.
|
||||||
|
*/
|
||||||
typedef enum UserAuth
|
typedef enum UserAuth
|
||||||
{
|
{
|
||||||
uaReject,
|
uaReject,
|
||||||
uaImplicitReject,
|
uaImplicitReject, /* Not a user-visible option */
|
||||||
uaTrust,
|
uaTrust,
|
||||||
uaIdent,
|
uaIdent,
|
||||||
uaPassword,
|
uaPassword,
|
||||||
@ -32,6 +38,7 @@ typedef enum UserAuth
|
|||||||
uaCert,
|
uaCert,
|
||||||
uaRADIUS,
|
uaRADIUS,
|
||||||
uaPeer
|
uaPeer
|
||||||
|
#define USER_AUTH_LAST uaPeer /* Must be last value of this enum */
|
||||||
} UserAuth;
|
} UserAuth;
|
||||||
|
|
||||||
typedef enum IPCompareMethod
|
typedef enum IPCompareMethod
|
||||||
|
@ -1338,6 +1338,16 @@ pg_group| SELECT pg_authid.rolname AS groname,
|
|||||||
WHERE (pg_auth_members.roleid = pg_authid.oid)) AS grolist
|
WHERE (pg_auth_members.roleid = pg_authid.oid)) AS grolist
|
||||||
FROM pg_authid
|
FROM pg_authid
|
||||||
WHERE (NOT pg_authid.rolcanlogin);
|
WHERE (NOT pg_authid.rolcanlogin);
|
||||||
|
pg_hba_file_rules| SELECT a.line_number,
|
||||||
|
a.type,
|
||||||
|
a.database,
|
||||||
|
a.user_name,
|
||||||
|
a.address,
|
||||||
|
a.netmask,
|
||||||
|
a.auth_method,
|
||||||
|
a.options,
|
||||||
|
a.error
|
||||||
|
FROM pg_hba_file_rules() a(line_number, type, database, user_name, address, netmask, auth_method, options, error);
|
||||||
pg_indexes| SELECT n.nspname AS schemaname,
|
pg_indexes| SELECT n.nspname AS schemaname,
|
||||||
c.relname AS tablename,
|
c.relname AS tablename,
|
||||||
i.relname AS indexname,
|
i.relname AS indexname,
|
||||||
|
@ -39,6 +39,13 @@ select count(*) >= 0 as ok from pg_file_settings;
|
|||||||
t
|
t
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- There will surely be at least one rule
|
||||||
|
select count(*) > 0 as ok from pg_hba_file_rules;
|
||||||
|
ok
|
||||||
|
----
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- There will surely be at least one active lock
|
-- There will surely be at least one active lock
|
||||||
select count(*) > 0 as ok from pg_locks;
|
select count(*) > 0 as ok from pg_locks;
|
||||||
ok
|
ok
|
||||||
|
@ -20,6 +20,9 @@ select count(*) = 0 as ok from pg_cursors;
|
|||||||
|
|
||||||
select count(*) >= 0 as ok from pg_file_settings;
|
select count(*) >= 0 as ok from pg_file_settings;
|
||||||
|
|
||||||
|
-- There will surely be at least one rule
|
||||||
|
select count(*) > 0 as ok from pg_hba_file_rules;
|
||||||
|
|
||||||
-- There will surely be at least one active lock
|
-- There will surely be at least one active lock
|
||||||
select count(*) > 0 as ok from pg_locks;
|
select count(*) > 0 as ok from pg_locks;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user