1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +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:
Tom Lane
2017-01-30 18:00:26 -05:00
parent d002f16c6e
commit de16ab7238
10 changed files with 873 additions and 121 deletions

View File

@ -7808,6 +7808,11 @@
<entry>groups of database users</entry>
</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>
<entry><link linkend="view-pg-indexes"><structname>pg_indexes</structname></link></entry>
<entry>indexes</entry>
@ -8408,6 +8413,114 @@
</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">
<title><structname>pg_indexes</structname></title>

View File

@ -597,6 +597,24 @@ hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable>
re-read the file.
</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>
<para>
To connect to a particular database, a user must not only pass the