Interview Prep/Python for DevOps/Environments, dependencies & packaging

How do you install dependencies from a private index safely?

AdvancedConceptEnvironments, dependencies & packaging
Answer

Use --index-url to point at the private index (which proxies PyPI), not --extra-index-url. With extra indexes pip picks the highest version across all indexes, so an attacker can publish acme-utils 99.0 on public PyPI and win (dependency confusion). Also:

  • Pin and hash (--require-hashes).
  • Keep credentials out of URLs in files: use keyring, PIP_INDEX_URL from a secret, or aws codeartifact login --tool pip.
  • Reserve your internal names on PyPI.
All Python for DevOps questions Roadmap: Python for automation

More on Environments, dependencies & packaging