aws-sdk-net: Unable to get Default Credentials using CredentialProfileStoreChain

Expected Behavior

When calling credentialProfileStoreChain.TryGetAWSCredentials("default", out defaultCredentials) with a valid profile named default I would expect it to return true and set the credentials properly.

Current Behavior

The credentials are not loaded for the default profile, but it will work for other profile names

Possible Solution

For a workaround I am able to use the deprecated call AWSCredentials creds = new StoredProfileAWSCredentials("default");

Steps to Reproduce (for bugs)

            var credentialProfileStoreChain = new CredentialProfileStoreChain();
            AWSCredentials otherCredentials;
            if (credentialProfileStoreChain.TryGetAWSCredentials("other_user", out otherCredentials))
                Console.WriteLine("Found other_user credentials using CredentialProfileStoreChain");
            else
                Console.WriteLine("Could not find other_user credentials using chain");
            
            AWSCredentials defaultCredentials;
            if (credentialProfileStoreChain.TryGetAWSCredentials("default", out defaultCredentials))
                Console.WriteLine("Found default credentials using chain");
            else
                Console.WriteLine("Could not find default credentials using CredentialProfileStoreChain");
            
            try
            {
                AWSCredentials creds = new StoredProfileAWSCredentials("default");
                Console.WriteLine("Got default credentials using deprecated StoredProfileAWSCredentials");
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not get default credentials using deprecated StoredProfileAWSCredentials" + e.Message);
                Console.WriteLine(e.StackTrace);
            }

Credentials file stored under C:\Users<user>.aws\credentials

[default]

aws_access_key_id = XXXXXXXXXXXXXXXXXXX

aws_secret_access_key = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

[other_user]

aws_access_key_id = XXXXXXXXXXXXXXXXXXX

aws_secret_access_key = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Results of running code above

Found other_user credentials using CredentialProfileStoreChain
Could not find default credentials using CredentialProfileStoreChain
Got default credentials using deprecated StoredProfileAWSCredentials

Context

I am trying to use my default profile to get credentials without using deprecated code.

Your Environment

  • AWSSDK.Core version used: 3.3.24.6
  • Operating System and version: Windows 10
  • Visual Studio version: Comunity 2015
  • Targeted .NET platform: 4.5

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

The reason for the difference is that the encrypted .NET credential store in the AWS Toolkit for Visual Studio predates the shared credentials files used by the AWS CLI and other SDKs. I’m working on a way to skip the profile in the .NET credentials file if it’s incomplete, and check the shared credentials file. Will update when a fix is ready.

I ran into this issue too and changing to [profile default] worked for me but not ideal.

I believe a special case for “default” needs to be added here: https://github.com/aws/aws-sdk-net/blob/master/sdk/src/Core/Amazon.Runtime/Internal/Util/_bcl+netstandard/ProfileIniFile.cs#L60

~Somewhat related, my app run with a role in production. So ideally I want not use any credentials parameter and have it use my default profile from my config file which assumes the dev role to run locally. Then code is the same for local, dev and prod. This doesn’t work currently.~

UPDATE: Actually using [profile default] fixes my other issue too. Should be an easy fix, I’ll give it a shot.

The code below correctly iterates over my profiles and gets the credentials

            SharedCredentialsFile sf = new SharedCredentialsFile();
            foreach (var profile in sf.ListProfiles())
            {
                profile.GetAWSCredentials(sf);
                Console.WriteLine($"Got {profile.Name} credentials using SharedCredentialsFile");
            }

There doesn’t appear to be a default credential in the .NET store(I just created the test one)

image