• Data Warehouse Service

dws
  1. Help Center
  2. Data Warehouse Service
  3. User Guide
  4. Connecting to a Cluster
  5. Using the gsql CLI Client to Connect to a Cluster
  6. Establishing Secure TCP/IP Connections in SSL Mode

Establishing Secure TCP/IP Connections in SSL Mode

If the client or JDBC/ODBC driver needs to use SSL connection, you must configure related SSL connection parameters in the client or application code. The DWS management console provides the SSL certificate required by the client. The SSL certificate contains the default certificate, private key, root certificate, and private key password encryption file required by the client. Download the SSL certificate to the host where the client resides and specify the path of the certificate on the client.
NOTE:

Using the default certificate may pose security risks. To improve system security, you are advised to periodically change the certificate to prevent password cracking. If you need to replace the certificate, contact the customer service personnel.

For more information about SSL certificates, see section Downloading the SSL Certificate File. The following parts are included in this section:

Configuring Digital Certificate Parameters Related to SSL Authentication on the gsql Client

After a data warehouse cluster is deployed, the SSL authentication mode is enabled by default. The server certificate, private key, and root certificate have been configured by default. You need to configure the client parameters.

  1. Log in to the DWS management console, download the SSL certificate, and upload it to the host where the gsql client is installed.

    1. Download the SSL certificate. For details, see section Downloading the SSL Certificate File.
    2. Use WinSCP to upload SSL certificate dws_ssl_cert.tar.gz to a directory on the client host, for example, /home/dbadmin/dws_ssl/.
    3. Use PuTTY to remotely log in to the host.
    4. Run the following commands to navigate to the directory where the SSL certificate is stored and decompress the SSL certificate:

      cd /home/dbadmin/dws_ssl/

      tar -xvf dws_ssl_cert.tar.gz

  2. Configure digital certificate parameters related to SSL authentication on the host of the gsql client.

    There are two SSL authentication modes: bidirectional authentication and unidirectional authentication. Different authentication modes require different client environment variables. For details, see SSL Authentication Modes and Client Parameters.

    The following parameters must be configured for bidirectional authentication:

    export PGSSLCERT="/home/dbadmin/dws_ssl/sslcert/client.crt"
    export PGSSLKEY="/home/dbadmin/dws_ssl/sslcert/client.key"
    export PGSSLMODE="verify-ca"
    export PGSSLROOTCERT="/home/dbadmin/dws_ssl/sslcert/cacert.pem"

    The following parameters must be configured for unidirectional authentication:

    export PGSSLMODE="verify-ca"
    export PGSSLROOTCERT="/home/dbadmin/dws_ssl/sslcert/cacert.pem"
    • You are advised to use bidirectional authentication for security purposes.
    • The environment variables configured for a client must contain the absolute file paths.

  3. Change the client private key permissions.

    The permissions on the client's root certificate, private key, certificate, and encrypted private key file must be 600. If the permissions do not meet the requirement, the client cannot connect to the cluster in SSL mode.

    chmod 600 client.key
    chmod 600 client.crt
    chmod 600 client.key.cipher
    chmod 600 client.key.rand
    chmod 600 cacert.pem

SSL Authentication Modes and Client Parameters

SSL authentication has two authentication modes: bidirectional certification and unidirectional authentication. Table Table 1 shows the differences between these two modes. You are advised to use bidirectional authentication for security purposes.

Table 1 Authentication modes

Authentication Mode

Description

Environment Variables Configured on a Client

Maintenance

Bidirectional certification (recommended)

The client verifies the server's certificate and the server verifies the client's certificate. Connection can be set up after the verifications are successful.

Set the following environment variables:

  • PGSSLCERT
  • PGSSLKEY
  • PGSSLROOTCERT
  • PGSSLMODE

This authentication mode is applicable to scenarios that require high data security. When using this mode, you are advised to set the PGSSLMODE client variable to verify-ca for network data security purposes.

Unidirectional authentication

The client verifies the server's certificate, whereas the server does not verify the client's certificate. The server loads the certificate information and sends it to the client. The client verifies the server's certificate according to the root certificate.

Set the following environment variables:

  • PGSSLROOTCERT
  • PGSSLMODE

To prevent TCP-based link spoofing, you are advised to use the SSL certificate authentication. In addition to configuring the client root certificate, you are advised to set the PGSSLMODE variable to verify-ca on the client.

Configure environment variables related to SSL authentication on the client. For details, see Table 2.

NOTE:

An example path of environment variables is /home/dbadmin/dws_ssl/ (for example). Replace it with the actual path.

Table 2 Client parameters

Environment Variable

Description

Value Range

PGSSLCERT

Specifies the certificate files for a client, including the public key. Certificates prove the legal identity of the client and the public key is sent to the remote end for data encryption.

The absolute path of the files must be specified, for example:
export PGSSLCERT='/home/dbadmin/dws_ssl/sslcert/client.crt'

Default value: null

PGSSLKEY

Specifies the private key file for the client to encrypt digital signatures and data encrypted using the public key.

The absolute path of the files must be specified, for example:
export PGSSLKEY='/home/dbadmin/dws_ssl/sslcert/client.key'

Default value: null

PGSSLMODE

Specifies whether to negotiate with the server about SSL connection and specifies the priority of the SSL connection.

Values and meanings:

  • disable: only tries to establish a non-SSL connection.
  • allow: tries to establish a non-SSL connection first, and then an SSL connection if the first attempt fails.
  • prefer: tries to establish an SSL connection first, and then a non-SSL connection if the first attempt fails.
  • require: only tries to establish an SSL connection. If there is a CA file, perform the verification according to the scenario in which the parameter is set to verify-ca.
  • verify-ca: tries to establish an SSL connection and check whether the server certificate is issued by a trusted CA.
  • verify-full: DWS does not support this mode.

Default value: prefer

PGSSLROOTCERT

Specifies the root certificate file for issuing client certificates. The root certificate is used to verify the server certificate.

The absolute path of the files must be specified, for example:
export PGSSLROOTCERT='/home/dbadmin/dws_ssl/sslcert/certca.pem'

Default value: null

PGSSLCRL

Specifies the certificate revocation list file, which is used to check whether a server certificate is in the list. If yes, the certificate invalid.

The absolute path of the files must be specified, for example:
export PGSSLCRL='/home/dbadmin/dws_ssl/sslcert/sslcrl-file.crl'

Default value: null