Skip to content

Commit 6c3bb68

Browse files
authored
Remove CRT SigV4a (#3107)
1 parent 10472d0 commit 6c3bb68

File tree

9 files changed

+50
-219
lines changed

9 files changed

+50
-219
lines changed

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Feature - Support `sigv4a` endpoint auth without CRT.
5+
46
3.205.0 (2024-09-11)
57
------------------
68

gems/aws-sdk-core/lib/aws-sdk-core/endpoints.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
module Aws
2020
# @api private
2121
module Endpoints
22-
supported_auth_traits = %w[aws.auth#sigv4 smithy.api#httpBearerAuth smithy.api#noAuth]
23-
supported_auth_traits += ['aws.auth#sigv4a'] if Aws::Sigv4::Signer.use_crt?
24-
SUPPORTED_AUTH_TRAITS = supported_auth_traits.freeze
22+
SUPPORTED_AUTH_TRAITS = %w[
23+
aws.auth#sigv4
24+
aws.auth#sigv4a
25+
smithy.api#httpBearerAuth
26+
smithy.api#noAuth
27+
].freeze
2528

2629
class << self
2730
def resolve_auth_scheme(context, endpoint)

gems/aws-sdk-s3/features/client/step_definitions.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,6 @@ def create_bucket(options = {})
464464
end
465465

466466
When(/I have access to an MRAP bucket and CRT/) do
467-
unless Aws::Sigv4::Signer.use_crt?
468-
pending("CRT is not available")
469-
end
470-
471467
begin
472468
@client.head_bucket(bucket: 'ruby-sdk-integtest-mrap-bucket')
473469
rescue

gems/aws-sdk-s3/spec/presigner_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ def initialize(expiration_time)
103103
end
104104

105105
it 'can sign with additional whitelisted headers' do
106-
skip("CRT does not support whitelisting user-agent") if Aws::Sigv4::Signer.use_crt?
107-
108106
actual_url = subject.presigned_url(
109107
:get_object,
110108
bucket: 'examplebucket',
@@ -256,8 +254,6 @@ def initialize(expiration_time)
256254
end
257255

258256
it 'can sign with additional whitelisted headers' do
259-
skip("CRT is unable to whitelist user-agent") if Aws::Sigv4::Signer.use_crt?
260-
261257
actual_url, = subject.presigned_request(
262258
:get_object,
263259
bucket: 'examplebucket',

gems/aws-sigv4/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Feature - Remove CRT `sigv4a` signing capability.
5+
46
1.9.1 (2024-07-29)
57
------------------
68

gems/aws-sigv4/lib/aws-sigv4/signer.rb

Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ module Sigv4
7474
# and `#session_token`.
7575
#
7676
class Signer
77-
78-
@@use_crt =
79-
begin
80-
require 'aws-crt'
81-
true
82-
rescue LoadError
83-
false
84-
end
85-
8677
# @overload initialize(service:, region:, access_key_id:, secret_access_key:, session_token:nil, **options)
8778
# @param [String] :service The service signing name, e.g. 's3'.
8879
# @param [String] :region The region name, e.g. 'us-east-1'. When signing
@@ -154,13 +145,6 @@ def initialize(options = {})
154145
@signing_algorithm = options.fetch(:signing_algorithm, :sigv4)
155146
@normalize_path = options.fetch(:normalize_path, true)
156147
@omit_session_token = options.fetch(:omit_session_token, false)
157-
158-
if @signing_algorithm == 'sigv4-s3express'.to_sym &&
159-
Signer.use_crt? && Aws::Crt::GEM_VERSION <= '0.1.9'
160-
raise ArgumentError,
161-
'This version of aws-crt does not support S3 Express. Please
162-
update this gem to at least version 0.2.0.'
163-
end
164148
end
165149

166150
# @return [String]
@@ -236,9 +220,6 @@ def initialize(options = {})
236220
# a `#headers` method. The headers must be applied to your request.
237221
#
238222
def sign_request(request)
239-
240-
return crt_sign_request(request) if Signer.use_crt?
241-
242223
creds, _ = fetch_credentials
243224

244225
http_method = extract_http_method(request)
@@ -344,7 +325,6 @@ def sign_request(request)
344325
# signature value (a binary string) used at ':chunk-signature' needs to converted to
345326
# hex-encoded string using #unpack
346327
def sign_event(prior_signature, payload, encoder)
347-
# Note: CRT does not currently provide event stream signing, so we always use the ruby implementation.
348328
creds, _ = fetch_credentials
349329
time = Time.now
350330
headers = {}
@@ -431,9 +411,6 @@ def sign_event(prior_signature, payload, encoder)
431411
# @return [HTTPS::URI, HTTP::URI]
432412
#
433413
def presign_url(options)
434-
435-
return crt_presign_url(options) if Signer.use_crt?
436-
437414
creds, expiration = fetch_credentials
438415

439416
http_method = extract_http_method(options)
@@ -801,131 +778,7 @@ def presigned_url_expiration(options, expiration, datetime)
801778
end
802779
end
803780

804-
### CRT Code
805-
806-
# the credentials used by CRT must be a
807-
# CRT StaticCredentialsProvider object
808-
def crt_fetch_credentials
809-
creds, expiration = fetch_credentials
810-
crt_creds = Aws::Crt::Auth::StaticCredentialsProvider.new(
811-
creds.access_key_id,
812-
creds.secret_access_key,
813-
creds.session_token
814-
)
815-
[crt_creds, expiration]
816-
end
817-
818-
def crt_sign_request(request)
819-
creds, _ = crt_fetch_credentials
820-
http_method = extract_http_method(request)
821-
url = extract_url(request)
822-
headers = downcase_headers(request[:headers])
823-
824-
datetime =
825-
if headers.include? 'x-amz-date'
826-
Time.parse(headers.delete('x-amz-date'))
827-
end
828-
829-
content_sha256 = headers.delete('x-amz-content-sha256')
830-
content_sha256 ||= sha256_hexdigest(request[:body] || '')
831-
832-
sigv4_headers = {}
833-
sigv4_headers['host'] = headers['host'] || host(url)
834-
835-
# Modify the user-agent to add usage of crt-signer
836-
# This should be temporary during developer preview only
837-
if headers.include? 'user-agent'
838-
headers['user-agent'] = "#{headers['user-agent']} crt-signer/#{@signing_algorithm}/#{Aws::Sigv4::VERSION}"
839-
sigv4_headers['user-agent'] = headers['user-agent']
840-
end
841-
842-
headers = headers.merge(sigv4_headers) # merge so we do not modify given headers hash
843-
844-
config = Aws::Crt::Auth::SigningConfig.new(
845-
algorithm: @signing_algorithm,
846-
signature_type: :http_request_headers,
847-
region: @region,
848-
service: @service,
849-
date: datetime,
850-
signed_body_value: content_sha256,
851-
signed_body_header_type: @apply_checksum_header ?
852-
:sbht_content_sha256 : :sbht_none,
853-
credentials: creds,
854-
unsigned_headers: @unsigned_headers,
855-
use_double_uri_encode: @uri_escape_path,
856-
should_normalize_uri_path: @normalize_path,
857-
omit_session_token: @omit_session_token
858-
)
859-
http_request = Aws::Crt::Http::Message.new(
860-
http_method, url.to_s, headers
861-
)
862-
signable = Aws::Crt::Auth::Signable.new(http_request)
863-
864-
signing_result = Aws::Crt::Auth::Signer.sign_request(config, signable)
865-
866-
Signature.new(
867-
headers: sigv4_headers.merge(
868-
downcase_headers(signing_result[:headers])
869-
),
870-
string_to_sign: 'CRT_INTERNAL',
871-
canonical_request: 'CRT_INTERNAL',
872-
content_sha256: content_sha256,
873-
extra: {config: config, signable: signable}
874-
)
875-
end
876-
877-
def crt_presign_url(options)
878-
creds, expiration = crt_fetch_credentials
879-
880-
http_method = extract_http_method(options)
881-
url = extract_url(options)
882-
headers = downcase_headers(options[:headers])
883-
headers['host'] ||= host(url)
884-
885-
datetime = Time.strptime(headers.delete('x-amz-date'), "%Y%m%dT%H%M%S%Z") if headers['x-amz-date']
886-
datetime ||= (options[:time] || Time.now)
887-
888-
content_sha256 = headers.delete('x-amz-content-sha256')
889-
content_sha256 ||= options[:body_digest]
890-
content_sha256 ||= sha256_hexdigest(options[:body] || '')
891-
892-
config = Aws::Crt::Auth::SigningConfig.new(
893-
algorithm: @signing_algorithm,
894-
signature_type: :http_request_query_params,
895-
region: @region,
896-
service: @service,
897-
date: datetime,
898-
signed_body_value: content_sha256,
899-
signed_body_header_type: @apply_checksum_header ?
900-
:sbht_content_sha256 : :sbht_none,
901-
credentials: creds,
902-
unsigned_headers: @unsigned_headers,
903-
use_double_uri_encode: @uri_escape_path,
904-
should_normalize_uri_path: @normalize_path,
905-
omit_session_token: @omit_session_token,
906-
expiration_in_seconds: presigned_url_expiration(options, expiration, datetime)
907-
)
908-
http_request = Aws::Crt::Http::Message.new(
909-
http_method, url.to_s, headers
910-
)
911-
signable = Aws::Crt::Auth::Signable.new(http_request)
912-
913-
signing_result = Aws::Crt::Auth::Signer.sign_request(config, signable, http_method, url.to_s)
914-
url = URI.parse(signing_result[:path])
915-
916-
if options[:extra] && options[:extra].is_a?(Hash)
917-
options[:extra][:config] = config
918-
options[:extra][:signable] = signable
919-
end
920-
url
921-
end
922-
923781
class << self
924-
925-
def use_crt?
926-
@@use_crt
927-
end
928-
929782
# @api private
930783
def uri_escape_path(path)
931784
path.gsub(/[^\/]+/) { |part| uri_escape(part) }

gems/aws-sigv4/spec/signer_spec.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,6 @@ module Sigv4
357357
end
358358

359359
it 'escapes path for the canonical request by default' do
360-
skip("CRT does not provide canonical request") if Signer.use_crt?
361-
362360
signature = Signer.new(options).sign_request(
363361
http_method: 'GET',
364362
url: 'https://domain.com/foo%bar'
@@ -367,8 +365,6 @@ module Sigv4
367365
end
368366

369367
it 'escapes path for the canonical request if :uri_escape_path is true' do
370-
skip("CRT does not provide canonical request") if Signer.use_crt?
371-
372368
options[:uri_escape_path] = true
373369
signature = Signer.new(options).sign_request(
374370
http_method: 'GET',
@@ -378,8 +374,6 @@ module Sigv4
378374
end
379375

380376
it 'does not escape path for the canonical request if :uri_escape_path is false' do
381-
skip("CRT does not provide canonical request") if Signer.use_crt?
382-
383377
options[:uri_escape_path] = false
384378
signature = Signer.new(options).sign_request(
385379
http_method: 'GET',
@@ -427,9 +421,6 @@ module Sigv4
427421
end
428422

429423
context ':canonical_request' do
430-
431-
before { skip("CRT Signer does not expose canonical request") if Signer.use_crt? }
432-
433424
it 'lower-cases and sort all header keys except authorization' do
434425
signature = Signer.new(options).sign_request(
435426
http_method: 'PUT',

0 commit comments

Comments
 (0)