Specifying server-side encryption with AWS KMS (SSE-KMS) for new object uploads in directory buckets (original) (raw)
Note
Only 1 customer managed key is supported per directory bucket for the lifetime of the bucket. The AWS managed key (aws/s3
) isn't supported. After you specify SSE-KMS as your bucket's default encryption configuration with a customer managed key, you can't change the customer managed key for the bucket's SSE-KMS configuration.
For Zonal endpoint (object-level) API operations except CopyObject and UploadPartCopy, you authenticate and authorize requests through CreateSession for low latency. We recommend that the bucket's default encryption uses the desired encryption configurations and you don't override the bucket default encryption in your CreateSession
requests or PUT
object requests. Then, new objects are automatically encrypted with the desired encryption settings. To encrypt new objects in a directory bucket with SSE-KMS, you must specify SSE-KMS as the directory bucket's default encryption configuration with a KMS key (specifically, a customer managed key). Then, when a session is created for Zonal endpoint API operations, new objects are automatically encrypted and decrypted with SSE-KMS and S3 Bucket Keys during the session. For more information about the encryption overriding behaviors in directory buckets, see Specifying server-side encryption with AWS KMS for new object uploads.
In the Zonal endpoint API calls (except CopyObject and UploadPartCopy) using the REST API, you can't override the values of the encryption settings (x-amz-server-side-encryption
, x-amz-server-side-encryption-aws-kms-key-id
, x-amz-server-side-encryption-context
, and x-amz-server-side-encryption-bucket-key-enabled
) from the CreateSession
request. You don't need to explicitly specify these encryption settings values in Zonal endpoint API calls, and Amazon S3 will use the encryption settings values from the CreateSession
request to protect new objects in the directory bucket.
Note
When you use the AWS CLI or the AWS SDKs, for CreateSession
, the session token refreshes automatically to avoid service interruptions when a session expires. The AWS CLI or the AWS SDKs use the bucket's default encryption configuration for the CreateSession
request. It's not supported to override the encryption settings values in the CreateSession
request. Also, in the Zonal endpoint API calls (except CopyObject and UploadPartCopy), it's not supported to override the values of the encryption settings from the CreateSession
request.
For CopyObject, to encrypt new object copies in a directory bucket with SSE-KMS, you must specify SSE-KMS as the directory bucket's default encryption configuration with a KMS key (specifically, a customer managed key). Then, when you specify server-side encryption settings for new object copies with SSE-KMS, you must make sure the encryption key is the same customer managed key that you specified for the directory bucket's default encryption configuration. For UploadPartCopy, to encrypt new object part copies in a directory bucket with SSE-KMS, you must specify SSE-KMS as the directory bucket's default encryption configuration with a KMS key (specifically, a customer managed key). You can't specify server-side encryption settings for new object part copies with SSE-KMS in the UploadPartCopy request headers. Also, the encryption settings that you provide in the CreateMultipartUpload request must match the default encryption configuration of the destination bucket.
Topics
- Amazon S3 REST API operations that support SSE-KMS
- Encryption context (x-amz-server-side-encryption-context)
- AWS KMS key ID (x-amz-server-side-encryption-aws-kms-key-id)
- S3 Bucket Keys (x-amz-server-side-encryption-aws-bucket-key-enabled)
The following object-level REST API operations in directory buckets accept thex-amz-server-side-encryption
,x-amz-server-side-encryption-aws-kms-key-id
, andx-amz-server-side-encryption-context
request headers.
- CreateSession – When you use Zonal endpoint (object-level) API operations (except CopyObject and UploadPartCopy), you can specify these request headers.
- PutObject – When you upload data by using the
PUT
API operation, you can specify these request headers. - CopyObject – When you copy an object, you have both a source object and a target object. When you pass SSE-KMS headers with the
CopyObject
operation, they're applied only to the target object. - CreateMultipartUpload – When you upload large objects by using the multipart upload API operation, you can specify these headers. You specify these headers in the
CreateMultipartUpload
request.
The response headers of the following REST API operations return thex-amz-server-side-encryption
header when an object is stored by using server-side encryption.
- CreateSession
- PutObject
- CopyObject
- POST Object
- CreateMultipartUpload
- UploadPart
- UploadPartCopy
- CompleteMultipartUpload
- GetObject
- HeadObject
Important
- All
GET
andPUT
requests for an object protected by AWS KMS fail if you don't make these requests by using Transport Layer Security (TLS), or Signature Version 4. - If your object uses SSE-KMS, don't send encryption request headers for
GET
requests andHEAD
requests, or you’ll get an**HTTP 400 BadRequest
** error.
Encryption context (x-amz-server-side-encryption-context
)
If you specify x-amz-server-side-encryption:aws:kms
, the Amazon S3 API supports you to optionally provide an explicit encryption context with the x-amz-server-side-encryption-context
header. For directory buckets, an encryption context is a set of key-value pairs that contain contextual information about the data. The value must match the default encryption context — the bucket Amazon Resource Name (ARN). An additional encryption context value is not supported.
For information about the encryption context in directory buckets, see Encryption context. For general information about the encryption context, see AWS Key Management Service Concepts - Encryption context in the AWS Key Management Service Developer Guide.
AWS KMS key ID (x-amz-server-side-encryption-aws-kms-key-id
)
You can use the x-amz-server-side-encryption-aws-kms-key-id
header to specify the ID of the customer managed key that's used to protect the data.
Your SSE-KMS configuration can only support 1 customer managed key per directory bucket for the lifetime of the bucket. The AWS managed key (aws/s3
) isn't supported. Also, after you specify a customer managed key for SSE-KMS, you can't override the customer managed key for the bucket's SSE-KMS configuration.
You can identify the customer managed key you specified for the bucket's SSE-KMS configuration, in the following way:
- You make a
HeadObject
API operation request to find the value ofx-amz-server-side-encryption-aws-kms-key-id
in your response.
To use a new customer managed key for your data, we recommend copying your existing objects to a new directory bucket with a new customer managed key.
For information about the encryption context in directory buckets, see AWS KMS keys.
S3 Bucket Keys (x-amz-server-side-encryption-aws-bucket-key-enabled
)
S3 Bucket Keys are always enabled for GET
and PUT
operations in a directory bucket and can’t be disabled. S3 Bucket Keys aren't supported, when you copy SSE-KMS encrypted objects from general purpose buckets to directory buckets, from directory buckets to general purpose buckets, or between directory buckets, through CopyObject, UploadPartCopy, the Copy operation in Batch Operations, or the import jobs. In this case, Amazon S3 makes a call to AWS KMS every time a copy request is made for a KMS-encrypted object. For information about the S3 Bucket Keys in directory buckets, see Encryption context.
Note
When you use the AWS CLI, for CreateSession
, the session token refreshes automatically to avoid service interruptions when a session expires. It's not supported to override the encryption settings values for the CreateSession
request. Also, in the Zonal endpoint API calls (except CopyObject and UploadPartCopy), it's not supported to override the values of the encryption settings from the CreateSession
request.
To encrypt new objects in a directory bucket with SSE-KMS, you must specify SSE-KMS as the directory bucket's default encryption configuration with a KMS key (specifically, a customer managed key). Then, when a session is created for Zonal endpoint API operations, new objects are automatically encrypted and decrypted with SSE-KMS and S3 Bucket Keys during the session.
To use the following example AWS CLI commands, replace the `user input placeholders`
with your own information.
When you upload a new object or copy an existing object, you can specify the use of server-side encryption with AWS KMS keys to encrypt your data. To do this, use the put-bucket-encryption
command to set the directory bucket's default encryption configuration as SSE-KMS (aws:kms
). Specifically, add the--server-side-encryption aws:kms
header to the request. Use the--ssekms-key-id `example-key-id`
to add your customer managed AWS KMS key that you created. If you specify --server-side-encryption aws:kms
, you must provide an AWS KMS key ID of your customer managed key. Directory buckets don't use an AWS managed key. For an example command, see Using the AWS CLI.
Then, when you upload a new object with the following command, Amazon S3 uses the bucket settings for default encryption to encrypt the object by default.
aws s3api put-object --bucket bucket-base-name--zone-id--x-s3 --key example-object-key --body filepath
You don't need to add -\-bucket-key-enabled
explicitly in your Zonal endpoint API operations commands. S3 Bucket Keys are always enabled for GET
and PUT
operations in a directory bucket and can’t be disabled. S3 Bucket Keys aren't supported, when you copy SSE-KMS encrypted objects from general purpose buckets to directory buckets, from directory buckets to general purpose buckets, or between directory buckets, through CopyObject, UploadPartCopy, the Copy operation in Batch Operations, or the import jobs. In this case, Amazon S3 makes a call to AWS KMS every time a copy request is made for a KMS-encrypted object.
You can copy an object from a source bucket (for example, a general purpose bucket) to a new bucket (for example, a directory bucket) and use SSE-KMS encryption for the destination objects. To do this, use the put-bucket-encryption
command to set the default encryption configuration of the destination bucket (for example, a directory bucket) as SSE-KMS (aws:kms
). For an example command, see Using the AWS CLI. Then, when you copy an object with the following command, Amazon S3 uses the bucket settings for default encryption to encrypt the object by default.
aws s3api copy-object --copy-source amzn-s3-demo-bucket/example-object-key --bucket bucket-base-name--zone-id--x-s3 --key example-object-key