aws-sdk-go
aws-sdk-go copied to clipboard
[shared defaults] unable to locate files when environment variables are not set
Describe the bug
The defaults for SharedCredentialsFilename() and SharedConfigFilename() in internal/shareddefaults/shared_config.go rely on UserHomeDir() to return the home directory of the current user:
// internal/shareddefaults/shared_config.go
func UserHomeDir() string {
if runtime.GOOS == "windows" { // Windows
return os.Getenv("USERPROFILE")
}
// *nix
return os.Getenv("HOME")
}
When either environment variable is not set, SharedCredentialsFilename() returns ".aws/credentials", and SharedConfigFilename() returns ".aws/config" - relative paths that can not be found.
Expected Behavior
Certain test environments, such as e.g. bazel, clear the HOME environment variable, causing tests that rely on the Golang v1 SDK to fail.
The situation is similar for Windows.
Other AWS SDKs (botocore, AWS C++ SDK >= 1.9) are resilient against changes in the environment, by looking up user information based on the UID of the user, rather than from the environment.
Current Behavior
Clearing $HOME on Linux, or running within bazel test causes the look-up of credential/configuration files ~/.aws/{credentials,config} to fail.
Reproduction Steps
Run code compiled against the Golang v1 SDK by clearing the $HOME variable:
unset HOMEorenv -i ./path/to/golang/executable.
Possible Solution
The standard library in os/user provides user.Current(), which provides the HomeDir field.
Additional Information/Context
Problem is also present in the Golang v2 SDK (same code) -- will create an issue there and refer to here.
SDK version used
v1.44.28
Environment details (Version of Go (go version)? OS name and version, etc.)
Independent of Go version (= all versions).
pending fix: https://github.com/aws/aws-sdk-go/pull/4519
pending fix: #4519
Please see comments in PR.
⚠️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.
⚠️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.
https://github.com/aws/aws-sdk-go/pull/4519/files#diff-9f4a894d36a233d5ad83d3a1a3cea61cba356e3a0e77724bae02bc514333217dL35-R40
This line addresses your concern, were you reading the fix out of context?
I was referring to this comment, which has since been addressed. Thank you for the fix.