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

Update request pipeline to use the AuthSchemeResolver to resolve the identity and signer #3552

Open
wants to merge 1 commit into
base: muhamoth/DOTNET-7538-remove-CreateSigner
Choose a base branch
from

Conversation

muhammad-othman
Copy link
Member

Description

  • Added AuthScheme.Signer() method to retrieve the signer associated with this authentication scheme.
  • Retrieved identity resolver and signer for the current scheme and attach them to request context in BaseAuthResolverHandler.
  • Updated BaseAuthResolverHandler to allow children to override the signer.
  • Added AuthSchemeHandler to the pipeline (limited to S3 and AutoScaling for now).

Motivation and Context

  • DOTNET-7802

Testing

  • Ran the unit tests and integration tests for S3 and AutoScaling services.

}
}

protected virtual AbstractAWSSigner GetSigner(IAuthScheme<BaseIdentity> scheme)
Copy link
Member

Choose a reason for hiding this comment

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

Should this return ISigner. AbstractAWSSigner seems tired to a SigV4(a) signer.

Copy link
Member Author

Choose a reason for hiding this comment

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

All the signers do implement AbstractAWSSigner, and this is the type of executionContext.RequestContext.Signer
so we will have to cast it again anyway.
image

Changing executionContext.RequestContext.Signer to ISigner wont be very simple since we do depend on signer referencing core internal types that need to be extracted / refactored (e.g. IRequest).

/// <inheritdoc/>
public ISigner Signer()
{
return new NullSigner();
Copy link
Member

Choose a reason for hiding this comment

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

For each of these schemes should the signer be a member variable so we can reuse the same instance instead of recreating the signer for every request?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add a static readonly variable to cache the signer.

// var identityResolver = scheme.IdentityResolver();
// var identity = identityResolver.GetIdentity();
// var signer = scheme.Signer();
executionContext.RequestContext.Identity = this.Identity;
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this have the problem that if a service client has some operations that take AWS SigV4 credentials and others that take a token we will always use the identity passed into the constructor for the service client. Should we only use the identity passed into the constructor for the operations that support that type. Otherwise use the resolver.

On that note, if a service does use both SigV4 and Token how do you configure the service client for both?

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 I did miss that, will rename this.Identity to DefaultAWSCredentials and make sure that we use it for SigV4/SigV4a.

For the other note, we didn't allow the users to provide a Token when creating the client, however the could provide IAWSTokenProvider implementation, which should be respected when implementing SSO, right @dscpinheiro?

if (executionContext.RequestContext.Identity == null)
{
var identityResolver = scheme.GetIdentityResolver(executionContext.RequestContext.ClientConfig.IdentityResolverConfiguration);
executionContext.RequestContext.Identity = identityResolver.ResolveIdentity();
Copy link
Member

Choose a reason for hiding this comment

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

Confirming if we do go in here for every request and the identity is eventually resolved by hitting IMDS we wouldn't go to IMDS for every request correct?

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 shouldn't happen since we do cache the credentials in DefaultAWSCredentialsIdentityResolver.

if (Credentials != null && !(Credentials is AnonymousAWSCredentials))
var identity = executionContext.RequestContext.Identity as AWSCredentials;

if (identity != null && !(identity is AnonymousAWSCredentials))
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we should update AnonymousAWSCredentials to return null for GetCredentialsAsync so we can avoid having these special cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be even simpler than that, we can just return null for GetCredentials and GetCredentialsAsync has an implementation in the base class that just uses GetCredentials and we don't need to change that.

Now this made me think that we shouldn't need the BearerTokenSigner special case too that we have above, since the signer cannot be BearerTokenSigner when the Identity is AWSCredentials.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants