question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid exposing secrets on requirements.txt for --[extra-]index-url with credentials

See original GitHub issue

When running

pip-compile requirements.in --extra-index-url https://${PYPI_USERNAME}:${PYPI_PASSWORD}@gitlab.com/api/v4/projects/.../packages/pypi/simple

the resulting requirements is

#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --extra-index-url='https://[USERNAME]:****@gitlab.com/api/v4/projects/.../packages/pypi/simple' requirements_test.in
#
--extra-index-url https://[USERNAME]:[PASSWORD]@gitlab.com/api/v4/projects/.../packages/pypi/simple

...==0.2.7  # via -r requirements.in
numpy==1.19.1             # via ...
scipy==1.5.2              # via ...

where both [USERNAME] and [PASSWORD] are shown in plain text. Since the requirements.txt shall end in version control, specially with post-commit hooks, this exfiltrates secrets to the git repository.

Environment Versions

  1. OS Type: Mac
  2. Python version: Python 3.7.3
  3. pip version: pip 20.2.1
  4. pip-tools version: pip-compile, version 5.3.1

Steps to replicate

See above.

Expected result

The secrets should not be outputted to the compiled requirements.txt. Instead, they should keep their original names, as pip accepts.

In the example above, IMO we should only output

--extra-index-url https://${PYPI_USERNAME}:${PYPI_PASSWORD}@gitlab.com/api/v4/projects/.../packages/pypi/simple

both on the header and on the actual requirements. It is the responsibility of the deployment team to ensure that they have the credentials to download dependencies from a pypi server.

Actual result

The secrets are outputted to requirements.txt.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jorgecarleitaocommented, Aug 19, 2020

closing in favor of #966 .

0reactions
ericbncommented, Mar 24, 2021

The issue here is that the shell is expanding the environment variables, so pip-compile will get the --extra-index-url parameter value with the environment variables already expanded. A solution is to use single quotes, to prevent the shell from expanding them, like:

pip-compile requirements.in --extra-index-url 'https://${PYPI_USERNAME}:${PYPI_PASSWORD}@gitlab.com/api/v4/projects/.../packages/pypi/simple'

But that only works partially. See #1367.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Credentials in pip.conf for private PyPI - python - Stack Overflow
But here I see two problems: For each url you'll need each time to specify the same username and password. Username and password...
Read more >
pipenv Documentation - Read the Docs
Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the. Python...
Read more >
extra-index-url` to install private packages from GitLab CI
I have the following use case: My client develops a closed-source Python library, with dependencies specified in setup.py through setuptools ...
Read more >
Install custom Python Libraries from private PyPI on Databricks
In this blog post I'm going to explain how to integrate your private PyPI repositories on Databricks clusters step by step.
Read more >
Documentation for the Command-Line Interface (CLI) and ...
--extra-index-url=https://packagecloud.io/user/publicRepo/pypi/simple. private repos: Append the repository to requirements.txt using a read token.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found