aws-sdk-s3 1.79.1 → 1.212.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1548 -0
- data/LICENSE.txt +202 -0
- data/VERSION +1 -0
- data/lib/aws-sdk-s3/access_grants_credentials.rb +57 -0
- data/lib/aws-sdk-s3/access_grants_credentials_provider.rb +250 -0
- data/lib/aws-sdk-s3/bucket.rb +900 -98
- data/lib/aws-sdk-s3/bucket_acl.rb +44 -10
- data/lib/aws-sdk-s3/bucket_cors.rb +51 -11
- data/lib/aws-sdk-s3/bucket_lifecycle.rb +53 -8
- data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +107 -9
- data/lib/aws-sdk-s3/bucket_logging.rb +43 -6
- data/lib/aws-sdk-s3/bucket_notification.rb +32 -9
- data/lib/aws-sdk-s3/bucket_policy.rb +90 -6
- data/lib/aws-sdk-s3/bucket_region_cache.rb +9 -5
- data/lib/aws-sdk-s3/bucket_request_payment.rb +38 -8
- data/lib/aws-sdk-s3/bucket_tagging.rb +46 -7
- data/lib/aws-sdk-s3/bucket_versioning.rb +127 -9
- data/lib/aws-sdk-s3/bucket_website.rb +46 -7
- data/lib/aws-sdk-s3/client.rb +13729 -3146
- data/lib/aws-sdk-s3/client_api.rb +1604 -277
- data/lib/aws-sdk-s3/customizations/bucket.rb +31 -47
- data/lib/aws-sdk-s3/customizations/errors.rb +40 -0
- data/lib/aws-sdk-s3/customizations/object.rb +253 -82
- data/lib/aws-sdk-s3/customizations/object_summary.rb +5 -0
- data/lib/aws-sdk-s3/customizations/object_version.rb +13 -0
- data/lib/aws-sdk-s3/customizations/types/permanent_redirect.rb +26 -0
- data/lib/aws-sdk-s3/customizations.rb +28 -29
- data/lib/aws-sdk-s3/default_executor.rb +103 -0
- data/lib/aws-sdk-s3/encryption/client.rb +9 -5
- data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +0 -4
- data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +2 -0
- data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +2 -0
- data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +15 -9
- data/lib/aws-sdk-s3/encryptionV2/client.rb +105 -26
- data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +7 -165
- data/lib/aws-sdk-s3/encryptionV2/decryption.rb +205 -0
- data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +20 -3
- data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +2 -4
- data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +2 -0
- data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +18 -6
- data/lib/aws-sdk-s3/encryptionV2/utils.rb +5 -0
- data/lib/aws-sdk-s3/encryptionV3/client.rb +885 -0
- data/lib/aws-sdk-s3/encryptionV3/decrypt_handler.rb +98 -0
- data/lib/aws-sdk-s3/encryptionV3/decryption.rb +244 -0
- data/lib/aws-sdk-s3/encryptionV3/default_cipher_provider.rb +159 -0
- data/lib/aws-sdk-s3/encryptionV3/default_key_provider.rb +35 -0
- data/lib/aws-sdk-s3/encryptionV3/encrypt_handler.rb +98 -0
- data/lib/aws-sdk-s3/encryptionV3/errors.rb +47 -0
- data/lib/aws-sdk-s3/encryptionV3/io_auth_decrypter.rb +60 -0
- data/lib/aws-sdk-s3/encryptionV3/io_decrypter.rb +35 -0
- data/lib/aws-sdk-s3/encryptionV3/io_encrypter.rb +84 -0
- data/lib/aws-sdk-s3/encryptionV3/key_provider.rb +28 -0
- data/lib/aws-sdk-s3/encryptionV3/kms_cipher_provider.rb +159 -0
- data/lib/aws-sdk-s3/encryptionV3/materials.rb +58 -0
- data/lib/aws-sdk-s3/encryptionV3/utils.rb +321 -0
- data/lib/aws-sdk-s3/encryption_v2.rb +1 -0
- data/lib/aws-sdk-s3/encryption_v3.rb +24 -0
- data/lib/aws-sdk-s3/endpoint_parameters.rb +181 -0
- data/lib/aws-sdk-s3/endpoint_provider.rb +889 -0
- data/lib/aws-sdk-s3/endpoints.rb +1544 -0
- data/lib/aws-sdk-s3/errors.rb +80 -1
- data/lib/aws-sdk-s3/event_streams.rb +1 -1
- data/lib/aws-sdk-s3/express_credentials.rb +55 -0
- data/lib/aws-sdk-s3/express_credentials_provider.rb +59 -0
- data/lib/aws-sdk-s3/file_downloader.rb +258 -82
- data/lib/aws-sdk-s3/file_uploader.rb +25 -14
- data/lib/aws-sdk-s3/legacy_signer.rb +17 -26
- data/lib/aws-sdk-s3/multipart_download_error.rb +8 -0
- data/lib/aws-sdk-s3/multipart_file_uploader.rb +111 -86
- data/lib/aws-sdk-s3/multipart_stream_uploader.rb +110 -92
- data/lib/aws-sdk-s3/multipart_upload.rb +304 -14
- data/lib/aws-sdk-s3/multipart_upload_error.rb +3 -4
- data/lib/aws-sdk-s3/multipart_upload_part.rb +344 -20
- data/lib/aws-sdk-s3/object.rb +2457 -225
- data/lib/aws-sdk-s3/object_acl.rb +76 -15
- data/lib/aws-sdk-s3/object_copier.rb +7 -5
- data/lib/aws-sdk-s3/object_multipart_copier.rb +48 -23
- data/lib/aws-sdk-s3/object_summary.rb +2033 -169
- data/lib/aws-sdk-s3/object_version.rb +470 -53
- data/lib/aws-sdk-s3/plugins/accelerate.rb +1 -39
- data/lib/aws-sdk-s3/plugins/access_grants.rb +178 -0
- data/lib/aws-sdk-s3/plugins/arn.rb +70 -0
- data/lib/aws-sdk-s3/plugins/bucket_dns.rb +3 -41
- data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +1 -6
- data/lib/aws-sdk-s3/plugins/checksum_algorithm.rb +44 -0
- data/lib/aws-sdk-s3/plugins/dualstack.rb +2 -49
- data/lib/aws-sdk-s3/plugins/endpoints.rb +86 -0
- data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +3 -1
- data/lib/aws-sdk-s3/plugins/express_session_auth.rb +88 -0
- data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +1 -1
- data/lib/aws-sdk-s3/plugins/http_200_errors.rb +87 -26
- data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +8 -26
- data/lib/aws-sdk-s3/plugins/location_constraint.rb +3 -1
- data/lib/aws-sdk-s3/plugins/md5s.rb +10 -68
- data/lib/aws-sdk-s3/plugins/s3_signer.rb +48 -88
- data/lib/aws-sdk-s3/plugins/streaming_retry.rb +28 -9
- data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -1
- data/lib/aws-sdk-s3/presigned_post.rb +99 -78
- data/lib/aws-sdk-s3/presigner.rb +50 -42
- data/lib/aws-sdk-s3/resource.rb +144 -15
- data/lib/aws-sdk-s3/transfer_manager.rb +321 -0
- data/lib/aws-sdk-s3/types.rb +12223 -4723
- data/lib/aws-sdk-s3/waiters.rb +1 -1
- data/lib/aws-sdk-s3.rb +37 -28
- data/sig/bucket.rbs +231 -0
- data/sig/bucket_acl.rbs +78 -0
- data/sig/bucket_cors.rbs +69 -0
- data/sig/bucket_lifecycle.rbs +88 -0
- data/sig/bucket_lifecycle_configuration.rbs +115 -0
- data/sig/bucket_logging.rbs +76 -0
- data/sig/bucket_notification.rbs +114 -0
- data/sig/bucket_policy.rbs +59 -0
- data/sig/bucket_request_payment.rbs +54 -0
- data/sig/bucket_tagging.rbs +65 -0
- data/sig/bucket_versioning.rbs +77 -0
- data/sig/bucket_website.rbs +93 -0
- data/sig/client.rbs +2612 -0
- data/sig/customizations/bucket.rbs +19 -0
- data/sig/customizations/object.rbs +38 -0
- data/sig/customizations/object_summary.rbs +35 -0
- data/sig/errors.rbs +44 -0
- data/sig/multipart_upload.rbs +120 -0
- data/sig/multipart_upload_part.rbs +109 -0
- data/sig/object.rbs +464 -0
- data/sig/object_acl.rbs +86 -0
- data/sig/object_summary.rbs +347 -0
- data/sig/object_version.rbs +143 -0
- data/sig/resource.rbs +141 -0
- data/sig/types.rbs +2899 -0
- data/sig/waiters.rbs +95 -0
- metadata +74 -16
- data/lib/aws-sdk-s3/plugins/bucket_arn.rb +0 -212
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module S3
|
|
5
|
+
module Types
|
|
6
|
+
# This error is not modeled.
|
|
7
|
+
#
|
|
8
|
+
# The bucket you are attempting to access must be addressed using the
|
|
9
|
+
# specified endpoint. Please send all future requests to this endpoint.
|
|
10
|
+
#
|
|
11
|
+
# @!attribute [rw] endpoint
|
|
12
|
+
# @return [String]
|
|
13
|
+
#
|
|
14
|
+
# @!attribute [rw] bucket
|
|
15
|
+
# @return [String]
|
|
16
|
+
#
|
|
17
|
+
# @!attribute [rw] message
|
|
18
|
+
# @return [String]
|
|
19
|
+
#
|
|
20
|
+
class PermanentRedirect < Struct.new(:endpoint, :bucket, :region, :message)
|
|
21
|
+
SENSITIVE = []
|
|
22
|
+
include Aws::Structure
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
module Aws
|
|
4
|
+
module S3
|
|
5
|
+
# utility classes
|
|
6
|
+
autoload :BucketRegionCache, 'aws-sdk-s3/bucket_region_cache'
|
|
7
|
+
autoload :Encryption, 'aws-sdk-s3/encryption'
|
|
8
|
+
autoload :EncryptionV2, 'aws-sdk-s3/encryption_v2'
|
|
9
|
+
autoload :EncryptionV3, 'aws-sdk-s3/encryption_v3'
|
|
10
|
+
autoload :FilePart, 'aws-sdk-s3/file_part'
|
|
11
|
+
autoload :DefaultExecutor, 'aws-sdk-s3/default_executor'
|
|
12
|
+
autoload :FileUploader, 'aws-sdk-s3/file_uploader'
|
|
13
|
+
autoload :FileDownloader, 'aws-sdk-s3/file_downloader'
|
|
14
|
+
autoload :LegacySigner, 'aws-sdk-s3/legacy_signer'
|
|
15
|
+
autoload :MultipartDownloadError, 'aws-sdk-s3/multipart_download_error'
|
|
16
|
+
autoload :MultipartFileUploader, 'aws-sdk-s3/multipart_file_uploader'
|
|
17
|
+
autoload :MultipartStreamUploader, 'aws-sdk-s3/multipart_stream_uploader'
|
|
18
|
+
autoload :MultipartUploadError, 'aws-sdk-s3/multipart_upload_error'
|
|
19
|
+
autoload :ObjectCopier, 'aws-sdk-s3/object_copier'
|
|
20
|
+
autoload :ObjectMultipartCopier, 'aws-sdk-s3/object_multipart_copier'
|
|
21
|
+
autoload :PresignedPost, 'aws-sdk-s3/presigned_post'
|
|
22
|
+
autoload :Presigner, 'aws-sdk-s3/presigner'
|
|
23
|
+
autoload :TransferManager, 'aws-sdk-s3/transfer_manager'
|
|
18
24
|
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
require 'aws-sdk-s3/customizations/object_summary'
|
|
23
|
-
require 'aws-sdk-s3/customizations/multipart_upload'
|
|
24
|
-
require 'aws-sdk-s3/customizations/types/list_object_versions_output'
|
|
25
|
+
# s3 express session auth
|
|
26
|
+
autoload :ExpressCredentials, 'aws-sdk-s3/express_credentials'
|
|
27
|
+
autoload :ExpressCredentialsProvider, 'aws-sdk-s3/express_credentials_provider'
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
].each do |klass|
|
|
31
|
-
klass.send(:alias_method, :delete, :batch_delete!)
|
|
32
|
-
klass.send(:extend, Aws::Deprecations)
|
|
33
|
-
klass.send(:deprecated, :delete, use: :batch_delete!)
|
|
29
|
+
# s3 access grants auth
|
|
30
|
+
autoload :AccessGrantsCredentials, 'aws-sdk-s3/access_grants_credentials'
|
|
31
|
+
autoload :AccessGrantsCredentialsProvider, 'aws-sdk-s3/access_grants_credentials_provider'
|
|
32
|
+
end
|
|
34
33
|
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module S3
|
|
5
|
+
# @api private
|
|
6
|
+
class DefaultExecutor
|
|
7
|
+
DEFAULT_MAX_THREADS = 10
|
|
8
|
+
RUNNING = :running
|
|
9
|
+
SHUTTING_DOWN = :shutting_down
|
|
10
|
+
SHUTDOWN = :shutdown
|
|
11
|
+
|
|
12
|
+
def initialize(options = {})
|
|
13
|
+
@max_threads = options[:max_threads] || DEFAULT_MAX_THREADS
|
|
14
|
+
@state = RUNNING
|
|
15
|
+
@queue = Queue.new
|
|
16
|
+
@pool = []
|
|
17
|
+
@mutex = Mutex.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Submits a task for execution.
|
|
21
|
+
# @param [Object] args Variable number of arguments to pass to the block
|
|
22
|
+
# @param [Proc] block The block to be executed
|
|
23
|
+
# @return [Boolean] Returns true if the task was submitted successfully
|
|
24
|
+
def post(*args, &block)
|
|
25
|
+
@mutex.synchronize do
|
|
26
|
+
raise 'Executor has been shutdown and is no longer accepting tasks' unless @state == RUNNING
|
|
27
|
+
|
|
28
|
+
@queue << [args, block]
|
|
29
|
+
ensure_worker_available
|
|
30
|
+
end
|
|
31
|
+
true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Immediately terminates all worker threads and clears pending tasks.
|
|
35
|
+
# This is a forceful shutdown that doesn't wait for running tasks to complete.
|
|
36
|
+
#
|
|
37
|
+
# @return [Boolean] true when termination is complete
|
|
38
|
+
def kill
|
|
39
|
+
@mutex.synchronize do
|
|
40
|
+
@state = SHUTDOWN
|
|
41
|
+
@pool.each(&:kill)
|
|
42
|
+
@pool.clear
|
|
43
|
+
@queue.clear
|
|
44
|
+
end
|
|
45
|
+
true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Gracefully shuts down the executor, optionally with a timeout.
|
|
49
|
+
# Stops accepting new tasks and waits for running tasks to complete.
|
|
50
|
+
#
|
|
51
|
+
# @param timeout [Numeric, nil] Maximum time in seconds to wait for shutdown.
|
|
52
|
+
# If nil, waits indefinitely. If timeout expires, remaining threads are killed.
|
|
53
|
+
# @return [Boolean] true when shutdown is complete
|
|
54
|
+
def shutdown(timeout = nil)
|
|
55
|
+
@mutex.synchronize do
|
|
56
|
+
return true if @state == SHUTDOWN
|
|
57
|
+
|
|
58
|
+
@state = SHUTTING_DOWN
|
|
59
|
+
@pool.size.times { @queue << :shutdown }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
if timeout
|
|
63
|
+
deadline = Time.now + timeout
|
|
64
|
+
@pool.each do |thread|
|
|
65
|
+
remaining = deadline - Time.now
|
|
66
|
+
break if remaining <= 0
|
|
67
|
+
|
|
68
|
+
thread.join([remaining, 0].max)
|
|
69
|
+
end
|
|
70
|
+
@pool.select(&:alive?).each(&:kill)
|
|
71
|
+
else
|
|
72
|
+
@pool.each(&:join)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
@mutex.synchronize do
|
|
76
|
+
@pool.clear
|
|
77
|
+
@state = SHUTDOWN
|
|
78
|
+
end
|
|
79
|
+
true
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
def ensure_worker_available
|
|
85
|
+
return unless @state == RUNNING
|
|
86
|
+
|
|
87
|
+
@pool.select!(&:alive?)
|
|
88
|
+
@pool << spawn_worker if @pool.size < @max_threads
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def spawn_worker
|
|
92
|
+
Thread.new do
|
|
93
|
+
while (job = @queue.shift)
|
|
94
|
+
break if job == :shutdown
|
|
95
|
+
|
|
96
|
+
args, block = job
|
|
97
|
+
block.call(*args)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -6,9 +6,9 @@ module Aws
|
|
|
6
6
|
module S3
|
|
7
7
|
|
|
8
8
|
# [MAINTENANCE MODE] There is a new version of the Encryption Client.
|
|
9
|
-
# AWS strongly recommends upgrading to the {Aws::S3::
|
|
9
|
+
# AWS strongly recommends upgrading to the {Aws::S3::EncryptionV3::Client},
|
|
10
10
|
# which provides updated data security best practices.
|
|
11
|
-
# See documentation for {Aws::S3::
|
|
11
|
+
# See documentation for {Aws::S3::EncryptionV3::Client}.
|
|
12
12
|
# Provides an encryption client that encrypts and decrypts data client-side,
|
|
13
13
|
# storing the encrypted data in Amazon S3.
|
|
14
14
|
#
|
|
@@ -120,7 +120,7 @@ module Aws
|
|
|
120
120
|
# attr_reader :encryption_materials
|
|
121
121
|
#
|
|
122
122
|
# def key_for(matdesc)
|
|
123
|
-
# key_name = JSON.
|
|
123
|
+
# key_name = JSON.parse(matdesc)['key']
|
|
124
124
|
# if key = @keys[key_name]
|
|
125
125
|
# key
|
|
126
126
|
# else
|
|
@@ -270,7 +270,9 @@ module Aws
|
|
|
270
270
|
envelope_location: @envelope_location,
|
|
271
271
|
instruction_file_suffix: @instruction_file_suffix,
|
|
272
272
|
}
|
|
273
|
-
|
|
273
|
+
Aws::Plugins::UserAgent.metric('S3_CRYPTO_V1N') do
|
|
274
|
+
req.send_request
|
|
275
|
+
end
|
|
274
276
|
end
|
|
275
277
|
|
|
276
278
|
# Gets an object from Amazon S3, decrypting data locally.
|
|
@@ -298,7 +300,9 @@ module Aws
|
|
|
298
300
|
envelope_location: envelope_location,
|
|
299
301
|
instruction_file_suffix: instruction_file_suffix,
|
|
300
302
|
}
|
|
301
|
-
|
|
303
|
+
Aws::Plugins::UserAgent.metric('S3_CRYPTO_V1N') do
|
|
304
|
+
req.send_request(target: block)
|
|
305
|
+
end
|
|
302
306
|
end
|
|
303
307
|
|
|
304
308
|
private
|
|
@@ -165,10 +165,6 @@ module Aws
|
|
|
165
165
|
# to initialize the cipher, and the decrypter truncates the
|
|
166
166
|
# auth tag from the body when writing the final bytes.
|
|
167
167
|
def authenticated_decrypter(context, cipher, envelope)
|
|
168
|
-
if RUBY_VERSION.match(/1.9/)
|
|
169
|
-
raise "authenticated decryption not supported by OpenSSL in Ruby version ~> 1.9"
|
|
170
|
-
raise Aws::Errors::NonSupportedRubyVersionError, msg
|
|
171
|
-
end
|
|
172
168
|
http_resp = context.http_response
|
|
173
169
|
content_length = http_resp.headers['content-length'].to_i
|
|
174
170
|
auth_tag_length = auth_tag_length(envelope)
|
|
@@ -16,6 +16,8 @@ module Aws
|
|
|
16
16
|
# envelope and encryption cipher.
|
|
17
17
|
def encryption_cipher
|
|
18
18
|
cipher = Utils.aes_encryption_cipher(:CBC)
|
|
19
|
+
##= ../specification/s3-encryption/data-format/content-metadata.md#algorithm-suite-and-message-format-version-compatibility
|
|
20
|
+
##% Objects encrypted with ALG_AES_256_CBC_IV16_NO_KDF MAY use either the V1 or V2 message format version.
|
|
19
21
|
envelope = {
|
|
20
22
|
'x-amz-key' => encode64(encrypt(envelope_key(cipher))),
|
|
21
23
|
'x-amz-iv' => encode64(envelope_iv(cipher)),
|
|
@@ -38,6 +38,8 @@ module Aws
|
|
|
38
38
|
io = StringIO.new(io) if String === io
|
|
39
39
|
context.params[:body] = IOEncrypter.new(cipher, io)
|
|
40
40
|
context.params[:metadata] ||= {}
|
|
41
|
+
##= ../specification/s3-encryption/data-format/content-metadata.md#content-metadata-mapkeys
|
|
42
|
+
##% - The mapkey "x-amz-unencrypted-content-length" SHOULD be present for V1 format objects.
|
|
41
43
|
context.params[:metadata]['x-amz-unencrypted-content-length'] = io.size
|
|
42
44
|
if context.params.delete(:content_md5)
|
|
43
45
|
warn('Setting content_md5 on client side encrypted objects is deprecated')
|
|
@@ -17,13 +17,17 @@ module Aws
|
|
|
17
17
|
# envelope and encryption cipher.
|
|
18
18
|
def encryption_cipher
|
|
19
19
|
encryption_context = { "kms_cmk_id" => @kms_key_id }
|
|
20
|
-
key_data =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
key_data = Aws::Plugins::UserAgent.metric('S3_CRYPTO_V1N') do
|
|
21
|
+
@kms_client.generate_data_key(
|
|
22
|
+
key_id: @kms_key_id,
|
|
23
|
+
encryption_context: encryption_context,
|
|
24
|
+
key_spec: 'AES_256'
|
|
25
|
+
)
|
|
26
|
+
end
|
|
25
27
|
cipher = Utils.aes_encryption_cipher(:CBC)
|
|
26
28
|
cipher.key = key_data.plaintext
|
|
29
|
+
##= ../specification/s3-encryption/data-format/content-metadata.md#algorithm-suite-and-message-format-version-compatibility
|
|
30
|
+
##% Objects encrypted with ALG_AES_256_CBC_IV16_NO_KDF MAY use either the V1 or V2 message format version.
|
|
27
31
|
envelope = {
|
|
28
32
|
'x-amz-key-v2' => encode64(key_data.ciphertext_blob),
|
|
29
33
|
'x-amz-iv' => encode64(cipher.iv = cipher.random_iv),
|
|
@@ -58,10 +62,12 @@ module Aws
|
|
|
58
62
|
"#{envelope['x-amz-wrap-alg']}"
|
|
59
63
|
end
|
|
60
64
|
|
|
61
|
-
key =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
key = Aws::Plugins::UserAgent.metric('S3_CRYPTO_V1N') do
|
|
66
|
+
@kms_client.decrypt(
|
|
67
|
+
ciphertext_blob: decode64(envelope['x-amz-key-v2']),
|
|
68
|
+
encryption_context: encryption_context
|
|
69
|
+
).plaintext
|
|
70
|
+
end
|
|
65
71
|
|
|
66
72
|
iv = decode64(envelope['x-amz-iv'])
|
|
67
73
|
block_mode =
|
|
@@ -5,9 +5,17 @@ require 'forwardable'
|
|
|
5
5
|
module Aws
|
|
6
6
|
module S3
|
|
7
7
|
|
|
8
|
-
REQUIRED_PARAMS = [:key_wrap_schema, :content_encryption_schema, :security_profile]
|
|
9
|
-
SUPPORTED_SECURITY_PROFILES = [:v2, :v2_and_legacy]
|
|
8
|
+
REQUIRED_PARAMS = [:key_wrap_schema, :content_encryption_schema, :security_profile].freeze
|
|
9
|
+
SUPPORTED_SECURITY_PROFILES = [:v2, :v2_and_legacy].freeze
|
|
10
|
+
SUPPORTED_COMMITMENT_POLICIES = [:forbid_encrypt_allow_decrypt].freeze
|
|
10
11
|
|
|
12
|
+
# [MAINTENANCE MODE] There is a new version of the Encryption Client.
|
|
13
|
+
# AWS strongly recommends upgrading to the {Aws::S3::EncryptionV3::Client},
|
|
14
|
+
# which provides updated data security best practices.
|
|
15
|
+
# For migration guidance, see: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/s3-encryption-migration-v2-v3.html
|
|
16
|
+
# Provides an encryption client that encrypts and decrypts data client-side,
|
|
17
|
+
# storing the encrypted data in Amazon S3.
|
|
18
|
+
#
|
|
11
19
|
# Provides an encryption client that encrypts and decrypts data client-side,
|
|
12
20
|
# storing the encrypted data in Amazon S3. The `EncryptionV2::Client` (V2 Client)
|
|
13
21
|
# provides improved security over the `Encryption::Client` (V1 Client)
|
|
@@ -157,7 +165,7 @@ module Aws
|
|
|
157
165
|
# attr_reader :encryption_materials
|
|
158
166
|
#
|
|
159
167
|
# def key_for(matdesc)
|
|
160
|
-
# key_name = JSON.
|
|
168
|
+
# key_name = JSON.parse(matdesc)['key']
|
|
161
169
|
# if key = @keys[key_name]
|
|
162
170
|
# key
|
|
163
171
|
# else
|
|
@@ -307,15 +315,29 @@ module Aws
|
|
|
307
315
|
# @option options [KMS::Client] :kms_client A default {KMS::Client}
|
|
308
316
|
# is constructed when using KMS to manage encryption keys.
|
|
309
317
|
#
|
|
318
|
+
# @option options [Symbol] :commitment_policy (nil)
|
|
319
|
+
# Optional parameter for migration from V2 to V3. When set to
|
|
320
|
+
# :forbid_encrypt_allow_decrypt, this explicitly indicates you are
|
|
321
|
+
# maintaining V2 encryption behavior while preparing for migration.
|
|
322
|
+
# This allows the V2 client to decrypt V3-encrypted objects while
|
|
323
|
+
# continuing to encrypt new objects using V2 algorithms.
|
|
324
|
+
# Only :forbid_encrypt_allow_decrypt is supported.
|
|
325
|
+
# For migration guidance, see: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/s3-encryption-migration-v2-v3.html
|
|
326
|
+
#
|
|
310
327
|
def initialize(options = {})
|
|
311
328
|
validate_params(options)
|
|
312
329
|
@client = extract_client(options)
|
|
313
|
-
@cipher_provider =
|
|
330
|
+
@cipher_provider = build_cipher_provider(options)
|
|
331
|
+
@key_provider = @cipher_provider.key_provider if @cipher_provider.is_a?(DefaultCipherProvider)
|
|
314
332
|
@envelope_location = extract_location(options)
|
|
315
333
|
@instruction_file_suffix = extract_suffix(options)
|
|
316
334
|
@kms_allow_decrypt_with_any_cmk =
|
|
317
335
|
options[:kms_key_id] == :kms_allow_decrypt_with_any_cmk
|
|
318
336
|
@security_profile = extract_security_profile(options)
|
|
337
|
+
@commitment_policy = extract_commitment_policy(options)
|
|
338
|
+
# The v3 cipher is only used for decrypt.
|
|
339
|
+
# Therefore any configured v2 `content_encryption_schema` is going to be incorrect.
|
|
340
|
+
@v3_cipher_provider = build_v3_cipher_provider_for_decrypt(options.reject { |k, _| k == :content_encryption_schema })
|
|
319
341
|
end
|
|
320
342
|
|
|
321
343
|
# @return [S3::Client]
|
|
@@ -341,6 +363,11 @@ module Aws
|
|
|
341
363
|
# by this string.
|
|
342
364
|
attr_reader :instruction_file_suffix
|
|
343
365
|
|
|
366
|
+
# @return [Symbol, nil] Optional commitment policy for V2 to V3 migration.
|
|
367
|
+
# When set to :forbid_encrypt_allow_decrypt, explicitly indicates
|
|
368
|
+
# maintaining V2 encryption behavior while preparing for migration.
|
|
369
|
+
attr_reader :commitment_policy
|
|
370
|
+
|
|
344
371
|
# Uploads an object to Amazon S3, encrypting data client-side.
|
|
345
372
|
# See {S3::Client#put_object} for documentation on accepted
|
|
346
373
|
# request parameters.
|
|
@@ -361,7 +388,9 @@ module Aws
|
|
|
361
388
|
instruction_file_suffix: @instruction_file_suffix,
|
|
362
389
|
kms_encryption_context: kms_encryption_context
|
|
363
390
|
}
|
|
364
|
-
|
|
391
|
+
Aws::Plugins::UserAgent.metric('S3_CRYPTO_V2') do
|
|
392
|
+
req.send_request
|
|
393
|
+
end
|
|
365
394
|
end
|
|
366
395
|
|
|
367
396
|
# Gets an object from Amazon S3, decrypting data locally.
|
|
@@ -408,17 +437,64 @@ module Aws
|
|
|
408
437
|
req.handlers.add(DecryptHandler)
|
|
409
438
|
req.context[:encryption] = {
|
|
410
439
|
cipher_provider: @cipher_provider,
|
|
440
|
+
v3_cipher_provider: @v3_cipher_provider,
|
|
411
441
|
envelope_location: envelope_location,
|
|
412
442
|
instruction_file_suffix: instruction_file_suffix,
|
|
413
443
|
kms_encryption_context: kms_encryption_context,
|
|
414
444
|
kms_allow_decrypt_with_any_cmk: kms_any_cmk_mode,
|
|
415
445
|
security_profile: security_profile
|
|
416
446
|
}
|
|
417
|
-
|
|
447
|
+
Aws::Plugins::UserAgent.metric('S3_CRYPTO_V2') do
|
|
448
|
+
req.send_request(target: block)
|
|
449
|
+
end
|
|
418
450
|
end
|
|
419
451
|
|
|
420
452
|
private
|
|
421
453
|
|
|
454
|
+
def build_cipher_provider(options)
|
|
455
|
+
if options[:kms_key_id]
|
|
456
|
+
KmsCipherProvider.new(
|
|
457
|
+
kms_key_id: options[:kms_key_id],
|
|
458
|
+
kms_client: kms_client(options),
|
|
459
|
+
key_wrap_schema: options[:key_wrap_schema],
|
|
460
|
+
content_encryption_schema: options[:content_encryption_schema]
|
|
461
|
+
)
|
|
462
|
+
else
|
|
463
|
+
key_provider = extract_key_provider(options)
|
|
464
|
+
DefaultCipherProvider.new(
|
|
465
|
+
key_provider: key_provider,
|
|
466
|
+
key_wrap_schema: options[:key_wrap_schema],
|
|
467
|
+
content_encryption_schema: options[:content_encryption_schema]
|
|
468
|
+
)
|
|
469
|
+
end
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
def build_v3_cipher_provider_for_decrypt(options)
|
|
473
|
+
if options[:kms_key_id]
|
|
474
|
+
Aws::S3::EncryptionV3::KmsCipherProvider.new(
|
|
475
|
+
kms_key_id: options[:kms_key_id],
|
|
476
|
+
kms_client: kms_client(options),
|
|
477
|
+
key_wrap_schema: options[:key_wrap_schema],
|
|
478
|
+
content_encryption_schema: options[:content_encryption_schema]
|
|
479
|
+
)
|
|
480
|
+
else
|
|
481
|
+
# Create V3 key provider explicitly for proper namespace consistency
|
|
482
|
+
key_provider = if options[:key_provider]
|
|
483
|
+
options[:key_provider]
|
|
484
|
+
elsif options[:encryption_key]
|
|
485
|
+
Aws::S3::EncryptionV3::DefaultKeyProvider.new(options)
|
|
486
|
+
else
|
|
487
|
+
msg = 'you must pass a :kms_key_id, :key_provider, or :encryption_key'
|
|
488
|
+
raise ArgumentError, msg
|
|
489
|
+
end
|
|
490
|
+
Aws::S3::EncryptionV3::DefaultCipherProvider.new(
|
|
491
|
+
key_provider: key_provider,
|
|
492
|
+
key_wrap_schema: options[:key_wrap_schema],
|
|
493
|
+
content_encryption_schema: options[:content_encryption_schema]
|
|
494
|
+
)
|
|
495
|
+
end
|
|
496
|
+
end
|
|
497
|
+
|
|
422
498
|
# Validate required parameters exist and don't conflict.
|
|
423
499
|
# The cek_alg and wrap_alg are passed on to the CipherProviders
|
|
424
500
|
# and further validated there
|
|
@@ -448,36 +524,19 @@ module Aws
|
|
|
448
524
|
options.delete(:encryption_key)
|
|
449
525
|
options.delete(:envelope_location)
|
|
450
526
|
options.delete(:instruction_file_suffix)
|
|
527
|
+
options.delete(:commitment_policy)
|
|
451
528
|
REQUIRED_PARAMS.each { |p| options.delete(p) }
|
|
452
529
|
S3::Client.new(options)
|
|
453
530
|
end
|
|
454
531
|
end
|
|
455
532
|
|
|
456
533
|
def kms_client(options)
|
|
457
|
-
options[:kms_client] ||
|
|
534
|
+
options[:kms_client] || (@kms_client ||=
|
|
458
535
|
KMS::Client.new(
|
|
459
536
|
region: @client.config.region,
|
|
460
537
|
credentials: @client.config.credentials,
|
|
461
538
|
)
|
|
462
|
-
|
|
463
|
-
end
|
|
464
|
-
|
|
465
|
-
def cipher_provider(options)
|
|
466
|
-
if options[:kms_key_id]
|
|
467
|
-
KmsCipherProvider.new(
|
|
468
|
-
kms_key_id: options[:kms_key_id],
|
|
469
|
-
kms_client: kms_client(options),
|
|
470
|
-
key_wrap_schema: options[:key_wrap_schema],
|
|
471
|
-
content_encryption_schema: options[:content_encryption_schema]
|
|
472
|
-
)
|
|
473
|
-
else
|
|
474
|
-
@key_provider = extract_key_provider(options)
|
|
475
|
-
DefaultCipherProvider.new(
|
|
476
|
-
key_provider: @key_provider,
|
|
477
|
-
key_wrap_schema: options[:key_wrap_schema],
|
|
478
|
-
content_encryption_schema: options[:content_encryption_schema]
|
|
479
|
-
)
|
|
480
|
-
end
|
|
539
|
+
)
|
|
481
540
|
end
|
|
482
541
|
|
|
483
542
|
def extract_key_provider(options)
|
|
@@ -560,7 +619,27 @@ module Aws
|
|
|
560
619
|
end
|
|
561
620
|
security_profile
|
|
562
621
|
end
|
|
622
|
+
|
|
623
|
+
def extract_commitment_policy(options)
|
|
624
|
+
validate_commitment_policy(options[:commitment_policy])
|
|
625
|
+
end
|
|
626
|
+
|
|
627
|
+
def validate_commitment_policy(commitment_policy)
|
|
628
|
+
return nil if commitment_policy.nil?
|
|
629
|
+
|
|
630
|
+
unless SUPPORTED_COMMITMENT_POLICIES.include? commitment_policy
|
|
631
|
+
raise ArgumentError, "Unsupported commitment policy: :#{commitment_policy}. " \
|
|
632
|
+
"The V2 client only supports :forbid_encrypt_allow_decrypt for migration purposes. " \
|
|
633
|
+
"For migration guidance, see: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/s3-encryption-migration-v2-v3.html"
|
|
634
|
+
end
|
|
635
|
+
commitment_policy
|
|
636
|
+
end
|
|
563
637
|
end
|
|
564
638
|
end
|
|
565
639
|
end
|
|
566
640
|
end
|
|
641
|
+
|
|
642
|
+
##= ../specification/s3-encryption/data-format/content-metadata.md#v1-v2-shared
|
|
643
|
+
##= type=exception
|
|
644
|
+
##= reason=This has never been supported in Ruby
|
|
645
|
+
##% This string MAY be encoded by the esoteric double-encoding scheme used by the S3 web server.
|