Skip to main content
← CONCEPTS / SECURITY & IDENTITY
An end-to-end domain learning journey

Encryption at Rest
& in Transit.

Encryption in transit protects data moving across untrusted networks via TLS 1.3/mTLS, while encryption at rest protects persisted disks and backups using AES-256-GCM envelope encryption backed by a KMS.
Start the journey7 sections· Last modified Oct 23, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When a service delegates authority across hops, terminate TLS 1.3 everywhere (including internal service-to-service mTLS), use envelope encryption (DEK + KMS KEK) for storage, and separate key-management permissions from data-storage permissions.

TL;DR30-second simplified summary
▾

Core Mechanics: Data faces two distinct threat surfaces: In Transit: TLS 1.3 (RFC 8446) uses 1-RTT ephemeral ECDHE (Perfect Forward Secrecy) + AEAD ciphers (TLS_AES_256_GCM_SHA384).

Visual & Structural Flow: Depicts TLS 1.3 + mTLS Ingestion & KMS Envelope Encryption with AAD Binding (Browser (TLS 1.3) -> Gateway (mTLS) -> Doc Service -> AWS KMS (KEK) -> S3 (SSE-KMS)); Automated KMS KEK Versioning & SPIFFE mTLS Certificate Rotation (ACTIVE KEK v2 -> RETIRED KEK v1 -> ALERT / REVOKE).

Trade-Offs & Production: Balance real-time revocation against KMS rate limits and operational complexity. Enable automatic annual KEK rotation in KMS (KMS retains old versions transparently for decrypt while encrypting new DEKs under the latest key), rotate short-lived mTLS certs.

Failure Modes & Application: Explore automated TLS rotation, mitigating TLS handshake storms, CSRF defense, and container image scanning.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
API Security: OAuth 2.1, JWT & mTLS
Modern API security pairs OAuth 2.0 (for delegated user/client authorization), signed JWTs (for stateless, verifiable claims), and Mutual TLS (mTLS) (for cryptographic workload and high-assurance client identity).
Full walkthrough · 7 stages
01
STAGE 01 · WHAT IT ISL4 · FUNDAMENTALS

What are Encryption in Transit & Envelope Encryption at Rest.

Why this matters: The mechanism: understand how Encryption in Transit & Envelope Encryption at Rest works from first principles.

Data faces two distinct threat surfaces:

  • In Transit: TLS 1.3 (RFC 8446) uses 1-RTT ephemeral ECDHE (Perfect Forward Secrecy) + AEAD ciphers (TLS_AES_256_GCM_SHA384). Inside clusters, mTLS authenticates both client and server via short-lived X.509 certificates (Istio/SPIRE).
  • At Rest: Envelope encryption encrypts payloads locally with a fast symmetric Data Encryption Key (DEK) (AES-256-GCM + random 96-bit nonce + AAD), then wraps the DEK with a hardware-backed KMS Key Encryption Key (KEK).
02
STAGE 02 · WHY WE NEED ITL4 · FUNDAMENTALS

Why Disk-Only Encryption & Plaintext VPCs Still Leak Data.

Why this matters: The problem: see what breaks without Why Disk-Only Encryption & Plaintext VPCs Still Leak Data under real concurrency or scale.

Think of Why Disk-Only Encryption & Plaintext VPCs Still Leak Data as the intuition layer for Encryption at Rest & in Transit: The problem: see what breaks without Why Disk-Only Encryption & Plaintext VPCs Still Leak Data under real concurrency or scale.

Unencrypted east-west VPC traffic lets any compromised pod sniff credentials, while disk-only EBS/RDS encryption decrypts transparently for DBAs, BI replicas, and SQL injection—requiring app-layer envelope encryption for high-value secrets like OAuth refresh tokens.

Envelope Encryption Flow

TLS 1.3 + mTLS Ingestion & KMS Envelope Encryption with AAD Binding

Browser (TLS 1.3)Gateway (mTLS)Doc ServiceAWS KMS (KEK)S3 (SSE-KMS)1. 1-RTT TLS 1.3 (ECDHE PFS)2. Istio STRICT mTLS (SPIFFE)3. GenerateDataKey -> DEK + encDEK4. AES-256-GCM(DEK, rand96,AAD=tenant)5. s3:GetObject without kms:Decrypt ->…

Separating s3:GetObject from kms:Decrypt ensures a storage/backup leak cannot decrypt payloads without KMS access.

Engineering Decision Framework
Problem
How to implement Encryption at Rest & in Transit without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When a service delegates authority across hops, terminate TLS 1.3 everywhere (including internal service-to-service mTLS), use envelope encryption (DEK + KMS KEK) for storage, and separate key-management permissions from data-storage permissions.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Encryption at Rest & in Transit experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

App-Layer Envelope Encryption for OAuth Tokens

Even with RDS disk encryption, DBAs and BI replicas could read plaintext OAuth refresh tokens. Wrapping per-record AES-256-GCM DEKs with KMS (kms:Decrypt granted only to auth-svc) blocked unauthorized reads.

Enforcing TLS 1.3 + STRICT mTLS (<1.2 ms Overhead)

Enforcing TLSv1.3 on edge ALB, sslmode=verify-full on Postgres, and Istio STRICT mTLS secured east-west traffic with <1.2 ms p99 overhead via TLS session resumption.

03
STAGE 03 · WHERE IT IS USEDL5 · APPLIED DESIGN

