Quick revision
The short answer
Encryption at rest protects data when storage leaves our control, such as a stolen disk, a copied snapshot or a lost backup, but it does nothing against someone who can run SQL or a compromised application, because the database decrypts data for every authorised query. For data in transit, we connect with sslmode=verify-full and the CA certificate in sslrootcert, so the driver both encrypts the connection and checks that the server is really our database. On the server, ssl = on and hostssl rules in pg_hba.conf reject plain connections.
What to remember
In this answer, we separated three kinds of encryption. Encryption at rest protects disks, snapshots and backups but not data reached through SQL or a compromised application, because the database decrypts it for every authorised query. In transit, we used sslmode=verify-full with sslrootcert so the driver encrypts and verifies the server's identity, while require would leave us open to a man in the middle. On the server, ssl = on and hostssl and reject rules in pg_hba.conf enforce TLS, and application-level encryption with keys in a KMS protects the few fields even administrators must not read.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Encryption at rest protects data when storage leaves our control, such as a stolen disk, a copied snapshot or a lost backup, but it does nothing against someone who can run SQL or a compromised application, because the database decrypts data for every authorised query. For data in transit, we connect with sslmode=verify-full and the CA certificate in sslrootcert, so the driver both encrypts the connection and checks that the server is really our database. On the server, ssl = on and hostssl rules in pg_hba.conf reject plain connections.
Why this question is asked
Encryption is often discussed as a single checkbox, and that is how teams end up believing their data is safe from a SQL injection because the disk is encrypted, or believing their connection is secure because it uses TLS without checking who is on the other end. Interviewers ask this question to see whether we understand what each layer actually protects against. In this answer, we will recap the kinds of encryption, see what encryption at rest does and does not protect, configure a Spring Boot service to connect to PostgreSQL over verified TLS, enforce TLS on the server, and look at field-level encryption for data even administrators should not read.
1A Quick Recap of the Kinds of Encryption
Encryption at rest means the data is encrypted where it is stored: on the disk, the cloud volume, the snapshot or the backup file. It can be done by the disk, the volume or the cloud provider, or by the database itself, which is called transparent data encryption because applications do not notice it. Encryption in transit means the network traffic between the application and the database is encrypted, which for PostgreSQL means TLS on the connection.
There is a third kind that is easy to forget: application-level or column-level encryption, where the application encrypts a field before it ever reaches the database. Each of the three protects against a different threat, so we need to be precise about which one we mean.
| Threat | At rest | TLS in transit | Application-level |
|---|---|---|---|
| Stolen disk, snapshot or backup | yes | no | yes |
| Network sniffing between app and DB | no | yes | yes, for those fields |
| Fake database server (man in the middle) | no | only with verify-full | partly |
| SQL injection or stolen app password | no | no | yes, unless the app decrypts it |
| DBA reading the table | no | no | yes |
2What Encryption at Rest Does Not Protect
The key thing to understand is when the decryption happens. With encryption at rest, the database server or the storage layer decrypts pages as it reads them, for every query from every role that has the privilege. So an attacker who gets SQL access, through injection, a leaked application password or an over-privileged account, sees plaintext. So does a compromised application server, because it receives query results like any client. Encryption at rest is still important, because backups and snapshots are copied around and disks are replaced, but it is a defence for the storage, not for the data's access path.
3Connecting Spring Boot to PostgreSQL Over Verified TLS
The PostgreSQL JDBC driver controls TLS with the sslmode parameter. Its default, prefer, tries TLS and silently falls back to plain text if the server does not offer it, which an attacker on the network can arrange. Mode require insists on encryption but does not check the server certificate, so a man-in-the-middle with any certificate can decrypt and re-encrypt the traffic. Mode verify-ca checks that the certificate was signed by our CA, and verify-full also checks that the host name in the URL matches the certificate, which is what we want.
7 messages in order. Play them, or step through them one at a time.
require would skip both checks on the client side; verify-full makes them mandatory.
Notice that sslrootcert points to the CA certificate that signed the server's certificate, mounted into the container from a secret or config map, not to the server certificate itself. If the CA is a public one or our cloud provider's, we use its published bundle. With verify-full, a typo in the host name or a certificate without the right name fails the connection at start-up, which is exactly the point: we would rather fail loudly than talk to the wrong server.
4Enforcing TLS on the Server
Client settings are not enough on their own, because one misconfigured client could still connect in plain text. So the server must refuse non-TLS connections.
In pg_hba.conf, a hostssl line matches only connections that use TLS, and hostnossl matches only those that do not. Because the file is read from the top and the first match decides, the result is that our application subnet can log in over TLS with a password, and any plain-text connection from anywhere is rejected. Managed services usually expose the same rule as a setting, such as a parameter that forces SSL; check your provider.
5Field-Level Encryption for the Most Sensitive Data
For a few fields, such as national ID numbers or bank details, we may need protection even from people with SQL access, including database administrators. Then the application encrypts the value with a key the database never sees, typically with an authenticated cipher such as AES-GCM and a key from a key management service. The database stores only ciphertext. The cost is that the database can no longer search, sort or index the plaintext, so we use it for specific fields rather than whole tables.
6Follow-up questions
Where do you keep the encryption keys?
Never next to the data they protect. For disk and backup encryption, keys live in the cloud provider's key management service or a hardware security module, with access limited to the storage service and audited. For application-level encryption, we use envelope encryption: a master key stays inside the KMS and is used only to encrypt data keys, the encrypted data key is stored with the data, and the application asks the KMS to decrypt it when needed. So a copy of the database or backup is useless without KMS access, and every decryption request is logged.
What does the Java service need to trust a private CA?
Only the CA certificate file, passed with sslrootcert. The PostgreSQL driver uses its own trust handling for that file, so we do not need to add the CA to the JVM's default trust store, which keeps the trust narrow to this connection. If we use client certificates as well, we pass sslcert and sslkey the same way; check the driver documentation for the key format it expects.
Is TLS between the service and the database necessary inside a private network?
Yes in most environments. Private networks are shared with many other workloads, and an attacker who gets a foothold anywhere in it could read or alter traffic. TLS with verification costs little CPU on modern hardware and removes the whole class of network attacks.
7Conclusion
In this answer, we separated three kinds of encryption. Encryption at rest protects disks, snapshots and backups but not data reached through SQL or a compromised application, because the database decrypts it for every authorised query. In transit, we used sslmode=verify-full with sslrootcert so the driver encrypts and verifies the server's identity, while require would leave us open to a man in the middle. On the server, ssl = on and hostssl and reject rules in pg_hba.conf enforce TLS, and application-level encryption with keys in a KMS protects the few fields even administrators must not read.
Open with
Encryption at rest, whether on the disk, the cloud volume or transparent database encryption, protects against storage leaving our control: a stolen disk, a copied snapshot, a lost backup.
Then, if they want more
It does not protect against anyone who can run SQL, through injection or a leaked password, or against a compromised application, because the database decrypts the data for every authorised query.
For in transit, the PostgreSQL JDBC driver defaults to prefer, which can silently fall back to plain text, and require encrypts but does not check the certificate, so a man in the middle still works. So I set sslmode=verify-full in the JDBC URL with sslrootcert pointing to our CA certificate.
Then the driver checks that the certificate is signed by our CA and that the host name matches, and a wrong server fails at start-up.
On the server I set ssl = on with a minimum TLS version, and in pg_hba.conf I use hostssl lines for allowed clients and a hostnossl reject line, so plain connections are refused even from a misconfigured client.
For the most sensitive fields, like national IDs, I would add application-level encryption with AES-GCM and keys in a KMS using envelope encryption, so even DBAs only see ciphertext. Keys never live next to the data they protect.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What does encryption at rest protect against and what does it not protect against? How...": https://scrivio-interview-library.netlify.app/databases/database-security/9668ea45cf/