awslabs / amazon-ecr-credential-helper

Automatically gets credentials for Amazon ECR on docker push/docker pull
Apache License 2.0
2.45k stars 335 forks source link

Error parsing credentials process contained within quotes in Windows #801

Open chaychoong opened 2 months ago

chaychoong commented 2 months ago

According to the documentation here, I should be able to do the following

credential_process = "C:\Path\To\credentials.cmd" parameterWithoutSpaces "parameter with spaces"

However, when I am using the following, it does not work:

[default]
credential_process = "C:\Program Files\aws_signing_helper\aws_signing_helper.exe" <params>

Using Process Monitor, we can see that the arguments are not being passed into the process. To reproduce this, set up the following dummy ~/.aws/config:

[default]
credential_process = "C:\Program Files\aws_signing_helper\aws_signing_helper.exe" test

Open up Process Monitor, filter by Process Name contains aws_signing_helper and Operation contains Process Start, then run docker pull, you should see the following:

CleanShot 2024-05-02 at 12 14 15@2x

Modify the ~/.aws/config to contain this:

[default]
credential_process = aws_signing_helper test

Make sure aws_signing_helper is in PATH, of course. Run docker pull again and you should see the following

CleanShot 2024-05-02 at 12 16 02@2x

Relevant info: aws_signing_helper version: 1.1.1

austinvazquez commented 2 months ago

Hi @chaychoong, thanks for reporting the issue and including so much detail. Initial triage leads me to believe this is a software bug introduced with the AWS Go SDK the credential helper uses for parsing the AWS CLI configuration. Can you share the Amazon ECR credential helper version you used when you experienced the issue?

austinvazquez commented 2 months ago

Initial triage

Docker is configured to fetch credentials via Amazon ECR credential helper. Users can configure credential helper via AWS CLI configuration to fetch credentials via an external process. The credential helper uses the AWS SDK Go V2 for parsing the AWS CLI configuration and providing credentials.

Docker -> Amazon ECR Credential Helper -> External Process (via .aws/config)

The issue occurs when the external process is quoted for encapsulating a file path or parameter with spaces: From AWS CLI v2 user guide:

  • If the path or file name contains a space, surround the complete path and file name with double-quotation marks (" "). The path and file name can consist of only the characters: A-Z a-z 0-9 - _ . space
  • If a parameter name or a parameter value contains a space, surround that element with double-quotation marks (" "). Surround only the name or value, not the pair.