Configuring Client Authentication
A newer version of this documentation is available. Click here to view the most up-to-date release of the Greenplum 4.x documentation.
Configuring Client Authentication
This topic explains how to configure client connections and authentication for Greenplum Database.
When a Greenplum Database system is first initialized, the system contains one predefined superuser role. This role will have the same name as the operating system user who initialized the Greenplum Database system. This role is referred to as gpadmin. By default, the system is configured to only allow local connections to the database from the gpadmin role. To allow any other roles to connect, or to allow connections from remote hosts, you configure Greenplum Database to allow such connections.
Allowing Connections to Greenplum Database
Client access and authentication is controlled by the standard PostgreSQL host-based authentication file, pg_hba.conf. In Greenplum Database, the pg_hba.conf file of the master instance controls client access and authentication to your Greenplum Database system. Greenplum Database segments have pg_hba.conf files that are configured to allow only client connections from the master host and never accept client connections. Do not alter the pg_hba.conf file on your segments.
See The pg_hba.conf File in the PostgreSQL documentation for more information.
The general format of the pg_hba.conf file is a set of records, one per line. Greenplum Database ignores blank lines and any text after the # comment character. A record consists of a number of fields that are separated by spaces and/or tabs. Fields can contain white space if the field value is quoted. Records cannot be continued across lines. Each remote client access record has the following format:
host database role CIDR-address authentication-method
Each UNIX-domain socket access record has the following format:
local database role authentication-method
The following table describes meaning of each field.
|local||Matches connection attempts using UNIX-domain sockets. Without a record of this type, UNIX-domain socket connections are disallowed.|
|host||Matches connection attempts made using TCP/IP. Remote TCP/IP connections will not be possible unless the server is started with an appropriate value for the listen_addresses server configuration parameter.|
|hostssl||Matches connection attempts made using TCP/IP, but only when the connection is made with SSL encryption. SSL must be enabled at server start time by setting the ssl configuration parameter|
|hostnossl||Matches connection attempts made over TCP/IP that do not use SSL.|
|database||Specifies which database names this record matches. The value all specifies that it matches all databases. Multiple database names can be supplied by separating them with commas. A separate file containing database names can be specified by preceding the file name with @.|
|role||Specifies which database role names this record matches. The value all specifies that it matches all roles. If the specified role is a group and you want all members of that group to be included, precede the role name with a +. Multiple role names can be supplied by separating them with commas. A separate file containing role names can be specified by preceding the file name with @.|
|CIDR-address||Specifies the client machine IP address range that this record
matches. It contains an IP address in standard dotted decimal notation and a CIDR
mask length. IP addresses can only be specified numerically, not as domain or host
names. The mask length indicates the number of high-order bits of the client IP
address that must match. Bits to the right of this must 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 a CIDR-address are 192.0.2.89/32 for a single host, or 192.0.2.0/24 for a small network, or 10.6.0.0/16 for a larger one. To specify a single host, use a CIDR mask of 32 for IPv4 or 128 for IPv6. In a network address, do not omit trailing zeroes.
|These fields can be used as an alternative to the CIDR-address notation. Instead of specifying the mask length, the actual mask is specified in a separate column. For example, 255.255.255.255 represents a CIDR mask length of 32. These fields only apply to host, hostssl, and hostnossl records.|
|authentication-method||Specifies the authentication method to use when connecting. Greenplum supports the authentication methods supported by PostgreSQL 9.0.|
Editing the pg_hba.conf File
This example shows how to edit the pg_hba.conf file of the master to allow remote client access to all databases from all roles using encrypted password authentication.
- Open the file $MASTER_DATA_DIRECTORY/pg_hba.conf in a text editor.
- Add a line to the file for each type of connection you want to allow.
Records are read sequentially, so 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
# allow the gpadmin user local access to all databases # using ident authentication local all gpadmin ident sameuser host all gpadmin 127.0.0.1/32 ident host all gpadmin ::1/128 ident # allow the 'dba' role access to any database from any # host with IP address 192.168.x.x and use md5 encrypted # passwords to authenticate the user # Note that to use SHA-256 encryption, replace md5 with # password in the line below host all dba 192.168.0.0/32 md5 # allow all roles access to any database from any # host and use ldap to authenticate the user. Greenplum role # names must match the LDAP common name. host all all 192.168.0.0/32 ldap ldapserver=usldap1 ldapport=1389 ldapprefix="cn=" ldapsuffix=",ou=People,dc=company,dc=com"
- Save and close the file.
- Reload the pg_hba.conf configuration file for
your changes to take effect:
$ gpstop -u
Limiting Concurrent Connections
Greenplum Database allocates some resources on a per-connection basis, so setting the maximum number of connections allowed is recommended.
To limit the number of active concurrent sessions to your Greenplum Database system, you can configure the max_connections server configuration parameter. This is a local parameter, meaning that you must set it in the postgresql.conf file of the master, the standby master, and each segment instance (primary and mirror). Pivotal recommends that the value of max_connections on segments be 5-10 times the value on the master.
When you set max_connections, you must also set the dependent parameter max_prepared_transactions. This value must be at least as large as the value of max_connections on the master, and segment instances should be set to the same value as the master.
In $MASTER_DATA_DIRECTORY/postgresql.conf (including standby master):
In SEGMENT_DATA_DIRECTORY/postgresql.conf for all segment instances:
The following steps set the parameter values with the Greenplum Database utility gpconfig.
For information about gpconfig, see the Greenplum Database Utility Guide.
To change the number of allowed connections
- Log into the Greenplum Database master host as the Greenplum Database administrator and source the file $GPHOME/greenplum_path.sh.
- Set the value of the max_connections parameter. This
gpconfig command sets the value on the segments to 1000 and the value
on the master to 200.
$ gpconfig -c max_connections -v 1000 -m 200
The value on the segments must be greater than the value on the master. Pivotal recommends that the value of max_connections on segments be 5-10 times the value on the master.
- Set the value of the max_prepared_transactions
parameter. This gpconfig command sets the value to 200 on the master
and all segments.
$ gpconfig -c max_prepared_transactions -v 200
The value of max_prepared_transactions must be greater than or equal to max_connections on the master.
- Stop and restart your Greenplum Database system.
$ gpstop -r
- You can check the value of parameters on the master and segments with
-s option. This gpconfig command displays the values
of the max_connections parameter.
$ gpconfig -s max_connections
Raising the values of these parameters may cause Greenplum Database to request more shared memory. To mitigate this effect, consider decreasing other memory-related parameters such as gp_cached_segworkers_threshold.
Encrypting Client/Server Connections
Enable SSL for client connections to Greenplum Database to encrypt the data passed over the network between the client and the database.
Greenplum Database has native support for SSL connections between the client and the master server. SSL connections prevent third parties from snooping on the packets, and also prevent man-in-the-middle attacks. SSL should be used whenever the client connection goes through an insecure link, and must be used whenever client certificate authentication is used.
To enable SSL requires that OpenSSL be installed on both the client and the master server systems. Greenplum Database can be started with SSL enabled by setting the server configuration parameter ssl=on in the master postgresql.conf. When starting in SSL mode, the server will look for the files server.key (server private key) and server.crt (server certificate) in the master data directory. These files must be set up correctly before an SSL-enabled Greenplum Database system can start.
A self-signed certificate can be used for testing, but a certificate signed by a certificate authority (CA) should be used in production, so the client can verify the identity of the server. Either a global or local CA can be used. If all the clients are local to the organization, a local CA is recommended.
Creating a Self-signed Certificate without a Passphrase for Testing Only
To create a quick self-signed certificate for the server for testing, use the following OpenSSL command:
# openssl req -new -text -out server.req
Enter the information requested by the prompts. Be sure to enter the local host name as Common Name. The challenge password can be left blank.
The program will generate a key that is passphrase protected, and does not accept a passphrase that is less than four characters long.
To use this certificate with Greenplum Database, remove the passphrase with the following commands:
# openssl rsa -in privkey.pem -out server.key # rm privkey.pem
Enter the old passphrase when prompted to unlock the existing key.
Then, enter the following command to turn the certificate into a self-signed certificate and to copy the key and certificate to a location where the server will look for them.
# openssl req -x509 -in server.req -text -key server.key -out server.crt
Finally, change the permissions on the key with the following command. The server will reject the file if the permissions are less restrictive than these.
# chmod og-rwx server.key
For more details on how to create your server private key and certificate, refer to the OpenSSL documentation.