Course map

Topic 164 / Core

Encryption at rest and in transit

Chapter 10.3 · Protecting Data

What and why

Access control (→ 159–163) decides who may ask for data; encryption protects the data itself if every other control fails — a stolen disk, an intercepted connection, a database backup left somewhere it shouldn't be. Encryption in transit protects data while it moves across a network. Encryption at rest protects data while it's stored. Neither protects data once it's decrypted and sitting in application memory, logs, or a screen — encryption has a precise scope, and knowing that scope matters more than the algorithm used. Builds on: → 27 (TLS and secure communication).

Diagram

Layer Protects against Does not protect against
In transit (TLS, → 27; mTLS between services) Network eavesdropping, interception, tampering in flight Data already decrypted at either endpoint
At rest — volume/disk encryption A stolen disk or backup medium A breach using valid application/database credentials
At rest — application-level field encryption Even the database operator reading the raw value Added query complexity (can't index or search the plaintext directly)

How it works

  1. Encrypt everywhere in transit — not only at the public edge; service-to-service traffic inside the perimeter uses mTLS too, because "internal" is not "safe" (→ 169).
  2. Encrypt at rest as a baseline: volume or disk-level encryption protects against physical media theft with near-zero application changes.
  3. For the small set of fields that need protection even from your own database operators, add application-level field encryption on top of the baseline.
  4. Use envelope encryption for that field-level case: encrypt the data with a data key, then encrypt (wrap) the data key with a master key held in a KMS — rotating the master key re-wraps only the data keys, never the bulk data itself.
  5. Decide the level needed per data classification — not every field needs field-level encryption, and treating all data identically either overspends on the trivial fields or underprotects the sensitive ones.

Practical example

(illustrative). A payments table stores a card-reference token (never the raw card number — tokenization and PCI scope, → 171), and that token column is additionally protected with envelope encryption: a per-row data key encrypts the value, and a master key in a KMS wraps every data key. Rotating the master key re-wraps the (much smaller) set of data keys, not every row in the table — the cost of key rotation stays constant as the table grows.

When to use it

  • Use in-transit encryption always, with no exceptions, including traffic that never leaves a private network.
  • Use at-rest volume encryption as a baseline always.
  • Add field-level/envelope encryption only for the highest-sensitivity fields — it adds real cost (key management, query limitations) that most fields don't need.
  • Failure scenarios: internal traffic left unencrypted "because it's inside the VPC" (the exact assumption zero trust, → 169, rejects); sensitive values logged in plaintext despite being encrypted at rest, defeating the protection entirely; a leaked master key exposing every data key it wrapped.
  • Simpler alternative: for most data, volume-level at-rest encryption plus TLS in transit is sufficient on its own; reach for field-level encryption only when a specific field needs protection from your own operators, not as a default everywhere.

Practice

(Decision kind — judge scenarios and defend the choice; 20 min, lab: Postgres). Verify the lab's Postgres connection uses TLS. Then, for three columns in a schema you've designed (e.g. a user's email, a password hash, a session token), decide for each: volume encryption alone, or field-level envelope encryption, and justify the choice by naming who specifically must not be able to read the plaintext. Done when each of the three columns has a named threat the chosen level actually defeats.

Shared lab setup

Key takeaway

Encryption protects data in two distinct places — in transit and at rest — and each has a precise boundary past which it offers no protection at all. Done when you can: for a given breach scenario, say whether encryption at rest, in transit, both, or neither would have stopped it. Used next in → 165 (the keys this topic assumed already existed).

References

None — this topic makes no external claims.

Source directory

Search the guide