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

DotNet Credential should be scoped to a valid region when using CloudFront KeyValueStore #3143

Closed
genifycom opened this issue Jan 11, 2024 · 9 comments · Fixed by #3144
Closed
Labels
bug This issue is a bug. credentials

Comments

@genifycom
Copy link

genifycom commented Jan 11, 2024

Describe the bug

Error: "Credential should be scoped to a valid region" when attempting to read keys from the CloudFront KeyValueStore.

Might be related to #1097 in the JS AWS-SDK

Expected Behavior

As per AWS CLI, the keys/values are returned from the KeyValueStore

Current Behavior

c# Exception with the Message "Credential should be scoped to a valid region"

Reproduction Steps

The following c# code dementrates the issue. Checked kvarn using AWS CLI and results return as expected.

`
BasicAWSCredentials creds = new BasicAWSCredentials(aws_access_key, aws_secret_key);

        AmazonCloudFrontKeyValueStoreConfig config = new();
        config.SignatureVersion = "v4"; //Tried with and without
        config.RegionEndpoint = RegionEndpoint.USWest1; //Region of the provided keys

        AmazonCloudFrontKeyValueStoreClient kvs = new(creds, config);

        ListKeysRequest request = new()
        {
            KvsARN = kvarn,
            MaxResults = 10
        };

        try
        {
            var result = await kvs.ListKeysAsync(request);
        }
        catch (Exception ex)
        {
            var msg = ex.Message; //Credential should be scoped to a valid region.
        }

`

Possible Solution

Maybe something with signing as per #1097 in the JS AWS-SDK

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Targeted .NET Platform

.NET Core .8

Operating System and version

Windows 11

@genifycom genifycom added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 11, 2024
@normj
Copy link
Member

normj commented Jan 12, 2024

@genifycom This is a bug on our side. The CloudFront KeyValueStore service uses SigV4a for signing and our automations systems didn't pick that up and is signing with SigV4 which causes the error you are seeing. We will work to get this addressed so it uses SigV4a.

If you need an immediate work around you can subclass AmazonCloudFrontKeyValueStoreClient and override the CreateSigner to force SigV4a. Below is an example.

public class AmazonCloudFrontKeyValueStoreClientWithSigV4a : AmazonCloudFrontKeyValueStoreClient
{
    public AmazonCloudFrontKeyValueStoreClientWithSigV4a(AWSCredentials creds, AmazonCloudFrontKeyValueStoreConfig config)
        : base(creds, config) { }

    public AmazonCloudFrontKeyValueStoreClientWithSigV4a(AmazonCloudFrontKeyValueStoreConfig config)
        : base(config) { }

    protected override AbstractAWSSigner CreateSigner()
    {
        return new Amazon.Runtime.Internal.Auth.AWS4aSignerCRTWrapper();
    }
}

Since this is using SigV4a you also need to include the AWSSDK.Extensions.CrtIntegration NuGet package for your project.

@dscpinheiro dscpinheiro added p0 This issue is the highest priority and removed needs-triage This issue or PR still needs to be triaged. labels Jan 12, 2024
@muhammad-othman
Copy link
Member

Good day @genifycom
We've created a fix to this bug in this PR #3144.
It will be included in today's release which should complete before 4pm PST.

@genifycom
Copy link
Author

Thanks so much!

Copy link

⚠️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.

@muhammad-othman
Copy link
Member

@genifycom The release is completed, please update CloudFrontKeyValueStore nuget package to v3.7.300.28
I've tested it with the same code that you provided which didn't work before this release.
image

@genifycom
Copy link
Author

Don't forget to add NuGet AWSSDK.Extensions.CrtIntegration v3.7.300 as a dependency for CloudFrontKeyValueStore v3.7.300.28 otherwise this will not work.

Thanks

@genifycom
Copy link
Author

I tested with Windows and everything is fine. Under Android (MAUI Android) however

result = await kvs.ListKeysAsync(request); //Gives "The type initializer for 'Aws.Crt.NativeAPI' threw an exception"

The call stack shows nothing useful.

Using the latest:

	<PackageReference Include="AWSSDK.CloudFrontKeyValueStore" Version="3.7.301.11" />
	<PackageReference Include="AWSSDK.Extensions.CrtIntegration" Version="3.7.300.1" />

@genifycom genifycom reopened this Feb 14, 2024
@dscpinheiro dscpinheiro added needs-review and removed p0 This issue is the highest priority labels Feb 14, 2024
@dscpinheiro
Copy link
Contributor

Oh, I think this is an issue with the CRT library, as far as I know it doesn't support .NET bindings on Android / IOS.

We have a separate issue with the same root cause (#2126), I'll close this one and also follow up on the aws-crt-dotnet repo (awslabs/aws-crt-dotnet#90).

Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. credentials
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants