gimme-aws-creds icon indicating copy to clipboard operation
gimme-aws-creds copied to clipboard

When ~/.aws/credentials is a directory gimme-aws-creds fails

Open DavideDaniel opened this issue 5 years ago • 2 comments

Unsure what set the directory (possibly preconfigured machine from IT) but running gimme-aws-creds was getting an error that could be handled gracefully or with a clearer message.

Expected Behavior

gimme-aws-creds should write creds when the option is set to true in the configuration

Current Behavior

Currently if the user has an existing ~/.aws/credentials and it's a directory the following error is thrown:

Traceback (most recent call last):
  File "/usr/local/bin/gimme-aws-creds.py", line 17, in <module>
    GimmeAWSCreds().run()
  File "/usr/local/lib/python3.7/site-packages/gimme_aws_creds/main.py", line 494, in run
    aws_creds['SessionToken']
  File "/usr/local/lib/python3.7/site-packages/gimme_aws_creds/main.py", line 111, in _write_aws_creds
    with open(self.AWS_CONFIG, 'w+') as configfile:
IsADirectoryError: [Errno 21] Is a directory: '/Users/{USER}/.aws/credentials'

Possible Solution

When writing creds to the credentials path, the _write_aws_creds in main.py should be able to inform you that credentials is a directory, prompt you to confirm deletion if it's not empty, delete it if it is empty and write the expected credential file.

Steps to Reproduce (for bugs)

  1. Configure gimme-aws-creds with write option as true
  2. Create a directory at ~/.aws/credentials
  3. Run gimme-aws-creds command.

Context

Following the instructions from github and company's confluence I had to remember that aws credentials is supposed to be a file not a directory and while the trace was helpful it wasn't clear why the problem wasn't handled if the tools expect a file.

Your Environment

  • App Version used: [email protected]
  • Environment name and version: This happens with both the docker image and installing via pip3/python3
  • Operating System and version: Mac OS Mojave 10.14.6

DavideDaniel avatar Aug 29 '19 06:08 DavideDaniel

i've had a similar issue. testing to see what gimme-aws-creds would do if there wasn't a credentials file present and write_aws_creds = True, ~/.aws/credentials was generated as a directory and then I received the same traceback error as above.

i have a shell wrapper around the gimme-aws-creds container so i just stuck some file/directory detection and handling in the wrapper as a workaround but I was curious about why ~/.aws/credentials was being generated as a directory if no credentials file was present.

jbhasemeier avatar Jul 23 '20 14:07 jbhasemeier

I get the same error, but this time, /home/USER/.aws/credentials file exists, but is still mounted as a directory inside the gimme-aws-creds container.

I run this with WSL2. I looked at the overlay2 volume data from docker-desktop-data and the credentials file is indeed a folder inside the container.

I use an alias to start the container: alias gimme-aws-creds=docker run -it --rm -v /home/USERNAME/.aws/credentials:/root/.aws/credentials -v /home/USERNAME/.okta_aws_login_config:/root/.okta_aws_login_config gimme-aws-creds

EDIT:

By default in WSL2, /home/.aws is a symlink to /mnt/c/Users/USERNAME/.aws. I removed that symlink and created a local /home/USERNAME/.aws folder directly in my WSL2 filesystem (OpenSuse Tumbleweed). This did not fix the problem.

nlaplante avatar Mar 30 '22 14:03 nlaplante