aws-rotate-iam-keys icon indicating copy to clipboard operation
aws-rotate-iam-keys copied to clipboard

The powershell script fails if repeated 2 times or more

Open MarcSamD opened this issue 2 years ago • 1 comments

On my case, the script only works when launch the first time. Then there is an authentication issue and it cannot creates new keys (nor do anything in AWS in fact).

I found after the script is run a first time, 2 profiles "default" exist and can be displayed with the command Get-AWSCredentials -ListProfileDetail:

ProfileName StoreTypeName         ProfileLocation
----------- -------------         ---------------
default     NetSDKCredentialsFile
default     SharedCredentialsFile C:\Users\username\.aws\credentials

I suspect that somehow, when the script updates the profiles, it succeeds for the SharedCredentialsFile but it fails for the NetSDKCredentialsFile. Manually removing the NetSDKCredentialsFile with the command Remove-AWSCredentialProfile -ProfileName default is a workaround to make the script work again once.

MarcSamD avatar Oct 11 '22 07:10 MarcSamD

A (dirty?) way to fix this issue is to comment the line Set-AWSCredential -StoreAs $profile -AccessKey $new_key.AccessKeyId -SecretKey $new_key.SecretAccessKey in the script to only keep the 1st one that update the ProfileLocation (so the SharedCredentialsFile).

I'm not sure what this 2nd line is for (updating SDK credentials ?) and it seems other people are not complaining about so I don't create a PR for this. But I see 2 reasons that it could be linked to: either MFA setup or usage on a non standard region (I'm on China region). The issue #65 could also be caused by that as I had very similar authentication error message.

MarcSamD avatar Oct 11 '22 08:10 MarcSamD