Skip to content

Commit

Permalink
Minor role names comparison fix
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegBoulanov committed Sep 30, 2022
1 parent 1bc2fcc commit b9b8df4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion s3iLib/AmazonAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using System.Diagnostics.Contracts;

using Amazon;
using Amazon.Runtime;
using Amazon.Runtime.CredentialManagement;
using Amazon.S3;
Expand Down Expand Up @@ -34,7 +35,9 @@ public static class AmazonAccount
{
// not running on EC2
}
return string.IsNullOrWhiteSpace(instanceRoleName) || !profile.Options.RoleArn.EndsWith(instanceRoleName)
var parts = profile.Options.RoleArn.Split('/'); // arn:aws:iam::1234567890:role/name
var roleName = 2 == parts.Length ? parts[1] : ""; // never null
return string.IsNullOrWhiteSpace(instanceRoleName) || !roleName.Equals(instanceRoleName)
? profile.GetAWSCredentials(profile.CredentialProfileStore) // follow standard chain: https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/creds-assign.html
: new InstanceProfileAWSCredentials(instanceRoleName); // use instance refreshed credentials directly (not assuming any roles)
});
Expand Down

0 comments on commit b9b8df4

Please sign in to comment.