Course contentsShow
← Databases & SQL
Lesson 1594 of 1,95315. Database Security and GovernanceFree lesson

Securing Data in Transit

You will be able to configure TLS/SSL connectivity requirements for all client-to-database communication.

In this lesson, you will learn how to enforce TLS/SSL requirements to ensure all client-to-database communication is encrypted, preventing data interception and tampering.

Even with robust authentication, such as the Role-Based Access Control and Multi-Factor Authentication strategies we covered earlier, your sensitive data remains vulnerable if it travels over the network in plaintext. Securing data in transit ensures that the "pipe" between your application and the database is effectively a private, encrypted tunnel.

Enforcing Encrypted Connectivity

To secure transit, you must move beyond opportunistic encryption and enforce mandatory TLS (Transport Layer Security) requirements at both the database server level and the client connection string.

On the server side, you configure the database to reject non-encrypted connections entirely. For example, in many PostgreSQL environments, you manage this via the pg_hba.conf file by specifying the hostssl record:

# Only allow encrypted connections for the application user
hostssl    app_db    app_user    10.0.0.5/32    scram-sha-256

By using hostssl instead of host, the database engine will terminate any attempt to connect via standard TCP, forcing the client to perform the TLS handshake.

The Client Perspective

On the application side, the connection string must be configured to verify the server's identity. If you omit the verification, you remain susceptible to "man-in-the-middle" attacks, where an adversary intercepts the traffic by masquerading as your database. Your application’s connection configuration should look similar to this:

jdbc:postgresql://db-server:5432/app_db?ssl=true&sslmode=verify-full&sslrootcert=/path/to/ca-cert.pem

By setting sslmode=verify-full, the client driver confirms that the database server presents a certificate signed by a trusted Certificate Authority (CA) and that the hostname matches the certificate's identity. This creates a chain of trust that protects your credentials and query data from being read or modified by malicious intermediaries.

When combined with your existing knowledge of connection string sanitization and ephemeral credentials, enforcing TLS ensures that the entire lifecycle of a database request—from the moment the app establishes a connection to the execution of the final query—remains confidential and authenticated.

Key Takeaway: Enforcing TLS/SSL for database connectivity is non-negotiable for enterprise security, as it prevents plaintext data exposure and verifies the identity of the database server during the handshake process.