Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add creds to .netrc for codeartifact pip login. #8532

Open
1 of 2 tasks
hughack opened this issue Feb 9, 2024 · 2 comments
Open
1 of 2 tasks

Add creds to .netrc for codeartifact pip login. #8532

hughack opened this issue Feb 9, 2024 · 2 comments
Labels
codeartifact login customization Issues related to CLI customizations (located in /awscli/customizations) feature-request A feature should be added or improved. p3 This is a minor priority issue

Comments

@hughack
Copy link

hughack commented Feb 9, 2024

Describe the feature

Add the ability to have aws codeartifact login --tool pip ... write credentials to ~/.netrc. "Tool" could also be netrc or something.

Use Case

When using requirements.txt to define dependencies, I can't find a clean way to securely build a docker image with a private package repository in a way that is resilient by default against dependency confusion, and works across developer machines and builds.

The problem with writing to pip.conf is it sets the index outside of requirements.txt, which means someone can still run pip install -r requirements.txt without logging in to codeartifact, and if there are name collisions with a package in pypi then they will be installed.

We could add --index-url https://aws:${CODEARTIFACT_TOKEN}@... at the start of requirements.txt but this falls apart when building in docker, since that means setting an env var which can easily be accidentally built in to the container.

Proposed Solution

Add the ability to have aws codeartifact login --tool pip ... write credentials to ~/.netrc instead of pip.conf.

This allows us to force requirements.txt to use our codeartifact repo like this:

--index-url https://ai-pypi-12345678.d.codeartifact.us-east-1.amazonaws.com/pypi/my-pypi/simple/
boto3==...

Since pip honours creds in ~/.netrc it will fail to install anything unless that file exists and has correct creds.

Users and build tools can login using the cli.

Within a Dockerfile we can put:

RUN --mount=type=secret,id=netrc,target=/root/.netrc pip install -r requirements.txt

And build using:

docker buildx build --secret id=netrc,src=$HOME/.netrc .

Other Information

Someones blog post: https://zapata.ai/building-a-python-docker-image-using-private-pypi-repository/

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CLI version used

2.15.18

Environment details (OS name and version, etc.)

macos sonoma 14.0

@hughack hughack added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Feb 9, 2024
@couling
Copy link

couling commented Feb 27, 2024

This would be compatible with both pip and poetry

@tim-finnigan tim-finnigan self-assigned this May 7, 2024
@tim-finnigan tim-finnigan added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label May 7, 2024
@tim-finnigan
Copy link
Contributor

Thanks for the feature request. I'll share this with the CodeArtifact team, who owns and maintains this customization. In the meantime we can continue to track the request and gather feedback here.

@tim-finnigan tim-finnigan removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-triage This issue or PR still needs to be triaged. labels May 7, 2024
@tim-finnigan tim-finnigan removed their assignment May 7, 2024
@tim-finnigan tim-finnigan added codeartifact login customization Issues related to CLI customizations (located in /awscli/customizations) p3 This is a minor priority issue labels May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codeartifact login customization Issues related to CLI customizations (located in /awscli/customizations) feature-request A feature should be added or improved. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

3 participants