Skip to content

Lesson 8 of 9 · 22m

Private Indexes and Supply-Chain Controls

How to run or consume a private package index without creating dependency-confusion holes.

The moment a company publishes internal packages, package resolution becomes a security boundary. The catastrophic pattern is dependency confusion: pip is configured to consult both a private index and public PyPI, and an attacker publishes your internal package name publicly with a higher version.

Understand the resolution order problem

pip's --extra-index-url does not mean "use this as a fallback." Indexes are combined, and the resolver chooses the best version across all of them.

pip install internal-auth   --index-url https://packages.acme.internal/simple   --extra-index-url https://pypi.org/simple

If internal-auth exists publicly at version 999.0.0, pip may install the attacker's package. The configuration looks redundant and harmless. It isn't.

Safer patterns

  1. Use a proxy or repository manager that namespaces or controls upstream caching.
  2. Publish internal names that cannot realistically be squatted, and register defensive names where appropriate.
  3. Use explicit index configuration per environment and avoid mixing public and private indexes for internal names.
  4. Pin and hash production dependencies.
  5. Audit newly seen dependencies in CI.

Repository managers such as devpi, Artifactory, Nexus, or cloud artifact registries can expose one internal endpoint and proxy PyPI through governed caching rules.

Verify what the client is actually doing

pip config debug
python -m pip install internal-auth --dry-run --report /tmp/report.json

The JSON report tells you exactly which candidates and URLs pip considered. This is far more useful than guessing based on shell aliases or a half-remembered pip.conf.

Metadata is also supply-chain data

Check maintainers, project URLs, release cadence, and artifact history. A sudden maintainer change or a release published years after inactivity deserves scrutiny. Pinning protects known-good versions, but it doesn't decide which versions deserve trust.

Field notes

  • --index-url replaces the default; --extra-index-url adds another source. Know which one you typed.
  • Public squatting is easier when internal names are generic. Prefix organization-specific packages consistently.
  • Do not put credentials in URLs committed to git; use environment-specific secret injection.
  • Dependency review in CI should flag new direct dependencies, not only vulnerable versions.

Was this lesson helpful?

Sign in to rate