aws-sdk-go icon indicating copy to clipboard operation
aws-sdk-go copied to clipboard

[shared defaults] unable to locate files when environment variables are not set

Open grrtrr opened this issue 3 years ago • 3 comments

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 HOME or
  • env -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).

grrtrr avatar Jun 16 '22 12:06 grrtrr

pending fix: https://github.com/aws/aws-sdk-go/pull/4519

RanVaknin avatar Oct 18 '22 18:10 RanVaknin

pending fix: #4519

Please see comments in PR.

grrtrr avatar Oct 19 '22 14:10 grrtrr

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

github-actions[bot] avatar Oct 25 '22 18:10 github-actions[bot]

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

github-actions[bot] avatar Mar 30 '23 17:03 github-actions[bot]

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?

RanVaknin avatar Mar 30 '23 17:03 RanVaknin

I was referring to this comment, which has since been addressed. Thank you for the fix.

grrtrr avatar Mar 30 '23 20:03 grrtrr