aws / aws/aws-cli

Output of `configure export-credentials --format env` ends with `\r`

Open
#8,187 9 comments 0 reactions 0 assignees View on GitHub
bug credential-provider p2
Dominant language
Python
Stars
17.3k
Forks
4.6k
Avg merge
1d 10h
Merged PRs (30d)
18

Description

### Describe the bug

The output of `configure export-credentials --format env` seems to end with `\r`.

Therefore, `$(command)` will not set the environment variable correctly, and then the error `unhandled exception: Invalid header value` will occur at the request with authentication.

### Expected Behavior

The environment variables are set correctly by doing the following:
```sh
$(aws configure export-credentials --format env)
```
or
```sh
`aws configure export-credentials --format env`
```

### Current Behavior

Error occurs when running commands that require authentication.
```console
$ aws s3 ls

An HTTP Client raised an unhandled exception: Invalid header value b'(...long base64 token...)\r'
^^^
```

### Reproduction Steps

1. Specify profile

```console
$ export AWS_PROFILE=
```

2. Set env vars

```console
$ $(aws configure export-credentials --format env)
```

3. Run commands that require authentication

```console
$ aws s3 ls
```

### Possible Solution

Currently, I work around it by assigning it to a temporary variable once and removing `\r`.
```console
$ _EXPORTS=$(aws configure export-credentials --format env); ${_EXPORTS//$'\r'/}
```

However, if the output were quoted, or if it did not end with `\r`, this issue would not occur.
* As is
```console
$ aws configure export-credentials --format env
export AWS_ACCESS_KEY_ID=(Access Key ID)
export AWS_SECRET_ACCESS_KEY=(Secret Access Key)
export AWS_SESSION_TOKEN=(Session Token)
...
```
* To be
```console
$ aws configure export-credentials --format env
export AWS_ACCESS_KEY_ID="(Access Key ID)"
export AWS_SECRET_ACCESS_KEY="(Secret Access Key)"
export AWS_SESSION_TOKEN="(Session Token)"
...
```

### Additional Information/Context

_No response_

### CLI version used

aws-cli/2.13.19 Python/3.11.5 Windows/10 exe/AMD64 prompt/off

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

Windows 10, Git for Windows version 2.42.0.windows.2

Contributor guide

Open the contributing guide

Research direction

Start by locating the implementation of `configure export-credentials --format env` and reproduce the command in Windows Git Bash using the reported profile and `aws s3 ls` steps. Done means the generated environment assignments no longer include the trailing `\r`, and authentication-dependent commands work correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, shell
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.