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

Remove ImmutableCredentials property from IRequestContext #3589

Open
wants to merge 1 commit into
base: sra-identity-auth
Choose a base branch
from

Conversation

muhammad-othman
Copy link
Member

Description

  • Removed ImmutableCredentials property from IRequestContext.
  • Existing usages of requestContext.ImmutableCredentials are updated to use request.Identity instead.
  • Update the ISigner interface to include the methods and properties needed for its usages.
  • Remove the references to AbstractAWSSigner start using the new ISigner interface instead.

Motivation and Context

DOTNET-7845

Testing

DRY_RUN-93591562-46d9-4349-a75e-07822865d20a


// credentials would be null in the case of anonymous users getting public resources from S3
if (immutableCredentials == null && requestContext.Signer.RequiresCredentials)
if (requestContext.Identity == null && requestContext.Signer.RequiresCredentials)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anonymous calls will pass this condition, since the identity will be an AnonymousAWSCredentials instance, and I think it is the right approach as we shouldn't add extra corner cases for AnonymousAWSCredentials and they will have a NullSigner which can be called at the end of this method.

@@ -201,26 +201,6 @@ public void TestSerializingExceptions()
}
}

[TestMethod]
[TestCategory("General")]
public void TestAnonymousCredentialsGetThroughPipeline()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case isn't valid anymore since AnonymousAWSCredentials cannot be used for actions that require credentials.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @afroz429 (I think this may impact PowerShell - I recall seeing code that explicitly set anonymous credentials for specific Cmdlets)

@@ -201,26 +201,6 @@ public void TestSerializingExceptions()
}
}

[TestMethod]
[TestCategory("General")]
public void TestAnonymousCredentialsGetThroughPipeline()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @afroz429 (I think this may impact PowerShell - I recall seeing code that explicitly set anonymous credentials for specific Cmdlets)

@@ -113,7 +113,7 @@ private static string CheckRegionAndUpdateCache(AmazonS3Uri requestedBucketUri,
private static string GetHeadBucketPreSignedUrl(string bucketName, IRequestContext requestContext)
{
// all buckets accessible via USEast1
using (var s3Client = GetUsEast1ClientFromCredentials(requestContext.ImmutableCredentials))
using (var s3Client = GetUsEast1ClientFromCredentials(requestContext.ClientConfig.DefaultAWSCredentials))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other places you changed use requestContext.Identity as AWSCredentials and awsCredentials.GetCredentials().

Is using ClientConfig.DefaultAWSCredentials instead here intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep it is intentional. Here we are creating a client this way
image

And we cannot just set the identity, since it will be overridden anyway in the request pipeline, we need to set the credentials if we was provided by the user, otherwise we will leave it to the AuthResolver to figure it out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. It'd be good to include a comment, it's easy to miss why DefaultAWSCredentials is being used if you don't have more context.

@@ -67,9 +67,9 @@ public void TestRetriesOnException<T>(T exception) where T : AmazonServiceExcept
.GetValue(client, null)
as RuntimePipeline;
// Setup STS failures
var credentialsRetriever = new Mock<CredentialsRetriever>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed this class is using the FallbackCredentialsFactory (same for https://github.com/aws/aws-sdk-net/blob/sra-identity-auth/sdk/test/UnitTests/Custom/Runtime/Credentials/FallbackFactoryTest.cs).

We should probably update our tests to use the DefaultAWSCredentialsIdentityResolver instead (as a separate PR - not as part of this one).

@@ -24,11 +31,25 @@ namespace Amazon.Runtime.Internal.Auth
/// the service to authenticate the SDK customer's identity.
/// </para>
/// </summary>
#pragma warning disable CA1040 // Avoid empty interfaces
public interface ISigner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add /// comments to the other public methods since you added them to RequiresCredentials.

Copy link
Contributor

@dscpinheiro dscpinheiro Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muhammad-othman There's some text in the SRA book (for the Signer interface) if you want to use that: Signs the provided HTTP request. The provided identity is used for signing, and an exception will be thrown if the identity is not compatible with this signer.

I also noticed the existing comment for RequiresCredentials mentions immutable credentials (which we're trying to remove). May as well remove the <see cref="ImmutableCredentials"/> from there.

@dscpinheiro dscpinheiro removed the request for review from normj December 31, 2024 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants