Sub topic 8
Encrypting data at rest and in transit
This chapter assumes you can create a bucket, upload objects with the AWS CLI or boto3, and read an IAM or bucket policy. It covers two separate protections. Encryption at rest protects the stored bytes. Encryption in transit protects the bytes while they move between a client and S3.
The two halves of S3 encryption
S3 encrypts every new object at rest by default. Since January 2023, all new objects are encrypted with server-side encryption using S3-managed keys (SSE-S3), and you cannot turn this off. So the real question is not whether objects are encrypted. The question is who controls the key and who can audit its use.
Encryption in transit is different. S3 accepts both HTTP and HTTPS on its endpoints. Nothing forces a client to use HTTPS unless you add a policy that rejects plain HTTP.
| Concern | Default behavior | What you control |
|---|---|---|
| At rest | SSE-S3 on all new objects | Which key type, and whether to require it |
| In transit | HTTPS is available, HTTP is also accepted | A bucket policy that denies non-HTTPS requests |
Server-side encryption options
With server-side encryption, S3 encrypts the object before writing it to disk and decrypts it when an authorized request reads it. Your application sends and receives plaintext (over TLS). S3 offers these server-side modes:
- SSE-S3. S3 owns and manages the keys. There is no extra charge and no key management work. You get no per-key audit trail and no way to restrict who can use the key beyond S3 permissions.
- SSE-KMS. The object is encrypted with a data key protected by an AWS Key Management Service (KMS) key. You can use the AWS managed key
aws/s3or a customer managed key. Each use of the key is logged in AWS CloudTrail, and the key has its own key policy. A caller needs both S3 permissions and KMS permissions to read the object. - DSSE-KMS. Dual-layer server-side encryption applies two independent layers of encryption with KMS keys. It exists for compliance regimes that require it.
- SSE-C. You supply the key with every request. S3 uses it to encrypt or decrypt and then discards it. You must store and manage the key yourself, and requests must use HTTPS. Newer buckets disable SSE-C by default, and AWS recommends against it for new designs.
Client-side encryption is a separate approach. Your application encrypts the data before sending it, so S3 only ever stores ciphertext. You manage the keys and the decryption logic.
How SSE-KMS works internally
SSE-KMS uses envelope encryption. S3 asks KMS for a data key, encrypts the object with that data key, and stores the encrypted copy of the data key alongside the object. To read the object, S3 asks KMS to decrypt the data key, which requires the caller to be allowed to use the KMS key.
Two consequences follow from this design:
- Every request that touches an SSE-KMS object can call KMS. KMS has per-Region request quotas and charges per request. A workload that reads millions of small objects can hit throttling or build up cost.
- Access to the data can be revoked at the key level. If you disable the KMS key or remove a principal from the key policy, that principal can no longer read the data, even if S3 permissions still allow it.
S3 Bucket Keys
A bucket key reduces KMS traffic. S3 generates a short-lived bucket-level key from KMS and uses it to create data keys for objects in the bucket, so most object operations no longer call KMS. AWS states this can cut KMS request costs substantially. The trade-off is that CloudTrail shows KMS events for the bucket key instead of one event per object, which gives a less granular audit trail.
Setting default encryption
Default encryption applies to uploads that do not specify an encryption mode. You set it per bucket. This example sets SSE-KMS with a customer managed key and enables a bucket key.
aws s3api put-bucket-encryption \
--bucket my-example-bucket-123456789012 \
--server-side-encryption-configuration '{
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms",
"KMSMasterKeyID": "arn:aws:kms:eu-west-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab"
},
"BucketKeyEnabled": true
}
]
}'Replace the key ARN with one from your account. Confirm the result with aws s3api get-bucket-encryption --bucket my-example-bucket-123456789012.
Changing the default does not re-encrypt objects that already exist. To change the encryption of existing objects, copy them over themselves with the new settings, or use S3 Batch Operations for large sets.
You can also request a mode per upload. With boto3:
import boto3
s3 = boto3.client("s3")
s3.put_object(
Bucket="my-example-bucket-123456789012",
Key="reports/2026/summary.txt",
Body=b"quarterly summary",
ServerSideEncryption="aws:kms",
SSEKMSKeyId="arn:aws:kms:eu-west-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab",
)
head = s3.head_object(
Bucket="my-example-bucket-123456789012",
Key="reports/2026/summary.txt",
)
print(head["ServerSideEncryption"], head["SSEKMSKeyId"])The head_object call returns the metadata for the object, including the encryption mode that was applied. It does not download the body.
Required permissions for SSE-KMS
A principal that uploads to an SSE-KMS bucket needs kms:GenerateDataKey on the key. A principal that downloads needs kms:Decrypt. These permissions must be granted in the IAM policy, the key policy, or both, depending on how the key policy is written. The most common failure is an AccessDenied error on a GetObject call where the S3 permissions are correct. Check the KMS side first.
Cross-account access adds one more requirement. The key policy must allow the other account, and that account's principals must also have IAM permissions to use the key. The AWS managed key aws/s3 cannot be shared across accounts, so use a customer managed key for any cross-account design.
Encryption in transit
TLS encrypts the connection between the client and S3. The AWS CLI and SDKs use HTTPS by default, so ordinary tooling is already protected. The risk comes from other clients, older scripts, or code that sets an explicit http:// endpoint.
To make the requirement enforceable, deny every request that does not use TLS. The policy below uses the aws:SecureTransport condition key, which is false for plain HTTP requests.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyInsecureTransport",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::my-example-bucket-123456789012",
"arn:aws:s3:::my-example-bucket-123456789012/*"
],
"Condition": {
"Bool": { "aws:SecureTransport": "false" }
}
}
]
}Apply it with aws s3api put-bucket-policy --bucket my-example-bucket-123456789012 --policy file://policy.json. An explicit Deny overrides any Allow, so this works regardless of other permissions.
To also set a minimum TLS version, add a second statement that denies requests where the s3:TlsVersion condition key is below 1.2.
Requiring a specific encryption mode
Default encryption fills in a mode when the client does not choose one. It does not stop a client from choosing a different allowed mode. If your policy requires SSE-KMS, add a deny statement that rejects uploads that use anything else.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyNonKmsUploads",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::my-example-bucket-123456789012/*",
"Condition": {
"StringNotEquals": {
"s3:x-amz-server-side-encryption": "aws:kms"
},
"Null": {
"s3:x-amz-server-side-encryption": "false"
}
}
}
]
}This policy rejects an upload only when the client explicitly names a mode other than aws:kms. The Null condition set to false means the header is present. Uploads that omit the header are not rejected, because the bucket default (SSE-KMS) then applies. This is the safe pattern: it lets simple clients rely on the default while blocking explicit attempts to use another mode.
Common errors and gotchas
AccessDeniedon read with correct S3 permissions. The caller lackskms:Decrypton the key. Fix the key policy or IAM policy.- Throttling or high KMS cost. Many small SSE-KMS reads or writes create a high KMS request rate. Enable a bucket key, or use SSE-S3 if you do not need key-level control.
- Presigned URL failures. If the object uses SSE-KMS, the signer needs KMS permissions, and the URL must be signed with Signature Version 4. Presigned URLs for SSE-KMS objects fail on older signing methods.
- Cross-account reads fail. The object was encrypted with
aws/s3, which other accounts cannot use. Re-encrypt with a customer managed key. - Assuming a default change fixes old data. Existing objects keep their original encryption until you rewrite them.
- Deleting or disabling the KMS key. Objects encrypted with that key become unreadable. KMS enforces a waiting period of 7 to 30 days before deleting a key, which gives you time to cancel.
Choosing a mode
| Need | Choice |
|---|---|
| Encryption with no operational work | SSE-S3 |
| Audit of key use, key-level access control, or cross-account sharing | SSE-KMS with a customer managed key |
| High request volume with SSE-KMS | SSE-KMS with a bucket key |
| Compliance requiring two encryption layers | DSSE-KMS |
| Keys must never be held by AWS | Client-side encryption |
Exercise
A teammate in the same account can list objects in a bucket, but GetObject returns AccessDenied. The IAM policy allows s3:GetObject on the bucket, and the objects are encrypted with SSE-KMS using a customer managed key. What do you check first, and what permission is likely missing?
Show answer
Check the KMS side. The teammate's principal probably lacks kms:Decrypt on the customer managed key, either in the IAM policy or in the key policy. S3 permissions alone are not enough to read an SSE-KMS object.
Exercise
You write a bucket policy with a single statement that denies s3:* when aws:SecureTransport is false. A script uses http:// to call the S3 endpoint. What happens, and why does an existing Allow for that script not help?
Show answer
The request is denied. aws:SecureTransport is false for plain HTTP, so the Deny statement matches. In IAM policy evaluation an explicit Deny always overrides any Allow.
Exercise
You change the bucket default encryption from SSE-S3 to SSE-KMS. Are the 10,000 objects uploaded last month now protected by the KMS key? How would you change them?
Show answer
No. Default encryption only applies to new uploads. To move existing objects to SSE-KMS, copy each object onto itself with the new encryption settings, or run an S3 Batch Operations copy job for a large set.