aws / aws-tools-for-powershell

The AWS Tools for PowerShell lets developers and administrators manage their AWS services from the PowerShell scripting environment.
Apache License 2.0
235 stars 78 forks source link

Why doesn't AWS.Tools.Common support setting environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY? #199

Closed passbt closed 3 years ago

passbt commented 3 years ago

Why doesn't Set-AWSCredentials in, AWS.Tools.Common, support setting environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY for it's authentication credentials? My specific use case is around a CI/CD tool that is not hosted within an AWS boundary. Obviously, if the CI/CD tool is hosted within an AWS boundary a role is the preferred approach and authentication works without having to do anything further. However, it appears Set-AWSCredentials only supports the use a credentials saved in a profile and this seems like a bad idea in in a CI/CD environment. I know Set-AWSCredentials does support passing the key and secret into it directly, but why not just include the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in it's default search algorithm?

I apologize if I've somehow missed this in the online documentation.

Environment

AWS.Tools.Common: 4.1.6.0 Windows 10


This is a :question: general question

ashishdhingra commented 3 years ago

Hi @passbt,

Good morning.

Thanks for posting the guidance question. The behavior of Set-AWSCredentials is by design where it supports storing credentials to persistent store (-StoreAs) or temporarily for the shell (based on -Scope parameter, refer https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes). I'm not sure why it doesn't support setting credentials to environment variables (may be a good candidate for a feature request!).

You could set an environment variable scoped to a user using the below command as an example:

[System.Environment]::SetEnvironmentVariable('AWS_ACCESS_KEY_ID','<<access_key_id>>',[System.EnvironmentVariableTarget]::User)

Thanks, Ashish

passbt commented 3 years ago

Thank you for your response. What I'm asking for is to also include the above environment variables in the search described here. If it doesn't already exist, and opening a feature is the best way to move forward, I can do that.

ashishdhingra commented 3 years ago

Thank you for your response. What I'm asking for is to also include the above environment variables in the search described here. If it doesn't already exist, and opening a feature is the best way to move forward, I can do that.

Hi @passbt,

The link that you shared specifies credential search order, not the storing credentials. You might have figured out that environment variables can be set at PS session level, user level and system level. Hence it is quite ambiguous to implement this feature.

Thanks, Ashish

github-actions[bot] commented 3 years ago

This issue has not recieved a response in 2 weeks. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.