Skip to content

Commit

Permalink
Merge 80c8d9c into aa7b379
Browse files Browse the repository at this point in the history
  • Loading branch information
cjyclaire committed May 29, 2019
2 parents aa7b379 + 80c8d9c commit 986a54e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Improved exception messages in credential providers to exclude detailed parse errors that may contain sensitive information.

2.11.284 (2019-05-29)
------------------

Expand Down
24 changes: 14 additions & 10 deletions aws-sdk-core/lib/aws-sdk-core/ecs_credentials.rb
Expand Up @@ -60,7 +60,7 @@ def initialize options = {}
super
end

# @return [Integer] The number of times to retry failed atttempts to
# @return [Integer] The number of times to retry failed attempts to
# fetch credentials from the instance metadata service. Defaults to 0.
attr_reader :retries

Expand All @@ -78,14 +78,18 @@ def refresh
# Retry loading credentials up to 3 times is the instance metadata
# service is responding but is returning invalid JSON documents
# in response to the GET profile credentials call.
retry_errors([JSON::ParserError, StandardError], max_retries: 3) do
c = JSON.parse(get_credentials.to_s)
@credentials = Credentials.new(
c['AccessKeyId'],
c['SecretAccessKey'],
c['Token']
)
@expiration = c['Expiration'] ? Time.parse(c['Expiration']) : nil
begin
retry_errors([JSON::ParserError, StandardError], max_retries: 3) do
c = JSON.parse(get_credentials.to_s)
@credentials = Credentials.new(
c['AccessKeyId'],
c['SecretAccessKey'],
c['Token']
)
@expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
end
rescue JSON::ParserError
raise Aws::Errors::MetadataParserError.new
end
end

Expand Down Expand Up @@ -126,7 +130,7 @@ def retry_errors(error_classes, options = {}, &block)
retries = 0
begin
yield
rescue *error_classes => error
rescue *error_classes => _error
if retries < max_retries
@backoff.call(retries)
retries += 1
Expand Down
9 changes: 9 additions & 0 deletions aws-sdk-core/lib/aws-sdk-core/errors.rb
Expand Up @@ -34,6 +34,15 @@ class << self
end
end

# Raised when InstanceProfileCredentialsProvider or
# EcsCredentialsProvider fails to parse the metadata response after retries
class MetadataParserError < RuntimeError
def initialize(*args)
msg = "Failed to parse metadata service response."
super(msg)
end
end

# Various plugins perform client-side checksums of responses.
# This error indicates a checksum failed.
class ChecksumError < RuntimeError; end
Expand Down
22 changes: 13 additions & 9 deletions aws-sdk-core/lib/aws-sdk-core/instance_profile_credentials.rb
Expand Up @@ -51,7 +51,7 @@ def initialize options = {}
super
end

# @return [Integer] The number of times to retry failed atttempts to
# @return [Integer] The number of times to retry failed attempts to
# fetch credentials from the instance metadata service. Defaults to 0.
attr_reader :retries

Expand All @@ -69,14 +69,18 @@ def refresh
# Retry loading credentials up to 3 times is the instance metadata
# service is responding but is returning invalid JSON documents
# in response to the GET profile credentials call.
retry_errors([JSON::ParserError, StandardError], max_retries: 3) do
c = JSON.parse(get_credentials.to_s)
@credentials = Credentials.new(
c['AccessKeyId'],
c['SecretAccessKey'],
c['Token']
)
@expiration = c['Expiration'] ? Time.parse(c['Expiration']) : nil
begin
retry_errors([JSON::ParserError, StandardError], max_retries: 3) do
c = JSON.parse(get_credentials.to_s)
@credentials = Credentials.new(
c['AccessKeyId'],
c['SecretAccessKey'],
c['Token']
)
@expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
end
rescue JSON::ParserError
raise Aws::Errors::MetadataParserError.new
end
end

Expand Down
5 changes: 4 additions & 1 deletion aws-sdk-core/spec/aws/ecs_credentials_spec.rb
Expand Up @@ -106,7 +106,10 @@ module Aws
to_return(:status => 200, :body => ' ')
expect {
ECSCredentials.new(backoff:0)
}.to raise_error(JSON::ParserError)
}.to raise_error(
Aws::Errors::MetadataParserError,
'Failed to parse metadata service response.'
)
end

it 'retries errors parsing expiration time 3 times' do
Expand Down
5 changes: 4 additions & 1 deletion aws-sdk-core/spec/aws/instance_profile_credentials_spec.rb
Expand Up @@ -157,7 +157,10 @@ module Aws
to_return(:status => 200, :body => ' ')
expect {
InstanceProfileCredentials.new(backoff:0)
}.to raise_error(JSON::ParserError)
}.to raise_error(
Aws::Errors::MetadataParserError,
'Failed to parse metadata service response.'
)
end

it 'retries errors parsing expiration time 3 times' do
Expand Down

0 comments on commit 986a54e

Please sign in to comment.