Skip to content

Commit

Permalink
Merge pull request #107 from OlegBoulanov/develop
Browse files Browse the repository at this point in the history
Minor role names comparison fix
  • Loading branch information
OlegBoulanov authored Sep 30, 2022
2 parents 1d59548 + b9b8df4 commit 2fa1aca
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 2fa1aca

Please sign in to comment.