aws / aws/aws-cli

Cannot use non-default `.aws` location for non-existing user (in Docker)

Open
#7,953 4 comments 0 reactions 0 assignees View on GitHub
configuration docker feature-request needs-discussion p3
Dominant language
Python
Stars
17.3k
Forks
4.6k
Avg merge
1d 2h
Merged PRs (30d)
13

Description

### Describe the bug

When using a docker container (with aws) installed + mounting `~/.aws` into it + using Docker's `--user` argument + using a non-default profile for `aws`, the tool doesn't find the profile.

### Expected Behavior

If finds the profile.

### Current Behavior

The profile is not found.

### Reproduction Steps

Using this Dockerfile

```
cat Dockerfile
FROM ubuntu:20.04

RUN apt-get update \
&& apt-get install -y curl unzip less

RUN curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm -rf aws awscliv2.zip

WORKDIR /home
CMD ["bash"]
```

```bash
IMAGE=7218476461d5 # built locally

# Okay
docker run -it --rm --mount "type=bind,source=$HOME/.aws,target=/aws,readonly" --env AWS_CONFIG_FILE=/aws/config --env AWS_SHARED_CREDENTIALS_FILE=/aws/credentials --env AWS_PROFILE= $IMAGE aws sts get-caller-identity
Enter MFA code for arn:aws:iam::************:mfa/****: # entering MFA now
{
"UserId": "****************************************************",
"Account": "****************",
"Arn": "arn:aws:sts::****************:assumed-role//botocore-session-1686051084"
}

# Not okay (with --user)
docker run -it --rm --mount "type=bind,source=$HOME/.aws,target=/aws,readonly" --env AWS_CONFIG_FILE=/aws/config --env AWS_SHARED_CREDENTIALS_FILE=/aws/credentials --env AWS_PROFILE= --user 1234:5678 $IMAGE aws sts get-caller-identity

The config profile () could not be found
```

### Possible Solution

I've seen in my actual scenario (i.e. not the SSCCE) a boto3 error about not being able to load `/.aws` which seems like `$HOME/.aws` if `HOME` is not set. So this looks to me as if `aws`/`boto3` tries to access the default location where it shouldn't.

### Additional Information/Context

_No response_

### CLI version used

aws-cli/2.11.25 Python/3.11.3 Linux/5.14.21-150400.24.63-default exe/x86_64.ubuntu.20 prompt/off

### Environment details (OS name and version, etc.)

Linux

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.