- Encryption at rest (
server_side_encryption_configuration) — sets the default encryption applied to objects when no encryption header is supplied by the caller. - Encryption enforcement policies — IAM bucket policies that deny PutObject requests that do not meet your encryption requirements.
Enforcement variables
| Variable | Default | Description |
|---|---|---|
attach_deny_incorrect_encryption_headers | false | Denies PutObject when the s3:x-amz-server-side-encryption header does not match the algorithm configured in server_side_encryption_configuration. |
attach_deny_incorrect_kms_key_sse | false | Denies PutObject when the KMS key specified in the request does not match allowed_kms_key_arn. |
allowed_kms_key_arn | null | The ARN of the KMS key that must be used in PutObject requests. Required when attach_deny_incorrect_kms_key_sse = true. |
attach_deny_unencrypted_object_uploads | false | Denies PutObject when no s3:x-amz-server-side-encryption header is present in the request. |
attach_deny_ssec_encrypted_object_uploads | false | Denies PutObject when a customer-provided encryption key (SSEC) header is detected. |
Policy conditions from source
Each enforcement policy is implemented as an IAMDeny statement targeting s3:PutObject. The following shows the exact conditions used in main.tf.
Deny incorrect encryption header
Checks thats3:x-amz-server-side-encryption matches the configured algorithm. When sse_algorithm = "aws:kms", only aws:kms is allowed; otherwise only AES256 is allowed.
Deny incorrect KMS key
Checks that the KMS key ID in the request matchesallowed_kms_key_arn:
Deny unencrypted object uploads
Checks that thes3:x-amz-server-side-encryption header is not null (i.e., it must be present):
Deny SSEC-encrypted object uploads
Checks that thes3:x-amz-server-side-encryption-customer-algorithm header is null (i.e., SSEC must not be used). Note the condition value is false — the header must be absent:
The
Null condition with values = [false] means “the key is NOT null” — i.e., the header IS present. This denies any PutObject where the customer-provided encryption header is set, effectively banning SSEC.Complete example
The following example configures a bucket with KMS encryption at rest and all relevant enforcement policies enabled:Choosing which policies to apply
Deny unencrypted uploads
Use
attach_deny_unencrypted_object_uploads = true as a baseline to ensure every object is encrypted, regardless of algorithm.Enforce a specific algorithm
Combine with
attach_deny_incorrect_encryption_headers = true and configure server_side_encryption_configuration so the policy knows which algorithm to require.Enforce a specific KMS key
Add
attach_deny_incorrect_kms_key_sse = true and set allowed_kms_key_arn when you need to ensure objects are encrypted with a specific customer-managed key.Prohibit SSEC
Use
attach_deny_ssec_encrypted_object_uploads = true to prevent callers from supplying their own encryption keys, keeping key management centralised in AWS KMS.
