skip to content

When a client application connects to a relational database over TLS, what exactly is protected, and which threats does that encryption not address?

level: juniorimportance: must knowfreq 55%

answer

  1. wire only, never disk or backups
  2. confidentiality + integrity + server identity
  3. credentials cross first
  4. encryption is not authorization
  5. TLS ends at the pooler

basics

~20 s

TLS protects the wire: credentials, SQL text, parameters and result rows cannot be read or silently altered by anyone on the network path, and the client can verify it reached the real server. It does nothing for data on disk, backups, in-database authorization, or a compromised host.

solid answer

~50 s

TLS on a database connection gives three things for the bytes on the wire: confidentiality (an eavesdropper cannot read credentials, SQL, bind parameters or result rows), integrity (an active attacker cannot tamper with a query or a result undetected), and server authentication (the client can prove it reached the intended database and not an impostor) -- the last one only if the client actually verifies the certificate. Optionally it also authenticates the client, via a client certificate. What it does not do: it does not encrypt rows stored in data files, redo/WAL logs or backups (a separate at-rest control); it does not decide who may read what (that is the privilege system); and it is worthless once an endpoint is compromised, since both ends handle plaintext. It also stops wherever TLS is terminated, so a pooler or proxy in front of the database means the hop behind it needs its own encryption.

go deeper

for a junior

Recall the three guarantees (confidentiality, integrity, server identity) and the clean line between in transit and at rest.

for a middle

Add that server identity depends on the client's verification mode, and that credentials are the first thing on the wire.

for a senior

Talk about verifying real connections in production, replication and backup streams, and the plaintext hop behind a TLS-terminating pooler.

for a principal

Frame it as a threat model and boundary question: what the control buys per network segment, what it costs operationally (expiry, rotation), and where it must be non-negotiable.

## What is on the wire A database session is a long-lived TCP conversation carrying, in order: a startup message, an authentication exchange (password, hash, challenge-response or token), then every SQL statement, every bind parameter, and every row of every result set for the life of the connection. Anyone able to observe that path -- another workload on the same subnet, a compromised switch or hypervisor, a cloud operator, someone tapping a link between availability zones -- sees all of it in cleartext if TLS is off. That is why the database connection is a high-value target: it carries credentials *and* the crown-jewel data, and it is usually long-lived enough to be worth watching. ## The three guarantees **Confidentiality.** Once the session is encrypted, an observer sees only ciphertext plus traffic metadata (endpoints, timing, byte counts). Note the leftovers: the fact that a connection exists, its volume and its timing are still visible. **Integrity.** TLS records are authenticated, so an active attacker cannot flip a byte in your UPDATE, swap a row in a result set, or splice data in without the connection failing. Without TLS, a network attacker is not limited to reading -- they can rewrite the statement. **Server authentication.** The client checks the server's certificate against a trusted CA and against the hostname it dialled. This is what stops a man-in-the-middle from terminating your connection, harvesting the password, and proxying to the real database. Crucially this guarantee is *opt-in per client*: a mode that encrypts without validating the certificate gives confidentiality against a passive listener and nothing at all against an active one. **Client authentication (optional).** If the deployment requires a client certificate, the server also gets cryptographic proof of who is connecting, instead of (or in addition to) a shared secret. ## What is out of scope - **Data at rest.** Table files, indexes, redo logs, temp files and backups are unaffected. Someone who steals a disk image or a backup file is untouched by transit encryption. - **Authorization.** TLS says nothing about which tables or columns the connected role may read; grants and roles do that. "The connection is encrypted" is not an answer to "why can this service read the salaries table". - **Endpoint compromise.** Malware on the app host, a debug log that prints SQL and parameters, or a compromised database host all see plaintext regardless. - **Everything past the termination point.** If a pooler, sidecar proxy or load balancer terminates TLS, the segment from there to the database is a separate connection that must be encrypted separately, or you have just moved the plaintext hop. - **Application-layer leaks.** Query text in an APM trace or an error message is not covered. ## Consequences worth stating in an interview Because the credentials cross the wire before anything else, an unencrypted connection leaks the account that everything else depends on. Because replication and backup streams are also just client connections, they need the same treatment -- a hardened application path with a plaintext replica feed carries the same rows. And because "we are inside a private network" only shifts the attacker model to lateral movement, it is a reason to think about cost, not a reason to assume safety. ## How to verify Don't take the config file's word for it. Most engines expose, per live connection, whether it is encrypted; check that view (or the connection log line) in production and count the plaintext sessions. Configuration that *allows* TLS is not the same as clients that *use* it.

  • The database sits on a private subnet with no internet route. Is TLS still worth enabling?
    Yes, in almost every case. A private network is a boundary against outsiders, not against a compromised neighbouring workload, a stolen internal credential, or an operator on the shared infrastructure -- and lateral movement is the normal shape of a real breach. Modern CPUs make the symmetric cost negligible, and pooled connections amortise the handshake, so the argument is usually about operational risk (certificate expiry) rather than performance.
  • Does encrypting the connection protect the rows once they are written to the table?
    No. Transit encryption covers only the bytes travelling between client and server; the moment the server decrypts them, they are written to data files, redo logs and later backups in whatever form the storage layer uses. Protecting stored data is a distinct control with a distinct threat model (stolen media, snapshots, backup files) and does not follow from TLS being on.

saying these in an interview costs you the question

  • Saying TLS means the data is encrypted in the database
  • Claiming a plaintext connection is fine because the password is hashed -- the session and the data are still exposed, and an active attacker can rewrite statements
  • Assuming a firewall or private VPC makes man-in-the-middle impossible
  • Believing that setting ssl=true or 'require' means the certificate was validated
  • Forgetting that a pooler or proxy terminating TLS leaves the hop behind it in plaintext

context