Where Each Encryption Layer Fits (and What It Doesn't Protect).

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Think of Where Each Encryption Layer Fits (and What It Doesn't Protect) as the intuition layer for Encryption at Rest & in Transit: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Never confuse disk encryption with app-layer field encryption—and never encrypt passwords (hash them with Argon2id or bcrypt).

ChoiceWhat it buysWhat it costs
Storage-Layer (EBS / S3 SSE-KMS / RDS TDE)Transparent to SQL queries, indexes, and ORMs; stops physical drive/snapshot leaks.Does NOT stop DBA snooping, BI replica leaks, or SQLi on authorized app roles.
App-Layer Envelope (`AES-256-GCM` + AAD)Protects sensitive PII/tokens even from DBAs and cross-tenant blob swaps (`AAD=tenantId`).Disables SQL range (`>`/`<`) and `LIKE` indexes; exact lookup needs HMAC blind indexes.
Avoid: `sslmode=require` or `InsecureSkipVerify: true`Always use `sslmode=verify-full` with pinned CA bundles.`require` encrypts the wire but skips hostname/CA checks, leaving connections open to MitM.
04
STAGE 04 · HOW IT IS MANAGEDL5 · APPLIED DESIGN

How to Prevent GCM Nonce Reuse, Bind AAD & Cache DEKs.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

1.

Never Reuse a 96-Bit GCM Nonce: Reusing (key, nonce) leaks the XOR of plaintexts and compromises GHASH—always generate os.urandom(12) per call and rotate DEKs well before 2^30 messages. 2. Bind AAD (tenantId:recordId): Stops an attacker with DB write access from copying Tenant A's ciphertext into Tenant B's row. 3.

Component Topology

How to Prevent GCM Nonce Reuse, Bind AAD & Cache DEKs

CalleringressRouter / APIcomputeProcessorstorageState Layercontrolrequestdispatchread/write
# AES-256-GCM authenticated encryption with fresh 96-bit nonce & tenant AAD (Python)
import os
from cryptography.hazmat.primitives.ciphers.aead import AESGCM

def encrypt_field(dek_32b: bytes, plaintext: bytes, tenant_id: str, record_id: str) -> tuple[bytes, bytes]:
    nonce = os.urandom(12)  # Fresh 96-bit CSPRNG nonce per encryption
    aad = f"{tenant_id}:{record_id}".encode("utf-8")
    ciphertext = AESGCM(dek_32b).encrypt(nonce, plaintext, aad)
    return nonce, ciphertext
05
STAGE 05 · ALTERNATIVESL6 · SCALE & TRADE-OFFS

Alternatives: KMS Call Per-Request vs. DEK Caching & Edge vs. Mesh TLS.

Why this matters: The trade-off: compare competing approaches across latency, consistency, and operational cost.

Think of Alternatives: KMS Call Per-Request vs. DEK Caching & Edge vs. Mesh TLS as the intuition layer for Encryption at Rest & in Transit: The trade-off: compare competing approaches across latency, consistency, and operational cost.

Balance real-time revocation against KMS rate limits and operational complexity.

ChoiceWhat it buysWhat it costs
Bounded Local DEK Cache (5-min TTL via AWS Encryption SDK)Avoids KMS API throttling (5.5k–30k req/s) and saves 5–15 ms per decrypt.Revoked KMS keys remain usable in cache up to the 5-min TTL.
Istio / SPIRE `STRICT` mTLS EverywhereCryptographic workload identity + 24h automated X.509 cert rotation.Adds cert-manager/mesh ops; breaks plain-TCP probes unless configured.
06
STAGE 06 · PRODUCTION ARCHITECTUREL7 · STAFF / PRINCIPAL

Production Architecture: Automated Key & Certificate Rotation.

Why this matters: Production architecture: see how the components compose end to end under real load.

Think of Production Architecture: Automated Key & Certificate Rotation as the intuition layer for Encryption at Rest & in Transit: Production architecture: see how the components compose end to end under real load.

Enable automatic annual KEK rotation in KMS (KMS retains old versions transparently for decrypt while encrypting new DEKs under the latest key), rotate short-lived mTLS certs every 24 hours, and alert <14 days before any public TLS cert expiry.

Key & Cert Lifecycle

Automated KMS KEK Versioning & SPIFFE mTLS Certificate Rotation

Annual auto-rotationSIEM bulk-decrypt alertACTIVE KEK v2Encrypts new DEKsRETIRED KEK v1Decrypt-only legacyALERT / REVOKEAnomalous kms:Decrypt

KMS key versioning rotates KEKs annually with zero downtime while keeping historical DEKs decryptable.

07
STAGE 07 · PROBLEMS SOLVED & FURTHER DEEP DIVEL7 · STAFF / PRINCIPAL

Problems solved & Related Concepts.

Why this matters: Applied problems: connect these internals to concrete system design and debugging scenarios.

Think of Problems solved & Related Concepts as the intuition layer for Encryption at Rest & in Transit: Applied problems: connect these internals to concrete system design and debugging scenarios.

Explore automated TLS rotation, mitigating TLS handshake storms, CSRF defense, and container image scanning.

Design Trade-Off

Problems solved & Related Concepts

Before · Unbounded Coupling
  • No backpressure on spikes
  • Implicit shared state
  • Cascading tail latency
After · Bounded & Observable
  • Explicit capacity budgets
  • Isolated failure domains
  • Predictable p99 latency
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

A service encrypts sensitive fields using `AES-256-GCM` with a KMS-wrapped DEK, but omits `AAD` (`tenantId`). What attack does this leave open?

Recommended Learning Flow