Volume 3 · Chapter 4 — Identity, Security and Compliance
Data Protection: KMS and Encryption
4.1 Introduction
Encryption is a non-negotiable control for a bank, and on AWS it’s made practical by the Key Management Service (KMS), which manages the cryptographic keys that protect data at rest and in transit. The interview-relevant points are what KMS does, the difference between encryption in transit and at rest, how envelope encryption works, and how key access is itself controlled and audited. Getting encryption right is squarely the customer’s responsibility, and KMS is the service that makes doing so straightforward and auditable across every other service.
4.2 Encryption in Transit and at Rest
There are two distinct things to protect. Encryption in transit protects data as it moves over the network - achieved with TLS, so that traffic between clients and services, and between services, cannot be read if intercepted. Encryption at rest protects data where it’s stored - in S3, EBS volumes, RDS databases, DynamoDB - so that the stored bytes are unreadable without the key, protecting against theft of the underlying storage. A bank encrypts both: TLS everywhere for data in motion, and at-rest encryption on every data store. These are independent controls and you need both - encrypting at rest doesn’t protect data on the wire, and TLS doesn’t protect data sitting in a database.
4.3 What KMS Does
KMS is a managed service that creates and controls the encryption keys used to protect data, and integrates with almost every AWS service so you can enable encryption with a key you control. The keys (KMS keys) never leave KMS in plaintext - cryptographic operations happen inside the service - and KMS handles their secure storage and lifecycle. You can use AWS-managed keys or, for more control, customer-managed keys where you define the key policy, enable rotation, and control precisely who can use the key. Crucially, access to a KMS key is governed by its key policy (a resource-based policy), so using a key to encrypt or decrypt is a permission you grant explicitly - which means encryption also becomes an access-control boundary: even if someone can reach the encrypted data, they can’t read it without permission to use the key.
flowchart LR App[Application] -->|1. request data key| KMS[KMS - holds master key] KMS -->|2. plaintext + encrypted data key| App App -->|3. encrypt data with plaintext data key| Data[(Encrypted data + encrypted data key stored together)] App -.->|4. discard plaintext data key| X[gone from memory] Data -->|to decrypt: send encrypted data key to KMS| KMS
4.4 Envelope Encryption
KMS uses envelope encryption for efficiency and security. Rather than sending large data to KMS to encrypt, the service generates a data key: KMS returns a plaintext data key and an encrypted copy of it. The application encrypts the actual data locally with the plaintext data key (fast, no size limit), then stores the encrypted data alongside the encrypted data key and discards the plaintext key from memory. To decrypt, it sends the encrypted data key to KMS, which returns the plaintext data key (if the caller is authorized), and the data is decrypted locally. The master key never leaves KMS, large data isn’t shipped to KMS, and the data key only exists in plaintext transiently. This pattern is how services like S3 and EBS encrypt large volumes of data efficiently while keeping the master key protected.
4.5 Key Governance and Auditing
Because keys are the crux of data protection, their use is controlled and logged. The key policy defines who can administer the key and who can use it for encryption/decryption, so you separate those duties and grant usage narrowly. Automatic key rotation replaces the underlying key material periodically without changing key references. And every use of a key is logged, so there’s a complete audit trail of who decrypted what and when - essential for a bank’s compliance. For the strictest requirements, customer-managed keys give the bank full control over the key policy and rotation, and there are options for keys backed by dedicated hardware. The overarching point is that encryption on AWS is not just scrambling bytes - it’s a governed, audited, access-controlled system where the ability to use a key is itself a tightly-held permission.
4.6 Banking Production Scenario
A bank enforces encryption everywhere. TLS protects all traffic - client to load balancer, and service to service. Every data store is encrypted at rest with customer-managed KMS keys: S3 buckets of statements, EBS volumes, the RDS PostgreSQL database, and DynamoDB tables. The KMS key policies grant decrypt permission only to the specific application roles that legitimately need it, so encryption doubles as an access boundary - the statements bucket is unreadable even to someone who gains bucket access but lacks key permission. Automatic rotation is enabled, and because every key use is logged, the bank has a full audit trail of access to sensitive data. Organization guardrails deny disabling encryption, so no environment can accidentally store data unencrypted.
4.7 Troubleshooting: Encryption and Key Access
Encryption issues usually revolve around key permissions. An application that can reach encrypted data but gets access-denied on decryption lacks permission to use the KMS key - the fix is to grant the specific role decrypt permission in the key policy, remembering that KMS access is governed by the key policy, not just the identity policy. Cross-account decryption failures mean the key policy doesn’t permit the other account. If a service can’t write encrypted data, it may lack permission to generate a data key. Performance concerns with heavy KMS use are addressed by envelope encryption (which minimizes KMS calls) and data-key caching where appropriate. The consistent principle is that being able to reach encrypted data is not the same as being able to read it - key usage is a separate, explicitly-granted permission - so encryption troubleshooting is really key-policy troubleshooting.
What is KMS, and explain envelope encryption and why it's used.
KMS - the Key Management Service - is AWS’s managed service for creating and controlling the cryptographic keys used to encrypt data, and it integrates with almost every AWS service so you can enable encryption with a key you control. Its defining properties are that the keys never leave KMS in plaintext - cryptographic operations happen inside the service and the master key material is never exposed - and that access to use a key is governed by the key’s policy, so using a key to encrypt or decrypt is an explicit permission you grant. That last point is important because it makes encryption an access-control boundary: even someone who can reach the encrypted data can’t read it without permission to use the key. Envelope encryption is the technique KMS uses to encrypt data efficiently without ever exposing or overusing the master key. Instead of sending your actual data to KMS to encrypt - which would be slow and size-limited - the flow generates a data key: KMS returns two things, a plaintext data key and an encrypted copy of that same data key. Your application encrypts the real data locally using the plaintext data key, which is fast and has no size limit, then stores the encrypted data together with the encrypted copy of the data key, and discards the plaintext data key from memory. To decrypt later, the application sends the encrypted data key back to KMS, which - if the caller is authorized to use the master key - returns the plaintext data key, and the data is decrypted locally. The reasons this is used are compelling: the master key never leaves KMS, so it’s never exposed; large volumes of data are never shipped to KMS, so it’s efficient and scalable; the plaintext data key exists only transiently in memory; and because decryption of the data key requires authorization to use the master key, the master key’s access policy controls access to all the data encrypted under it. This is exactly how services like S3 and EBS encrypt large amounts of data - each object or volume gets its own data key wrapped by the master key. So KMS is the governed, audited key-management service, and envelope encryption is the master-key-protects-data-keys-protect-data pattern that lets you encrypt data of any size efficiently while keeping the master key locked inside KMS and turning key usage into a controlled, auditable permission.
What's the difference between encryption in transit and at rest, and how do you ensure both for a banking workload?
Encryption in transit and encryption at rest protect data in two different states, and a secure system needs both because each addresses a threat the other doesn’t. Encryption in transit protects data while it moves across the network - it’s achieved with TLS, so that traffic between clients and services, and between services internally, is encrypted and unreadable if intercepted on the wire. Encryption at rest protects data where it’s stored - in S3, EBS volumes, RDS databases, DynamoDB - so the stored bytes are unreadable without the key, defending against theft or exposure of the underlying storage media or snapshots. They’re independent: encrypting data at rest does nothing to protect it as it travels the network, and TLS does nothing to protect data sitting in a database, so you must apply both. For a banking workload I ensure encryption in transit by enforcing TLS everywhere - clients connect to the load balancer over HTTPS, the load balancer and internal services communicate over TLS, and connections to the database and other services use TLS - and I can enforce this with policies that deny non-encrypted transport (a condition requiring secure transport). I ensure encryption at rest by enabling it on every data store using KMS keys, preferably customer-managed keys so the bank controls the key policy and rotation: the S3 buckets holding statements, the EBS volumes, the RDS PostgreSQL database, and any DynamoDB tables are all encrypted at rest, and the KMS key policies grant decrypt permission only to the specific application roles that need it, so encryption also acts as an access boundary. I enable automatic key rotation and rely on the fact that every key use is logged to get a full audit trail of access to sensitive data, which compliance requires. Finally, I put organization-level guardrails in place that deny disabling encryption and, ideally, deny creating unencrypted resources, so no environment can accidentally store data in the clear. The result is defense in depth for data: TLS protects it in motion, KMS-backed at-rest encryption protects it in storage, key policies control who can actually read it, and rotation plus logging make the whole thing governed and auditable - which is the standard a bank must meet for both regulation and genuine security.
Chapter Revision Notes
- Encryption in transit (TLS) protects data on the network; encryption at rest protects stored data - apply both, they’re independent.
- KMS creates and controls keys that never leave the service in plaintext; key access is governed by the key policy, making encryption an access boundary.
- Envelope encryption: KMS issues a data key (plaintext + encrypted); encrypt data locally with it, store the encrypted data key, discard the plaintext - master key stays in KMS.
- Customer-managed keys give control of policy and rotation; every key use is logged for a full audit trail.
- Reaching encrypted data isn’t reading it - key usage is a separate permission, so encryption troubleshooting is key-policy troubleshooting.