Skip to content

Use credentials of pyproject sources when downloading artifacts - #11287

Open
jay23606 wants to merge 4 commits into
python-poetry:mainfrom
jay23606:pr-go-simple/10419
Open

jay23606 wants to merge 4 commits into
python-poetry:mainfrom
jay23606:pr-go-simple/10419

Conversation

@jay23606

Copy link
Copy Markdown

What changed

The installer's Executor creates its own Authenticator for downloading artifacts, but it only knows about repositories defined in the repositories config section. Sources declared in pyproject.toml ([[tool.poetry.source]], added via poetry source add) are registered only on each repository's private authenticator, which is used for metadata requests. As a result, metadata requests carry credentials (e.g. POETRY_HTTP_BASIC_<NAME>_*) while wheel/sdist downloads from the same host are sent without them, and private indexes such as AWS CodeArtifact return 401 for artifacts.

The fix registers every LegacyRepository from pool.all_repositories with the executor's authenticator. LegacyRepository is used so PyPI credential handling is unchanged.

Tests

Added test_executor_uses_credentials_of_pool_repositories_for_downloads in tests/installation/test_executor.py, which checks that the executor resolves configured credentials for a file URL under a pool source.

Not run here: the test suite was not executed in this environment (dependencies must not be installed here). Only a stdlib py_compile syntax check was run on the two changed files.

Tests not run here: pytest tests/installation/test_executor.py -k test_executor_uses_credentials_of_pool_repositories_for_downloads (not run: dependencies must not be installed in this environment; CI runs the tests), pytest tests/installation tests/utils/test_authenticator.py (not run: same reason)

Fixes #10419

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
@jay23606
jay23606 marked this pull request as ready for review November 26, 2026 17:53
@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit e107ab9

#10419 Can't use my private CodeArtifact repo as PyPI proxy (401) · 1 of 1 met

# Requirement Status Notes
1 Use the private source's credentials when downloading package artifacts. ✅ Met For packages originating from a legacy source, the executor selects that repository's authenticator for archive downloads.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/poetry/installation/executor.py" line_range="105" />
<code_context>
+        # this one does not).
+        for repository in pool.all_repositories:
+            if isinstance(repository, LegacyRepository):
+                self._authenticator.add_repository(repository.name, repository.url)
         self._chef = Chef(self._artifact_cache, self._env, pool)
         self._chooser = Chooser(pool, self._env, config)
</code_context>
<issue_to_address>
**Downloads use wrong credentials**

When two legacy sources on the same host use different credentials and artifact URLs tie on path match, `get_repository_config_for_url` selects the first source on the path-match tie, so `Downloader` sends that source’s credentials for the other source’s artifact and the download fails with an authorization error.

Select credentials using the artifact’s originating repository rather than resolving them solely from the tied artifact URL path.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and registering each legacy source URL lets the authenticator attach that source’s configured HTTP Basic credentials to matching artifact downloads. If a URL is matched too broadly or points somewhere unintended, the credentials may be disclosed; reverting stops future sends but cannot recall credentials already exposed.

Blocking findings: src/poetry/installation/executor.py:105


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/poetry/installation/executor.py Resolved
Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com>
@jay23606
jay23606 marked this pull request as draft November 29, 2026 13:55
Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com>
Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com>
@jay23606
jay23606 marked this pull request as ready for review November 29, 2026 15:56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't use my private CodeArtifact repo as PyPI proxy (401)

1 participant