构建可重复 wheels 的工具。
项目描述
Amrasaman
这是一个为您的Python项目或所有依赖项构建可重复 wheels 的工具。也就是说,如果您使用相同的操作系统版本和类似系统级别依赖项,您将始终得到相同的 wheel。这样我们可以更好地保护免受侧信道攻击。任何 wheel 的用户都可以通过验证构建来验证他们是否使用了从确切源的正确构建。
为什么我们需要可重复的 wheel?
一些不同的积极点
- 如果我们从已知源(通过 requirements 文件中的固定散列)构建 wheel,我们还可以验证我们是否正在使用从它们构建的正确 wheel。
- 任何用户/开发者都可以从固定源重新构建 wheel,并应该得到相同的 wheel 作为输出。因此,如果构建过程中(例如在 CI 中)有任何东西被引入,或者 wheel 实际上是来自不同的源,自动化工具可以识别这些。
如何安装?
python3 -m pip install amrasaman
如何构建可重复 wheels?
asaman --help
Usage: asaman [OPTIONS]
Tool to build reproducible wheels.
Options:
-s, --source FILE A single source tarball or zip file.
-d, --directory DIRECTORY A directory containing all source tarballs and
zips.
-o, --output DIRECTORY The output directory to store all wheel files.
Default: ./wheels
-r, --requirement FILE Path to the requirement.txt file which contains
all packages to build along with hashes.
--sde TEXT Custom SOURCE_DATE_EPOCH value.
--help Show this message and exit.
为给定的源 tar 文件构建可重复的 wheel。
asaman -s dist/yourpackage_4.2.0.tar.gz
默认情况下,新鲜构建的 wheel 将存储在 ./wheels/
目录中,您可以使用 -o
或 --output
选项选择任何目录。
为目录中的所有源构建可重复的 wheels。
asaman -d path/to/sources/
或者,您可以指向包含所有依赖项及其散列的 requirements 文件。
asaman -r requirements.txt
如何从可重复 wheels 生成带散列的 requirements 文件?
asaman-generate requirements.txt
使用 asaman-generate
命令可以帮助您创建一个新的 verified-requirements.txt
,其中将包含可重复 wheels 的散列。您可以使用 -o/--output
选项传递您自定义的文件名。
asaman-generate --help
Usage: asaman-generate [OPTIONS] REQUIREMENT
Tool to build verified requirements file from reproducible wheels.
Options:
-o, --output FILE The output file. Default: verified-{requirement}.txt
-w, --wheels DIRECTORY The directory with reproducible wheels.
-s, --skip TEXT The packages we don't want in our final requirement
file.
--help Show this message and exit.
如何从 PyPI 或您的个人索引创建带散列的 requirements 文件?
使用 pip-tools 项目。
pip-compile --generate-hashes --allow-unsafe --output-file=requirements.txt requirements.in
请确保记录下任何给定 dependency
的所有构建依赖项,否则在构建过程中,pip
将从 PyPI 下载并安装它们到构建环境中。如果您从 requirements 文件构建,在下载和提取每个源 tar 文件时,您会发现依赖项是否有构建时间依赖项。否则,您可以手动查看构建时间依赖项。
例如,在以下文本中,您可以找到一些具有构建时间依赖项的软件包。查看带有 获取构建 wheel 的需求 的行。
Collecting build==0.7.0
Using cached build-0.7.0.tar.gz (15 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Collecting click==8.0.1
Using cached click-8.0.1.tar.gz (327 kB)
Collecting packaging==21.0
Using cached packaging-21.0.tar.gz (83 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Collecting pep517==0.11.0
Using cached pep517-0.11.0.tar.gz (25 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
初始化构建环境
对于任何生产使用,您还应初始化构建环境,并创建初始虚拟环境,在该环境中仅构建所有依赖项。您可以将 wheel 存储在您想要的任何位置(S3 或 git-lfs),并在下一次创建环境时从这里开始。
在以下命令中,我们将为在 bootstrap.in
中提到的构建需求创建一组 wheel,用于初始化环境。
amrasaman >=0.1.0
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install pip-tools # This is coming directly from pypi
pip-compile --generate-hashes --allow-unsafe --output-file=bootstrap.txt bootstrap.in
asaman -r bootstrap.txt
这将创建 ./wheels
目录中的所有 wheel。从现在开始,可以从 ./wheels
目录中安装它们。
但是,首先我们将创建一个新的 requirements 文件,其中只包含我们可重复 wheel 的哈希值,输出文件名为 verified-bootstrap.txt
。
asaman-generate bootstrap.txt
现在我们可以使用此文件来创建环境。
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --no-index --find-links ./wheels --require-hashes --only-binary :all: -r verified-bootstrap.txt
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源分布
构建分布
amrasaman-0.1.5.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 1aaa97aa09b84de0fa5a5d9ebecf37929fd8dd676f939b21d87c715ce694290a |
|
MD5 | d186874f60d94144da89b4199aa14f62 |
|
BLAKE2b-256 | 615303bb37655b31b8935802da6be5db790cfd726d148959ca25ced552b4c005 |
amrasaman-0.1.5-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 9dd853e59db1c9d0c1dfa523da2e568b5863fd61c990adb447c6ef8daf42fc1b |
|
MD5 | 8fd40c82fce27de9d6e0ecc09cee74ff |
|
BLAKE2b-256 | 46731e2e881a25e3c4f3f9ec804bfd4df8848e2f30d4f3e0cd57e2e355f271ae |