SkillSprout
Chapter 9 · Lesson 2
Advanced
5 min read

Client-Side vs Server-Side Encryption, Cross-Account Keys and Rotation

Overview

AWS can encrypt data server-side, where the service encrypts after receiving plaintext, or you can encrypt client-side before data ever leaves your application. Each has different trust, performance and key-management consequences. You also need to handle cross-account key access and key rotation.

Server-side encryption is like handing documents to a bank clerk who locks them in a vault for you. Client-side encryption is locking the documents in your own briefcase first, so the bank only ever stores a sealed case.

DVA-C02 asks you to choose the right option for a requirement, use keys correctly, and enable or disable rotation on KMS keys.

Key Concepts

  • SSE-S3 uses S3-managed keys (default for new objects); SSE-KMS uses KMS keys with audit and access control; DSSE-KMS applies two layers; SSE-C uses customer-provided keys sent per request over HTTPS.
  • Client-side encryption with the AWS Encryption SDK or S3/DynamoDB encryption clients means AWS only sees ciphertext.
  • KMS limits direct Encrypt to 4 KB; larger data uses envelope encryption with a data key from GenerateDataKey.
  • Cross-account use requires a key policy that trusts the other account plus an IAM policy in that account granting the KMS actions.
  • Grants give temporary, programmatic permission to use a key and are used by many AWS services.
  • Automatic rotation for customer managed symmetric keys creates new key material every year by default (configurable 90 days to 7 years); the key ID and ARN stay the same.
  • AWS managed keys rotate automatically every year; you cannot disable it. Asymmetric and imported keys do not auto-rotate.
  • Encryption context is authenticated additional data that binds ciphertext to a purpose and appears in CloudTrail.

Detailed Notes

Choosing an encryption model

RequirementChoice
Encrypt everything with minimal effortSSE-S3 (default)
Audit each use and control access with key policySSE-KMS
Keep keys fully under your control, not stored by AWSSSE-C or client-side
AWS must never see plaintextClient-side encryption
Field-level protection in DynamoDBDynamoDB Encryption Client or Encryption SDK
Regulatory dual-layerDSSE-KMS

Server-side with KMS is simplest, but plaintext reaches AWS before encryption. Client-side guarantees AWS only sees ciphertext but the application owns key handling, algorithms and performance.

Client-side envelope encryption with the Encryption SDK

python
import aws_encryption_sdk
from aws_encryption_sdk import CommitmentPolicy

client = aws_encryption_sdk.EncryptionSDKClient(
    commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
kms = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(
    key_ids=["arn:aws:kms:eu-west-1:111122223333:key/abcd-1234"])

ciphertext, header = client.encrypt(
    source=b"patient record", key_provider=kms,
    encryption_context={"purpose": "records", "tenant": "t-42"})
plaintext, _ = client.decrypt(source=ciphertext, key_provider=kms)

The SDK requests a data key, encrypts locally, and stores the encrypted data key in the message. Decryption requires kms:Decrypt on the CMK.

SSE-KMS on S3 and bucket keys

bash
aws s3api put-bucket-encryption --bucket my-bucket --server-side-encryption-configuration \
 '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"aws:kms","KMSMasterKeyID":"alias/app-data"},"BucketKeyEnabled":true}]}'

S3 Bucket Keys reduce KMS requests (and cost) by generating a bucket-level key. Heavy use of SSE-KMS can hit KMS request quotas, which appear as throttling errors.

Cross-account key access

Account A owns the key; a role in account B must decrypt.

json
{ "Sid": "AllowAccountB",
  "Effect": "Allow",
  "Principal": { "AWS": "arn:aws:iam::444455556666:root" },
  "Action": ["kms:Decrypt", "kms:DescribeKey", "kms:GenerateDataKey"],
  "Resource": "*" }

and in account B the role's IAM policy must allow the same actions on the key ARN. Both sides are required. For S3, the bucket policy must also allow the principal. AWS managed keys (aws/s3) cannot be shared cross-account, so use a customer managed key. When sharing encrypted EBS snapshots or RDS snapshots, share the key too.

Key rotation

bash
aws kms enable-key-rotation --key-id alias/app-data --rotation-period-in-days 180
aws kms get-key-rotation-status --key-id alias/app-data
aws kms rotate-key-on-demand --key-id alias/app-data

Rotation adds new backing key material while old material stays available to decrypt existing ciphertext, so no re-encryption is required and applications do not change. To "rotate" an asymmetric or imported key, create a new key and update an alias to point to it; callers using the alias are unaffected but old data must still be decryptable with the old key.

bash
aws kms update-alias --alias-name alias/app-data --target-key-id 5678abcd-...

Disabling a key makes ciphertext unreadable until re-enabled; scheduling deletion has a 7 to 30 day waiting period and is irreversible afterwards.

DynamoDB and other service encryption

DynamoDB always encrypts at rest (AWS owned, AWS managed or customer managed key). For attribute-level protection before data reaches DynamoDB use the client-side encryption library, noting that encrypted attributes cannot be used in key conditions or filters on plaintext.

Encryption context in practice

Supplying the same EncryptionContext on decrypt prevents a ciphertext from being used for a different purpose. Add conditions like kms:EncryptionContext:tenant to key policies for tenant-aware access, and search CloudTrail for the context during investigations.

Real World Example

A healthcare SaaS needed assurance that raw patient notes never reach AWS in plaintext. They encrypt each note with the Encryption SDK using a customer managed KMS key and an encryption context containing the tenant ID before writing to S3. A partner account in another AWS organization reads exports through a cross-account key policy plus IAM policy. Annual automatic rotation is enabled, and auditors verify it with get-key-rotation-status.

Architecture Diagram

Client-side envelope encryption
Architecture
Encryption flow
ApplicationEncryption SDK
KMS keyCMK
Encrypt locallyAES-GCM
S3 / DynamoDB

The app encrypts locally with a KMS-issued data key and stores only ciphertext.

  1. 1The application asks KMS for a data key with an encryption context.
  2. 2KMS returns the plaintext key and the encrypted copy.
  3. 3The app encrypts the data locally and discards the plaintext key.
  4. 4It stores ciphertext plus the encrypted data key; decrypt reverses the process.

Best Practices

  • ✓Choose SSE-KMS for auditability and client-side when AWS must never see plaintext.
  • ✓Enable S3 Bucket Keys to cut KMS request costs and throttling.
  • ✓Use customer managed keys for cross-account sharing; AWS managed keys cannot be shared.
  • ✓Turn on automatic rotation and use aliases so applications never reference key IDs directly.
  • ✓Always supply an encryption context and restrict it in key policies.

Common Interview Questions

Exam Tips

DVA-C02 focus

  • 'AWS must not see plaintext' means client-side encryption.
  • Data larger than 4 KB requires envelope encryption (GenerateDataKey).
  • Cross-account KMS needs both key policy and IAM policy; AWS managed keys are not shareable.
  • Rotation does not change the key ARN and requires no re-encryption; imported and asymmetric keys do not auto-rotate.

Finished this lesson?

0 of 46 lessons done · 0% of the course