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.
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).
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.
TLS 1.3 + mTLS Ingestion & KMS Envelope Encryption with AAD Binding
Separating s3:GetObject from kms:Decrypt ensures a storage/backup leak cannot decrypt payloads without KMS access.
- 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.
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.
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).
| Choice | What it buys | What 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. |
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.
How to Prevent GCM Nonce Reuse, Bind AAD & Cache DEKs
# 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
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.
| Choice | What it buys | What 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 Everywhere | Cryptographic workload identity + 24h automated X.509 cert rotation. | Adds cert-manager/mesh ops; breaks plain-TCP probes unless configured. |
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.
Automated KMS KEK Versioning & SPIFFE mTLS Certificate Rotation
KMS key versioning rotates KEKs annually with zero downtime while keeping historical DEKs decryptable.
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.
Problems solved & Related Concepts
- No backpressure on spikes
- Implicit shared state
- Cascading tail latency
- Explicit capacity budgets
- Isolated failure domains
- Predictable p99 latency
Practice: Make the trade-off yourself.
A service encrypts sensitive fields using `AES-256-GCM` with a KMS-wrapped DEK, but omits `AAD` (`tenantId`). What attack does this leave open?