Sub topic 8
Encrypting data at rest and in transit
This chapter assumes you can create a bucket, read a basic IAM or bucket policy, and run AWS CLI commands. S3 protects data in two places: stored on disk (at rest) and moving over the network (in transit).
Encryption at rest
Since January 2023, S3 encrypts every new object automatically. The default is SSE-S3, which means server-side encryption with keys that S3 manages. You cannot turn this off. What you can choose is which key type protects the objects.
| Option | Who manages the key | Typical reason to choose it |
|---|---|---|
| SSE-S3 | S3 | Default. No setup and no extra cost. |
| SSE-KMS | AWS KMS key that you control | Key policies, audit trail in CloudTrail, ability to disable a key. |
| DSSE-KMS | AWS KMS key, two layers of encryption | Compliance rules that require dual-layer encryption. |
| SSE-C | You supply the key on every request | You must hold the key outside AWS. |
Client-side encryption is also possible. You encrypt the data before upload, so S3 only ever stores ciphertext.
Setting a default for a bucket
A bucket's default encryption applies to any upload that does not request an encryption type. This command makes SSE-KMS the default. Replace the key ARN with one of your own.
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/EXAMPLE-KEY-ID"
},
"BucketKeyEnabled": true
}
]
}'BucketKeyEnabled lets S3 reuse a bucket-level key. This reduces the number of calls to KMS, which lowers cost on busy buckets.
Checking an object
Use head-object to see how an object is encrypted.
aws s3api head-object \
--bucket my-example-bucket-123456789012 \
--key reports/2026/report.csvThe response includes ServerSideEncryption and, for SSE-KMS, SSEKMSKeyId.
Encryption in transit
S3 endpoints accept both HTTP and HTTPS. The AWS CLI and SDKs use HTTPS by default, but nothing stops another client from using plain HTTP. To block it, add a bucket policy that denies requests where aws:SecureTransport is false.
{
"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. The policy lists both the bucket ARN and the /* object ARN so it covers bucket-level and object-level actions.
Common errors
- AccessDenied on SSE-KMS objects. The caller lacks
kms:Decryptorkms:GenerateDataKeyon the key. - Cross-account reads fail. The key policy must also allow the other account.
- Old objects keep their old key. Changing the default affects only new uploads. To re-encrypt existing objects, copy them over themselves or use S3 Batch Operations.
- Deny policy breaks a tool. Some old clients use HTTP. The deny rule rejects them, so update the client.
Exercise
You change a bucket's default encryption from SSE-S3 to SSE-KMS. What happens to the objects already in the bucket, and which condition key in a bucket policy blocks plain HTTP requests?
Show answer
Existing objects stay encrypted with SSE-S3, because the default applies only to new uploads. To re-encrypt them, copy them in place or use S3 Batch Operations. The condition key is aws:SecureTransport, with a Deny statement when its value is false.