aws-sdk-go-v2
aws-sdk-go-v2 copied to clipboard
Using aws.AnonymousCredentials{} in config fails to skip SignHTTPRequestMiddleware#HandleFinalize
Confirm by changing [ ] to [x] below to ensure that it's a bug:
- [x] I've gone though the API reference
- [x] I've checked AWS Forums and StackOverflow for answers
- [x] I've searched for previous similar issues and didn't find any solution
Describe the bug
Using aws.AnonymousCredentials{} in config fails to skip SignHTTPRequestMiddleware#HandleFinalize. The haveCredentialProvider function that returns true when it looks like it should be returning false.
File: github.com/aws/[email protected]/aws/signer/v4/middleware.go
I'm using config.LoadDefaultConfig like so with a call to SQS (using anonymous to write some tracing middleware unit tests).
awsCfg, err := config.LoadDefaultConfig(
context.Background(),
config.WithRegion("eu-west-1"),
config.WithEndpointResolver(resolver),
config.WithCredentialsProvider(aws.AnonymousCredentials{}),
)
sqsClient := sqs.NewFromConfig(awsCfg)
_, err = sqsClient.ListQueues(context.Background(), &sqs.ListQueuesInput{})
require.NoError(t, err)
// Error: operation error SQS: ListQueues, failed to sign request: failed to retrieve credentials:
// the AnonymousCredentials is not a valid credential provider, and cannot be used to sign AWS requests with
The reason I think this fails is because the type switch inside haveCredentialProvider is looking at p which is actually aws.CredentialsCache with aws.AnonymousCredentials{} within the cache.
func haveCredentialProvider(p aws.CredentialsProvider) bool {
if p == nil {
return false
}
switch p.(type) {
case aws.AnonymousCredentials,
*aws.AnonymousCredentials:
return false
}
return true
}
Version of AWS SDK for Go? v1.2.1
Version of Go (go version)?
go1.16 darwin/arm64
To Reproduce (observed behavior) See above description.
Expected behavior
I would expect the signing SignHTTPRequestMiddleware#HandleFinalize to return straight away when using aws.AnonymousCredentials{} so that signing is skipped.
Additional context N/A.
I have noticed that this is only due to using LoadDefaultConfig which does the work around wrapping the CredentialsProvider in the cache. So this may not be deemed an issue. I can get around it by just building the config manually -
awsCfg := aws.Config{
Region: "eu-west-1",
Credentials: aws.AnonymousCredentials{},
EndpointResolver: resolver,
}
Related to issue https://github.com/aws/aws-sdk-go-v2/issues/1797
Awaiting fix.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.