Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed ExternalId property in AWS options for assumed role session credentials. #3331

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions extensions/src/AWSSDK.Extensions.NETCore.Setup/AWSOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public class AWSOptions
/// </summary>
public string SessionName { get; set; } = "DefaultSessionName";

/// <summary>
/// A unique identifier that is used by third parties for the assumed session using the SessionRoleArn.
/// </summary>
public string ExternalId { get; set; }

/// <summary>
/// AWS Credentials used for creating service clients. If this is set it overrides the Profile property.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>AWSSDK.Extensions.NETCore.Setup</id>
<title>AWSSDK - Extensions for NETCore Setup</title>
<version>3.7.300</version>
<version>3.7.301</version>
<authors>Amazon Web Services</authors>
<description>Extensions for the AWS SDK for .NET to integrate with .NET Core configuration and dependency injection frameworks.</description>
<language>en-US</language>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ internal static IAmazonService CreateServiceClient(ILogger logger, Type serviceI

if (!string.IsNullOrEmpty(options?.SessionRoleArn))
{
credentials = new AssumeRoleAWSCredentials(credentials, options.SessionRoleArn, options.SessionName);
if (string.IsNullOrEmpty(options?.ExternalId))
{
credentials = new AssumeRoleAWSCredentials(credentials, options.SessionRoleArn, options.SessionName);
}
else
{
credentials = new AssumeRoleAWSCredentials(credentials, options.SessionRoleArn, options.SessionName, new AssumeRoleAWSCredentialsOptions() { ExternalId = options.ExternalId });
}
}

var config = CreateConfig(serviceInterfaceType, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public static AWSOptions GetAWSOptions(this IConfiguration config, string config
options.SessionName = section["SessionName"];
}

if (!string.IsNullOrEmpty(section["ExternalId"]))
{
options.ExternalId = section["ExternalId"];
}

var loggingSection = section.GetSection("Logging");
if(loggingSection != null)
{
Expand Down
1 change: 1 addition & 0 deletions extensions/test/NETCore.SetupTests/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void GetRoleNameAndSessionName()
Assert.Equal(RegionEndpoint.USWest2, options.Region);
Assert.Equal("arn:aws:iam::123456789012:role/fake_role", options.SessionRoleArn);
Assert.Equal("TestSessionName", options.SessionName);
Assert.Equal("TestExternalId", options.ExternalId);

IAmazonS3 client = options.CreateServiceClient<IAmazonS3>();
Assert.NotNull(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"AWS": {
"SessionRoleArn": "arn:aws:iam::123456789012:role/fake_role",
"SessionName": "TestSessionName",
"ExternalId": "TestExternalId",
"Region": "us-west-2"
}
}