Client Authenticationclient authentication
Since Pgpool-II is a middleware that works between
PostgreSQL servers and
a PostgreSQL database client, so when a
client application connects to
the Pgpool-II, Pgpool-II
in turn connects to the PostgreSQL servers
using the same credentials to serve the incoming client
connection. Thus, all the access privileges and restrictions defined
for the user in PostgreSQL gets
automatically applied to all Pgpool-II
clients, with an exceptions of the authentications
on PostgreSQL side that depends on the
client's IP addresses or host names. Reason being the connections
to the PostgreSQL server are made
by Pgpool-II on behalf of the connecting
clients and PostgreSQL server can only
see the IP address of the
Pgpool-II server and not that of the actual client.
Therefore, for the client host based authentications Pgpool-II has the
pool_hba mechanism similar to the pg_hba mechanism for
authenticating the incoming client connections.
The pool_passwd file manages passwords for
authentication used when clients connect
to Pgpool-II
(see for more details). The
passwords registered on pool_passwd must match
with the passwords registered
on PostgreSQL. Note that passwords
changed on PostgreSQL are not
automatically sync to the passwords
on pool_passwd. scram-shar-256
authentication and MD5
authentication require that the user name and the password
have been already registered on pool_passwd,
while clear text password
authentication
or does not
require that. Therefore, if you want to avoid maintaining
the pool_passwd, it would be worth to
check clear text password
authentication
or .
The pool_hba.conf Filepool_hba.conf
Just like the pg_hba.conf file for PostgreSQL,
Pgpool-II supports a similar client authentication
function using a configuration file called pool_hba.conf.
If Pgpool-II is installed from source code, it also includes the sample
pool_hba.conf.sample file in the default
configuration directory ("/usr/local/etc").
By default, pool_hba authentication is disabled, and
setting enable_pool_hba
to on enables it. see
the configuration
parameter.
If number of PostgreSQL servers is
only one, or when running in raw mode
(see ),
pool_hba.conf is not necessary
thus enable_pool_hba may be being set to off.
In this case the client authentication method is completely
managed by PostgreSQL. Also number
of PostgreSQL servers is more than
one, or not running in raw
mode, enable_pool_hba may be being set to off
as long as the authentication method defined
by PostgreSQL
is trust.
The format of the pool_hba.conf file
follows very
closely PostgreSQL's pg_hba.conf
format.
The general format of the pool_hba.conf file is
a set of records, one per line. Blank lines are ignored, as is any
text after the # comment character.
Records cannot be continued across lines.
A record is made
up of a number of fields which are separated by spaces and/or tabs.
Fields can contain white space if the field value is double-quoted.
Quoting one of the keywords in a database, user, or address field (e.g.,
all or replication) makes
the word lose its special meaning, and just match a database, user, or
host with that name.
Each record specifies a connection type, a client IP address
range (if relevant for the connection type), a database name, a
user name, and the authentication method to be used for
connections matching these parameters. The first record with a
matching connection type, client address, requested database,
and user name is used to perform authentication. There is
no fall-through or
backup: if one record is chosen and the authentication
fails, subsequent records are not considered. If no record matches,
access is denied.
A record can have one of the following formats
local databaseuserauth-methodauth-options
host databaseuserIP-addressIP-maskauth-methodauth-options
hostssl databaseuserIP-addressIP-maskauth-methodauth-options
hostnossl databaseuserIP-addressIP-maskauth-methodauth-options
host databaseuseraddressauth-methodauth-options
hostssl databaseuseraddressauth-methodauth-options
hostnossl databaseuseraddressauth-methodauth-options
The meaning of the fields is as follows:
local
This record matches connection attempts using Unix-domain
sockets. Without a record of this type, Unix-domain socket
connections are disallowed.
host
This record matches connection attempts made using TCP/IP.
host records match either
SSL or non-SSL connection
attempts.
Remote TCP/IP connections will not be possible unless
the server is started with an appropriate value for the
configuration parameter,
since the default behavior is to listen for TCP/IP connections
only on the local loopback address localhost.
hostssl
This record matches connection attempts made using TCP/IP, but only
when the connection is made with SSL encryption.
To make use of this option the Pgpool-II must be
built with SSL support. Furthermore, SSL must be enabled by setting the
configuration parameter. Otherwise, the hostssl record is ignored.
hostnossl
This record type has the opposite behavior of hostssl; it only matches connection
attempts made over TCP/IP that do not use SSL.
database
Specifies which database name(s) this record matches. The value
all specifies that it matches all databases.
"samegroup" for database field is not supported:
Since Pgpool-II does not know anything about
users in the PostgreSQL backend server, the database name is simply
compared against the entries in the database field of pool_hba.conf.
user
Specifies which database user name(s) this record
matches. The value all specifies that it
matches all users. Otherwise, this is the name of a specific
database user
group names following "+" for user field is not supported:
This is for the same reason as for the "samegroup" of database field.
A user name is simply checked against the entries in the user field of
pool_hba.conf.
address
Specifies the client machine address(es) that this record matches.
This field can contain either a host name, an IP address range,
or one of the special key words mentioned below.
An IP address range is specified using standard numeric notation for
the range's starting address, then a slash (/)
and a CIDR mask length.
The mask length indicates the number of high-order bits of the client
IP address that must match. Bits to the right of this should be zero
in the given IP address. There must not be any white space between the
IP address, the /, and the CIDR mask length.
Typical examples of an IPv4 address range specified this way are
172.20.143.89/32 for a single host, or
172.20.143.0/24 for a small network, or
10.6.0.0/16 for a larger one.
An IPv6 address range might look like ::1/128 for
a single host (in this case the IPv6 loopback address) or
fe80::7a31:c1ff:0000:0000/96 for a small network.
0.0.0.0/0 represents all IPv4 addresses, and
::0/0 represents all IPv6 addresses. To specify a
single host, use a mask length of 32 for IPv4 or 128 for IPv6.
In a network address, do not omit trailing zeroes.
An entry given in IPv4 format will match only IPv4 connections, and
an entry given in IPv6 format will match only IPv6 connections, even
if the represented address is in the IPv4-in-IPv6 range.
Note that entries in IPv6 format will be rejected if the system's C
library does not have support for IPv6 addresses.
You can also write all to match any IP address,
samehost to match any
of the server's own IP addresses, or samenet to match any address in
any subnet that the server is directly connected to.
If a host name is specified (anything that is not an IP address range or
a special key word is treated as a host name), that name is compared with
the result of a reverse name resolution of the client's IP address
(e.g., reverse DNS lookup, if DNS is used). Host name comparisons are
case insensitive. If there is a match, then a forward name resolution
(e.g., forward DNS lookup) is performed on the host name to check whether
any of the addresses it resolves to are equal to the client's IP address.
If both directions match, then the entry is considered to match.
(The host name that is used in pool_hba.conf should be the one that
address-to-name resolution of the client's IP address returns, otherwise
the line won't be matched. Some host name databases allow associating an
IP address with multiple host names, but the operating system will only
return one host name when asked to resolve an IP address.)
A host name specification that starts with a dot (.) matches
a suffix of the actual host name. So .example.com would match
foo.example.com (but not just example.com).
When host names are specified in pool_hba.conf, you should
make sure that name resolution is reasonably fast. It can be of advantage to
set up a local name resolution cache such as nscd.
This field only applies to host, hostssl, and hostnossl records.
Specifying the host name in address field is not supported prior to
Pgpool-II V3.7.
IP-addressIP-mask
These two fields can be used as an alternative to the
IP-address/mask-length notation.
Instead of specifying the mask length, the actual mask
is specified in a separate column. For
example, 255.0.0.0 represents an
IPv4 CIDR mask length
of 8,
and 255.255.255.255 represents a
CIDR mask length of 32.
This field only applies to host, hostssl, and hostnossl records.
auth-method
Specifies the authentication method to use when a connection matches
this record. The possible choices are summarized here; details
are in .
trust
Allow the connection unconditionally. This method
allows anyone that can connect to the
Pgpool-II.
reject
Reject the connection unconditionally. This is useful for
filtering out certain hosts, for example a
reject line could block a specific
host from connecting.
md5
Require the client to supply a double-MD5-hashed password for
authentication.
To use md5
authentication, you need to register the
user name and password
in file.
See for more
details. If you don't want to manage
password by
using pool_passwd,
you could
use .
scram-sha-256
Perform SCRAM-SHA-256 authentication to verify the user's password.
To use scram-sha-256
authentication, you need to register the
user name and password
in file.
See for more
details. If you don't want to manage
password by
using pool_passwd,
you could
use .
cert
Authenticate using SSL client certificates.
See for more details.
pam
Authenticate using the Pluggable Authentication Modules
(PAM) service provided by the operating system.
See for details.
PAM authentication is supported using user information on the host
where Pgpool-II is running.
To enable PAM support the Pgpool-II
must be configured with "--with-pam"
To enable PAM authentication, you must create a
service-configuration file
for Pgpool-II in the system's PAM
configuration directory (that is usually located
at "/etc/pam.d"). A sample
service-configuration file is also installed
as "share/pgpool.pam" under the install
directory.
ldap
Authenticate using LDAP server.
See for more details.
To enable LDAP support the Pgpool-II
must be configured with "--with-ldap"auth-options
After the auth-method field,
there can be field(s) of the
form name=value
that specify options for the authentication method.
Since the pool_hba.conf records are examined
sequentially for each connection attempt, the order of the records
is significant. Typically, earlier records will have tight
connection match parameters and weaker authentication methods, while
later records will have looser match parameters and stronger
authentication methods. For example, one might wish to
use trust authentication for local TCP/IP
connections but require a password for remote TCP/IP connections. In
this case a record specifying
trust authentication for connections from 127.0.0.1 would
appear before a record specifying password authentication for a wider
range of allowed client IP addresses.
All pool_hba authentication options described in this section are
about the authentication taking place between a client and the
Pgpool-II. A client still has to go
through the PostgreSQL's authentication
process and must have the CONNECT privilege for
the database on the backend PostgreSQL
server.
As far as pool_hba is concerned, it does not matter if a user name
and/or database name given by a client
(i.e. psql -U testuser testdb)
really exists in the backend. pool_hba only cares if a match in the
pool_hba.conf can be found or not.
Some examples of pool_hba.conf entries.
See the next section for details on the different authentication methods.
Example pool_hba.conf Entries
# Allow any user on the local system to connect to any database with
# any database user name using Unix-domain sockets (the default for local
# connections).
#
# TYPE DATABASE USER ADDRESS METHOD
local all all trust
# The same using local loopback TCP/IP connections.
#
# TYPE DATABASE USER ADDRESS METHOD
host all all 127.0.0.1/32 trust
# Allow any user from host 192.168.12.10 to connect to database
# "postgres" if the user's password is correctly supplied.
#
# TYPE DATABASE USER ADDRESS METHOD
host postgres all 192.168.12.10/32 md5
Authentication Methods
The following subsections describe the authentication methods
specified by pool_hba.conf in more detail.
Trust Authentication
When trust authentication is specified,
Pgpool-II assumes that anyone who can
connect to the server is authorized to access connect with
whatever database user name they specify.
Clear Text Password Authentication
The method password sends the password in
clear-text and is therefore vulnerable to password
sniffing attacks. It should always be avoided if
possible. If the connection is protected by SSL encryption then
password can be used safely, though. For this
sake, it is recommended to use hostssl in
pool_hba.conf so that clients are enforced to
use SSL encryption.
A benefit to use the method is, the password for authentication is
provided by client side and pool_passwd is
not consulted. So you can avoid maintaining
pool_passwd file.
You can avoid maintaining pool_passwd by
using as well
but it does not enforce to use SSL encryption because
pool_hba.conf cannot be used with the
parameter.
MD5 Password AuthenticationMD5
This authentication method is the password-based authentication
methods in which MD-5-hashed password is sent by client.
Since Pgpool-II does not has the
visibility of PostgreSQL's database
user password and client application only sends the MD5-hash of
the password, so md5 authentication
in Pgpool-II is supported using the
authentication file.
Authentication file format
To use the md5 authentication
authentication file must contain
the user password in either plain text, AES
or md5 encrypted format.
The file should contain lines in the following format:
"username:TEXT_plain_text_passwd"
"username:AES_encrypted_passwd"
"username:md5_encrypted_passwd"
(Actually "_" after "TEXT", "AES" or "md5" does not exist.)
Setting md5 AuthenticationMD5
here are the steps to enable md5
authentication:
1- Login as the database's operating system user and type
"pg_md5 --config-file=path_to_pgpool.conf --md5auth --username=username password" user name
and md5 encrypted password are registered
into . If pool_passwd does not exist yet, pg_md5
command will automatically create it for you.
user name and password must be identical to those registered
in PostgreSQL server.
2- Add an appropriate md5 entry to pool_hba.conf.
See for more details.
If pool_hba.conf is not enabled, make sure
that md5 authentication is specified
in pg_hba.conf
of PostgreSQL.
3- After changing md5 password (in both pool_passwd
and PostgreSQL of course), reload
the pgpool configurations.
scram-sha-256 AuthenticationSCRAM
This authentication method also known as SCRAM is a
challenge-response based authentication that prevents the
password sniffing on untrusted connections.
Since Pgpool-II does not has the
visibility of PostgreSQL's database user
password, so SCRAM authentication is supported using the
authentication file.
Authentication file entry for SCRAM
To use the SCRAM authentication
authentication file
must contain the user password in either plain text
or AES encrypted format.
"username:TEXT_plain_text_passwd"
"username:AES_encrypted_passwd"
(Actually "_" after "TEXT" or "AES" does not exist.)
md5 type user passwords in
file can't be used for
scram authentication
Setting scram-sha-256 AuthenticationSCRAM
Here are the steps to enable scram-sha-256
authentication:
1- Create file entry
for database user and password in plain text or AES
encrypted format.
The utility that comes with Pgpool-II
can be used to create the AES encrypted password
entries in the file.
User name and password must be identical to those registered
in the PostgreSQL server.
2- Add an appropriate scram-sha-256 entry to pool_hba.conf.
See for more details.
If pool_hba.conf is not enabled, make sure that md5 authentication is specified in pg_hba.conf of PostgreSQL.
3- After changing SCRAM password (in both pool_passwd
and PostgreSQL of course), reload
the Pgpool-II configuration.
Certificate AuthenticationCertificate
This authentication method uses SSL client certificates
to perform authentication. It is therefore only available for SSL connections.
When using this authentication method, the Pgpool-II
will require that the client provide a valid certificate.
No password prompt will be sent to the client.
The cn (Common Name) attribute of the certificate will be
compared to the requested database user name, and if they match the login will
be allowed.
The certificate authentication works between only client and
Pgpool-II. The certificate
authentication does not work between
Pgpool-II and
PostgreSQL. For backend
authentication you can use any other authentication method.
PAM AuthenticationPAM
This authentication method uses PAM (Pluggable
Authentication Modules) as the authentication mechanism. The
default PAM service name is pgpool.
PAM authentication is supported using user information on
the host where Pgpool-II is executed.
For more
information about PAM, please read the
Linux-PAM Page.
To enable PAM authentication, you need to create a service-configuration
file named for Pgpool-II in the system's
PAM configuration directory (which is usually at "/etc/pam.d").
To enable PAM support the Pgpool-II
must be configured with "--with-pam"LDAP AuthenticationLDAP
This authentication method uses LDAP as the password certification method.
LDAP is used only to validate the user name/password pairs. Therefore the user must
already exist in the database before LDAP can be used for authentication.
LDAP authentication can operate in two modes. In the first mode, which we
will call the simple bind mode, the server will bind to the distinguished
name constructed as
prefixusernamesuffix.
Typically, the prefix parameter is used to specify
cn=, or DOMAIN\
in an Active Directory environment. suffix is used
to specify the remaining part of the DN in a non-Active Directory environment.
In the second mode, which we will call the search+bind mode, the server first
binds to the LDAP directory with a fixed user name and password, specified
with ldapbinddn and ldapbindpasswd,
and performs a search for the user trying to log in to the database. If no
user and password is configured, an anonymous bind will be attempted to the
directory. The search will be performed over the subtree at
ldapbasedn, and will try to do an exact match of
the attribute specified in ldapsearchattribute.
Once the user has been found in this search, the server disconnects and
re-binds to the directory as this user, using the password specified by the
client, to verify that the login is correct. This mode is the same as that
used by LDAP authentication schemes in other software, such as Apache
mod_authnz_ldap and pam_ldap. This
method allows for significantly more flexibility in where the user objects
are located in the directory, but will cause two separate connections to the
LDAP server to be made.
The following configuration options are used in both modes:
ldapserver
Names or IP addresses of LDAP servers to connect to. Multiple servers
may be specified, separated by spaces.
ldapport
Port number on LDAP server to connect to. If no port is specified, the
LDAP library's default port setting will be used.
ldapscheme
Set to ldaps to use LDAPS. This is a non-standard
way of using LDAP over SSL, supported by some LDAP server implementations.
See also the ldaptls option for an alternative.
ldaptls
Set to 1 to make the connection between Pgpool-II and the LDAP server
use TLS encryption. This uses the StartTLS operation
per RFC 4513. See also the ldapscheme option for an alternative.
Note that using ldapscheme or
ldaptls only encrypts the traffic between the
Pgpool-II server and the LDAP server. The connection between the
Pgpool-II server and the client will still be unencrypted
unless SSL is used there as well.
The following options are used in simple bind mode only:
ldapprefix
String to prepend to the user name when forming the DN to bind as,
when doing simple bind authentication.
ldapsuffix
String to append to the user name when forming the DN to bind as,
when doing simple bind authentication.
The following options are used in search+bind mode only:
ldapbasedn
Root DN to begin the search for the user in, when doing search+bind
authentication.
ldapbinddn
DN of user to bind to the directory with to perform the search when
doing search+bind authentication.
ldapbindpasswd
Password for user to bind to the directory with to perform the search
when doing search+bind authentication.
ldapsearchattribute
Attribute to match against the user name in the search when doing
search+bind authentication. If no attribute is specified, the
uid attribute will be used.
ldapsearchfilter
The search filter to use when doing search+bind authentication.
Occurrences of $username will be replaced with the
user name. This allows for more flexible search filters than
ldapsearchattribute.
ldapurl
An RFC 4516 LDAP URL. This is an alternative way to write some of the
other LDAP options in a more compact and standard form. The format is
ldap[s]://host[:port]/basedn[?[attribute][?[scope][?[filter]]]]
scope must be one of base,
one, sub, typically the last.
(The default is base, which is normally not useful
in this application.) attribute can nominate
a single attribute, in which case it is used as a value for ldapsearchattribute.
If attribute is empty then filter
can be used as a value for ldapsearchfilter.
The URL scheme ldaps chooses the LDAPS method for
making LDAP connections over SSL, equivalent to using ldapscheme=ldaps.
To use encrypted LDAP connections using the StartTLS
operation, use the normal URL scheme ldap and specify the
ldaptls option in addition to ldapurl.
For non-anonymous binds, ldapbinddn and
ldapbindpasswd must be specified as separate options.
backend_use_passwd
Set to 1 to make the password used for LDAP authentication use authentication
between Pgpool-II and backend.
It is an error to mix configuration options for simple bind with options
for search+bind.
When using search+bind mode, the search can be performed using a single
attribute specified with ldapsearchattribute, or using
a custom search filter specified with
ldapsearchfilter.
Specifying ldapsearchattribute=foo is equivalent to
specifying ldapsearchfilter="(foo=$username)". If neither
option is specified the default is
ldapsearchattribute=uid.
If Pgpool-II was compiled with
OpenLDAP as the LDAP client library, the
ldapserver setting may be omitted. In that case, a
list of host names and ports is looked up via RFC 2782 DNS SRV records.
The name _ldap._tcp.DOMAIN is looked up, where
DOMAIN is extracted from ldapbasedn.
Here is an example for a simple-bind LDAP configuration:
host ... ldap ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"
When a connection to the database server as database
user foo is requested, Pgpool-II will attempt to
bind to the LDAP server using the DN cn=foo, dc=example,
dc=net and the password provided by the client. If that connection
succeeds, the database access is granted.
Here is an example for a search+bind configuration:
host ... ldap ldapserver=ldap.example.net ldapbasedn="dc=example, dc=net" ldapsearchattribute=uid
When a connection to the database server as database
user foo is requested, Pgpool-II will attempt to
bind anonymously (since ldapbinddn was not specified) to
the LDAP server, perform a search for (uid=foo)
under the specified base DN. If an entry is found, it will then attempt to
bind using that found information and the password supplied by the client.
If that second connection succeeds, the database access is granted.
Here is the same search+bind configuration written as a URL:
host ... ldap ldapurl="ldap://ldap.example.net/dc=example,dc=net?uid?sub"
Some other software that supports authentication against LDAP uses the
same URL format, so it will be easier to share the configuration.
Here is an example for a search+bind configuration that uses
ldapsearchfilter instead of
ldapsearchattribute to allow authentication by
user ID or email address:
host ... ldap ldapserver=ldap.example.net ldapbasedn="dc=example, dc=net" ldapsearchfilter="(|(uid=$username)(mail=$username))"
Here is an example for a search+bind configuration that uses DNS SRV
discovery to find the host name(s) and port(s) for the LDAP service for the
domain name example.net:
host ... ldap ldapbasedn="dc=example,dc=net"
Since LDAP often uses commas and spaces to separate the different
parts of a DN, it is often necessary to use double-quoted parameter
values when configuring LDAP options, as shown in the examples.
To enable LDAP support the Pgpool-II
must be configured with "--with-ldap"GSSAPI AuthenticationGSSAPI
GSSAPI is an industry-standard protocol for secure authentication
defined in RFC 2743. Currently
Pgpool-II does not support GSSAPI.
Clients should not use GSSAPI authentication, or should use
"prefer GSSAPI authentication if possible" option (this is the
default setting of PostgreSQL clients).
If latter is chosen, Pgpool-II requests
non-GSSAPI authentication to client, and the clients will fall
back to non-GSSAPI authentication method. Thus, usually users do
not need to worry about that Pgpool-II
does not accept GSSAPI authentication.
Using different methods for frontend and backend authenticationAUTH
Since Pgpool-IIV4.0
it possible to use different authentication for client application
and backend PostgreSQL servers.
For example, a client application can use scram-sha-256
to connect to Pgpool-II which
in turn can use trust or md5
authentication to connect to PostgreSQL
backend for the same session.
Using AES256 encrypted passwords in AUTHSCRAM authentication guards against the man-in-the-middle
type of attack, so Pgpool-II requires the user password
to authenticate with the PostgreSQL backend.
However, storing the clear text passwords in the "pool_passwd" file
is not a good idea.
You can instead store AES256 AES256 encrypted passwords, which will be used for authentication.
The password is first encrypted using the AES256 encryption with the user provided key
and then the encrypted password is base64 encoded and
an AES prefix is added to the encoded string.
You can use the utility to create the properly
formatted AES256 encrypted password.
Creating encrypted password entries can be used to create AES
encrypted password entries in file.
requires the key for encrypting the password entries.
Later that same key will be required by Pgpool-II
to decrypt the passwords to use for authentication.
Pgpool-II must be built with SSL
(--with-openssl) support to use the encrypted password feature.
Providing decryption key to Pgpool-II
If you have AES encrypted passwords stored in the
file, then Pgpool-II
will require the decryption key to decrypt the passwords before using them,
Pgpool-II tries to read the decryption key at
startup from the .pgpoolkey file.
pgpoolkeyPGPOOLKEYFILE.pgpoolkey is a plain text file which
contains the decryption key string.
By default the Pgpool-II will look for the
.pgpoolkey file in the user's home directory or the file
referenced by environment variable PGPOOLKEYFILE.
You can also specify the key file using the (-k, --key-file=KEY_FILE)
command line argument to the command.
The permissions on .pgpoolkey must disallow any access to world or group.
Change the file permissions by the command chmod 0600 ~/.pgpoolkey.