Skip to content

Conversation

@jamescurtin
Copy link
Contributor

Make sure you have checked all steps below.

Prerequisite

Description

Fixes an issue where PYTHON_BUILD_MIRROR_URL is not used if the mirror does not have the same checksum that is expected. In some cases, the mirror is not expected to have a matching checksum (as in the case of a corporate mirror behind a firewall), which causes errors.

By setting PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM, the PYTHON_BUILD_MIRROR_URL will be used but will not attempt to match a checksum.

Tests

  • My PR adds the following unit tests (if any)
    • package is fetched from mirror when checksum is invalid if SKIP_CHECKSUM set

@jamescurtin
Copy link
Contributor Author

👋 Checking in on this PR: would someone please be able to review? Thank you!

@jamescurtin
Copy link
Contributor Author

Hi: wanted to check in again--would a maintainer be able to review this PR please? Thank you! (CC @joshfriend sorry for the ping 😄 )

@joshfriend
Copy link
Member

why would the download from a mirror have a different checksum?

@jamescurtin
Copy link
Contributor Author

The downloaded file will have the same checksum--the issue with the current implementation is the assumption that the checksum is always included in the filepath of the mirrored distribution. For example:

3.8.5 can be downloaded from https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz.

My PYTHON_BUILD_MIRROR_URL is https://mirror.example.com/python/, and the source distribution is available at https://mirror.example.com/python/3.8.5/Python-3.8.5.tar.xz.

Based on this logic in python-build, there is an assumption that the path to the mirrored distribution is https://mirror.example.com/python/e3003.../Python-3.8.5.tar.xz, where e3003... is the checksum of the file. This may be the case for some mirrors, but is not the case when configuring a remote repository mirror using Artifactory (as is my situation).

Therefore, the behavior introduced with PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM is to skip templating the checksum into the URL of the download. The verify_checksum function is still called when downloading the tarball from the mirror, so you remain protected against corrupted or poisoned distributions.

@joshfriend
Copy link
Member

Ah I understand now :) thank you ❤️

@joshfriend joshfriend merged commit 5d84eed into pyenv:master Oct 3, 2020
@uzxmx
Copy link

uzxmx commented Oct 13, 2020

Just want to add a comment:

Because of this code snippet, it actually tries downloading the tarball twice. The first time it tries downloading with the checksum appended, but fails. The second time without checksum, hence succeeds.

So I think the name PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM may not be a good name, because it doesn't skip, but actually substitutes the original url with PYTHON_BUILD_MIRROR_URL.

  if [ -n "$PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM" ]; then
      local package_url="$(echo "$1" | sed -e "s|.*//${URL_BASE:-$official_source}|$PYTHON_BUILD_MIRROR_URL|g")"
  else
      local package_url="$1"
  fi

In order to use the name PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM, maybe here is a good place to do some edits.

@lushi516
Copy link

The Alibaba Cloud image path does not comply with the official agreement

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.

PYTHON_BUILD_MIRROR_URL desn't take effect. Support for pull-through cache-mirror of python packages

4 participants