Skip to content

Commit 58c85f2

Browse files
committed
Ignore invalid ARNs when trying to parse accountId in assume role credentials.
1 parent 2c4fe8b commit 58c85f2

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Diff for: gems/aws-sdk-core/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Unreleased Changes
33

44
* Issue - Add service identifiers to GlobalConfig's list of identifiers outside of autoload (#3113).
55

6+
* Issue - Ignore invalid ARNs when trying to parse accountId in assume role credentials.
7+
68
3.208.0 (2024-09-23)
79
------------------
810

Diff for: gems/aws-sdk-core/lib/aws-sdk-core/assume_role_credentials.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,17 @@ def initialize(options = {})
6464
def refresh
6565
c = @client.assume_role(@assume_role_params)
6666
creds = c.credentials
67+
account_id =
68+
begin
69+
ARNParser.parse(c.assumed_role_user.arn).account_id
70+
rescue Aws::Errors::InvalidARNError
71+
nil
72+
end
6773
@credentials = Credentials.new(
6874
creds.access_key_id,
6975
creds.secret_access_key,
7076
creds.session_token,
71-
account_id: ARNParser.parse(c.assumed_role_user.arn).account_id
77+
account_id: account_id
7278
)
7379
@expiration = creds.expiration
7480
end

Diff for: gems/aws-sdk-core/lib/aws-sdk-core/assume_role_web_identity_credentials.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,17 @@ def refresh
7575

7676
c = @client.assume_role_with_web_identity(@assume_role_web_identity_params)
7777
creds = c.credentials
78+
account_id =
79+
begin
80+
ARNParser.parse(c.assumed_role_user.arn).account_id
81+
rescue Aws::Errors::InvalidARNError
82+
nil
83+
end
7884
@credentials = Credentials.new(
7985
creds.access_key_id,
8086
creds.secret_access_key,
8187
creds.session_token,
82-
account_id: ARNParser.parse(c.assumed_role_user.arn).account_id
88+
account_id: account_id
8389
)
8490
@expiration = creds.expiration
8591
end

0 commit comments

Comments
 (0)