30491
Comment: replace jenkins.d.n with reproducible.debian.net where applicable
|
30754
Add python-setuptools to our custom toolchain
|
Deletions are marked like this. | Additions are marked like this. |
Line 380: | Line 380: |
== python-setuptools == DebianPts:python-setuptools needs a [[https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=python-setuptools_5.5.1-1_reproducible.diff;att=1;bug=773969 patch]] to write names `top_level.txt` in a stable order. See Bug:773969 |
It should be possible to reproduce, byte for byte, every build of every package in Debian.
This is an on-going project. To participate, we recommend you create an account on this wiki, subscribe to this page, and join the reproducible-builds@lists.alioth.debian.org mailing list. IRC channel is #debian-reproducible on OFTC.
Contents
- Why do we want reproducible builds?
- Status
- Useful things you (yes, you!) can do
- Reported bugs
- Lintian tags
- Archive wide rebuilds
- Reproducing builds
- Reproducible builds automated on jenkins.d.n
- The basics for making packages build reproducible
-
Identified problems, and possible solutions
- Files in data.tar.gz contains build paths
- Files in data.tar.gz depends on readdir order
- Files in data.tar.gz varies with the locale
- Files in data.tar.gz contains hostname, uname output, username
- Files in data.tar contains timestamps
- Symlinks in data.tar contain varying file mode
- Generation of files in data.tar depends on (pseudo-)randomness
- Members of control.tar and data.tar have varying mtimes
- {data,control}.tar.{gz,xz,bz2} will store files in readdir order
- Files generated by debhelper depend on readdir order
- Randomness in control file
- .deb ar-archive header contains a timestamp
- building the kernel
- XSLT generate-id() is non-deterministic
- PNG files contain timestamps
- Custom build environment
- Countering "trusting trust" issues by building Perl without Perl
- bash script to compare two package builds
- Further work
- References
- Presentations
- Publicity
- Related projects
Other resources:
Drivers:
- Lunar
- h01ger
Why do we want reproducible builds?
- Allow independent verifications that a binary matches what the source intended to produce.
Help Multi-Arch: same packages co-installation (as they need every matching file to be byte identical).
- Be able to generate debug symbols for packages which do not have a “debug package”.
- Ensure packages can be built from source. The archive could be made to only accept reproducible uploads: the maintainer would stop uploading .deb files but keep them referenced in the .changes. A buildd would then build the source. Only if the hash matches the upload gets accepted.
- Allow file-level deduplication on Debian mirror sites, or maybe snapshots.d.o, of .deb files whose contents didn't really change between versions.
- Allow .deb deltas to be smaller.
Packages with build profiles must offer the exact same functionality for all profiles. Reproducible builds could be use to verify that it is the case.
Making sure that Architecture:all packages are build identically on different build architectures.
Validate cross-builds against native builds.
Status
- Current focus in on the toolchain: trying to get as few changes as possibles in key packages to make as many builds as possible reproducible.
We have a custom toolchain that will allow a good amount of packages to be reproducible, as long as they use dh for their build process.
- We have a specification and a prototype implementation for recording the build environment.
- A build tool that would reproduce a build environment using packages from snapshot.debian.org is still missing.
Useful things you (yes, you!) can do
If you maintain a package for debian, you can make sure that your package uses a modern debhelper style (e.g. one-liner debian/rules with overrides as needed). We aim to fix many causes of non-deterministic builds in the debhelper suite directly, so packages that use debhelper will be much easier to make reproducible with just an upgrade of the toolchain.
Investigate ?failing packages from the latest experiment. Submit wishlist bugs with fixes for individual issues or find general solutions if needed.
Look at the last 24h of results from Jenkins reproducible jobs, pick a package, look at the debbindiff output and investigate.
- Find a way to prevent javadoc from writing timestamps.
- Find a way to prevent Epydoc from writing timestamps and output links in filesystem order.
- Understand why binaries produced by Mono are different.
Write a script to rebuild a package from a .buildinfo file. Probably wrapping or modifying sbuild or pbuilder.
Create a patch for pbuilder to build packages in /usr/src/debian/hello-2.8-1 instead of /tmp/buildd.
Research about other distributions: NixOS, SUSE (see build-compare), then write about it on your blog and link to it on this wiki page.
Write a more integrated dh_genbuildinfo helper for debhelper that would create a .buildinfo file (see below for the format). It should be be called after dh_builddeb and use dpkg-distaddfile to be included in the .changes. The current implementation remixes the output of dpkg-genchanges and dh-buildinfo. Good for experimenting, but not enough to be integrated upstream.
make the perl package build entirely without calling perl at all
If you want to help with this, feel free to ping the mailing list or edit this wiki page.
Reported bugs
All bugs relevant to the reproducible builds project should use usertags with user reproducible-builds@lists.alioth.debian.org.
Current usertags in use:
- toolchain
- affects a tool used by other package build systems
- infrastructure
- affects the whole Debian infrastructure or policies
- timestamps
- time of build in recorded during the build process
- fileordering
- build output varies with readdir() order
- buildpath
- path of sources is recorded during the build process
- username
- username is recorded during the build process
- hostname
- hostname is recorded during the build process
- uname
- uname output is recorded during the build process
- randomness
- some build aspects are dependent on (pseudo-)randomness
Control commands to update the view on the BTS.
Lintian tags
Here's a list of relevant Lintian tags:
Archive wide rebuilds
2013-09-07 by David Suárez. 24% of 5240 source packages reproducible. Variations: time, build path.
2014-01-26 by David Suárez. 67% of 6887 source packages reproducible. Variations: time, build path.
2014-09-19 by Lunar, 30% of 172 source core packages reproducible. Variations: time, file order.
Updated daily since 2014-09-28 by jenkins.debian.net. On 2014-11-11, 13213 (61.4%) out of 21448 packages are reproducible.
UDD query to get a list of core packages (172 as of 2014-09-19):
SELECT DISTINCT source FROM packages WHERE release = 'sid' AND section != 'debian-installer' AND ( essential = 'yes' OR build_essential = 'yes' OR priority IN ('required', 'important', 'standard') ) ORDER BY source;
Reproducing builds
There are two sides to the problem: first we need to record the initial build environment, and then we need a way to set up the same environment.
Recording the environment
Information on a build will be recorded in a new control file with extension `.buildinfo`.
Reproduce the build environment
Actions:
- We need a script that would take a list of binary packages and their respective version, installs them in a chroot and starts the build. Maybe based on pbuilder?
Ruby script that generates URL to .deb on snapshot.debian.org from a list of binary packages and their respective version: http://people.debian.org/~paulproteus/lunar-verify-script.rb
Here's another potential piece of the puzzle. The following script will convert a RFC822 date (as found in a .changes) to the URL of the last known archive state recorded by snapshot.debian.org. This might be useful to debootstrap the proper chroot before installing packages…
require 'date' require 'uri' require 'net/http' require 'nokogiri' changes_date = 'Mon, 30 Jan 2012 12:52:28 +0100' build_date = DateTime.rfc822(changes_date) url = "http://snapshot.debian.org/archive/debian/?year=#{build_date.year}&month=#{build_date.month}" response = Net::HTTP.get_response(URI.parse(url)) run = nil doc = Nokogiri::HTML(response.body) doc.css('p a').each do |link| date = DateTime.parse(link.content) break if date >= build_date run = link['href'] end puts "http://snapshot.debian.org/archive/debian/#{run}"
Note : it would probably be a lot better of adding a new query to the API interface of snapshot.d.o instead of parsing HTML.
Or you could use this shell one-liner:
echo -n "Input date: " &&\ read date &&\ ts=$(date -d "$date" -u +'%Y%m%dT%H%M%SZ') &&\ origurl="http://snapshot.debian.org/archive/debian/$ts/" &&\ echo "Use either $origurl" &&\ redirected=$(curl -s -L -I -o /dev/null -w '%{url_effective}' "$origurl") &&\ echo "or $redirected"
Reproducible builds automated on jenkins.d.n
Several jobs have been created to regularily test packages (from sid main) on jenkins.d.n. As a result there is the reproducible build overview of packages, which eventually will have results for all >21k sources packages in Debian.
The setup is explained in this blog post only, but this post is somewhat outdated by now and needs to be amended.
The basics for making packages build reproducible
Currently a plain sid environement is not enough to build packages reproducibly easily. Instead a few packages needs to be taken from the reproducible apt repository as explained above (at least debhelper >= 9.20141004~reproducible1 and dpkg >= 1.17.17~reproducible1 are needed). Besides this, these are the bascis for different types of packaging:
use dh with compat=9
use debhelper version 7 style packaging, add strip-nondeterminism to build-depends and make these modifications to debian/rules:
add dh_strip_nondeterminism before dh_compress
add dh_fixmtimes after dh_md5sums, right before dh_builddeb
add dh_genbuildinfo at the end of the dh_ sequence, so after dh_builddeb
use cdbs (needs cdbs >= 0.4.127~reproducible1)
Other types of packaging should be avoided and really be converted to dh.
With this, the basics should be covered and simple packages should build reproducible. See the next chapter for a discussion of common reproducibility issues and their solutions.
Identified problems, and possible solutions
Build systems tend to capture information about the environment that makes them produce different results accross different systems, despite having the same architecture and software installed.
Ideally, such variations should be fixed in the build system itself, but it might sometimes not be possible.
Files in data.tar.gz contains build paths
The build path is embedded in DWARF sections of ELF files among other types of file generated during builds. This has proven a real headache to fix after the path have been captured.
We are thus going to make mandatory to build package in a directory named like /usr/src/debian/hello-2.8-1.
As a bonus, this means that it will be easier to unpack packages in this canonical location for use with tools looking at the source code like gdb.
Files in data.tar.gz depends on readdir order
The build system needs to be patched to sort directory listings.
Epydoc
It looks like python-epydoc will produce links in an order that depends on the readdir order. This needs to be investigated.
Files in data.tar.gz varies with the locale
Builds should be made with LC_ALL=C.UTF-8.
It's quite unpractical to force such value in debian/rules and there is actually no reason this should not be the default.
Actions:
- We could make dpkg-buildpackage exports this variable; but we would need to change the policy to make dpkg-buildpackage be the canonical solution to build package.
Files in data.tar.gz contains hostname, uname output, username
We could write a LD_PRELOAD library that could answers consistent results for several system calls on the same model as libfaketime. Bdale suggested we call it liblietome.
But we can also consider that no build systems should capture or produce different builds depending on such information and fix them.
Files in data.tar contains timestamps
Recommended solutions in order of preference:
- Prevent the timestamp from being written entirely in the build products.
- Tell the tools to use the timestamp of “0” if the timestamp is not used.
Tell the tools to use the timestamp of the last debian/changelog entry.
- Strip timestamps at the end of the build process.
- Replace timestamps at the end of the build process.
Specific issues:
?Timestamps from C pre-processor macros
?Timestamps in PHP registry files
?Timestamp in generated documentation
?Timestamps in static libraries (.a files)
?Timestamps in documentation generated by Javadoc
?Timestamps in documentation generated by Doxygen
?Timestamps in PE binaries
?Timestamps in .dvi files generated by LaTeX
?Timestamps in .pdf files generated by LaTeX
?Timestamps in pom.properties files generated by Maven
Now fixed:
Symlinks in data.tar contain varying file mode
POSIX says that the file mode on symlinks is undefined, so this ends up being system dependent behavior. On Linux the umask is ignored when creating symlinks, but on other systems such as kFreeBSD or Hurd the umask is honored, which can produce varying file modes. This is at least a problem for architecture independent packages which are built on different operating systems.
A way to always get the same file mode for symlinks is to set umask to 0 before creating them, and restore the previous umask afterwards, but this might be unfeasible in general.
Generation of files in data.tar depends on (pseudo-)randomness
Now fixed:
Members of control.tar and data.tar have varying mtimes
dpkg-deb will record the mtime of files it packs in control.tar and data.tar. This is bad as most of these files are generated during the build process and will thus change with each build.
759886 contains a patch against debhelper that adds a new dh_fixmtimes helper that will ensure that the mtime of any file created after the date of latest changelog entry will be set to the date of the latest changelog entry.
{data,control}.tar.{gz,xz,bz2} will store files in readdir order
This is dependent on an accident of filesystem layout at build time, so it would sometimes not be reproducible.
We should probably fix this in dpkg by sorting the contents of the tar files.
Changes are discussed in 719845. Test case patch for pkg-tests. Patches that fork `sort` to get a stable order for files in control and data archives.
Files generated by debhelper depend on readdir order
At least the shlibs files generated by dh_makeshlibs depends on the order returned by find(1). There might be other debhelper programs with the same issue.
Randomness in control file
Now fixed:
.deb ar-archive header contains a timestamp
.deb are ar-archives. The header currently contains the “current time”.
759999 contains patches against dpkg that will preset the timestamp to the time of the latest entry of debian/changelog when a package is built using dpkg-buildpackage.
building the kernel
Uncoordinated experiments, see SameKernel.
XSLT generate-id() is non-deterministic
XSLT's generate-id() function is explicitly allowed by the XSLT spec to be non-deterministic, and is frequently implemented using memory addresses of XML nodes, which are of course non-deterministic thanks to ASLR. Consequentially, files that are generated by XSLT (typically documentation) that include the result of generate-id() in their output do not build deterministically.
piuparts, which uses xmlto to generate documentation, is affected by this.
PNG files contain timestamps
If the PNG is being generated by ?ImageMagick, some options can be passed to convert to inhibit inclusion of the timestamps. Please note that the options have to be passed just before the output filename and composite only supports the time chunk removal, for example:
convert -scale 32x32 input.png +set date:create +set date:modify -define png:exclude-chunk=time output.png composite -compose CopyOpacity mask.png input.png -define png:exclude-chunk=time output.png
Custom build environment
We maintain a set of modifications to the toolchain to perform our experiments. Commit notifications are sent to a dedicated mailing list.
Our modified packages can be found in the following APT archive, which is signed by 49B6 5747 36D0 B637 CC37 01EA 5DB7 CA67 EA59 A31F:
deb http://reproducible.alioth.debian.org/debian/ ./ deb-src http://reproducible.alioth.debian.org/debian/ ./
debhelper
The pu/reproducible_builds debhelper branch in the reproducible project contains:
dh_fixmtimes: an helper helper that will make the mtimes of control.tar and data.tar deterministic. It will be run by dh before building the .deb.
dh_strip_nondeterminism (see below) will be called before dh_installdeb in dh.
dh_genbuildinfo: an helper to generate .buildinfo control files as described above.
dpkg
The pu/reproducible_builds dpkg branch in the reproducible repository makes:
- file order deterministic in control and data part of the .deb,
- uses a single timestamp for .deb ar members
- preset the aforementioned timestamp to the latest changelog entry
add -Wdate-time as part of CPPFLAGS in dpkg-buildflags
strip-nondeterminism
strip-nondeterminism is a post-processing tool that will normalize various file types. dh_strip_nondeterminism will be run by debhelper at the end of the build process.
cdbs
The pu/reproducible_builds cdbs branch in the reproducible project contains a fix for 764478 which makes cdbs call the newly introduced dh_ commands from debhelper (see debhelper paragraph above for their description)
dh_fixmtimes
dh_strip_nondeterminism
dh_genbuildinfo
javatools
The pu/reproducible_builds javatools branch in the reproducible repository changes javahelper to call jh_installlibs after dh_install. See 764988.
discount
discount needs a patch to produce stable output of email addresses. See 762622 and the pu/reproducible_builds branch.
ghc
The pu/reproducible_builds ghc branch in the reproducible repository changes ghc to not include timestamps in interface hashes. See 769893
python-setuptools
python-setuptools needs a https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=python-setuptools_5.5.1-1_reproducible.diff;att=1;bug=773969 patch to write names top_level.txt in a stable order. See 773969
Usage example
If you have a pbuilder already setup, it's fairly easy to setup an environment with the custom toolchain:
sudo cp /var/cache/pbuilder/base.tgz /var/cache/pbuilder/base-reproducible.tgz sudo pbuilder --login --save-after-exec --basetgz /var/cache/pbuilder/base-reproducible.tgz echo 'deb http://reproducible.alioth.debian.org/debian/ ./' > /etc/apt/sources.list.d/reproducible.list apt-get update apt-get install dpkg dpkg-dev debhelper discount exit 0
Once that's done, rebuilding a package can be done through:
apt-get source --download-only acl sudo DEB_BUILD_OPTIONS=nocheck pbuilder --build --debbuildopts '-b' --basetgz /var/cache/pbuilder/base-reproducible.tgz acl_*.dsc mkdir b1 b2 dcmd cp /var/cache/pbuilder/result/acl_*.changes b1 sudo dcmd rm /var/cache/pbuilder/result/acl_*.changes sudo DEB_BUILD_OPTIONS=nocheck pbuilder --build --debbuildopts '-b' --basetgz /var/cache/pbuilder/base-reproducible.tgz acl_*.dsc dcmd cp /var/cache/pbuilder/result/acl_*.changes b2 sudo dcmd rm /var/cache/pbuilder/result/acl_*.changes
debbindiff (available in Debian main) is useful to check the result:
debbindiff --html $output_file b1/*.changes b2/*.changes
Adding a package to the APT archive
On alioth.debian.org:
Import the private signing key to your keyring, if you haven't already: gpg --import /home/groups/reproducible/private/reproducible-private.gpg
Place the package files in /home/groups/reproducible/htdocs/debian/
Run make from that directory.
Countering "trusting trust" issues by building Perl without Perl
Ken Thompson's classic "trusting trust" essay outlines an attack vector for embedding code in a compiler that will then be automatically added to anything that the compiler compiles. Since the main approach for making reproducible builds, using debhelper tools written in Perl, relies heavily on Perl, Debian's Perl package should be reproducibly buildable without any Perl at all. That will ensure the "trusting trust" cycle is broken. The current Perl packaging does not use debhelper, so that's a good start. Also, it looks like the Perl build system is written in make.
bash script to compare two package builds
Usage: ./diffp r1/hello_2.8-4_amd64.changes r2/hello_2.8-4_amd64
The script is available in the misc.git repository.
Further work
Having reproducible builds allows us to trust binary packages better, because it becomes easier to have:
- diversity of buildd location and jurisdiction - build packages in more than one location, including the developer's
- diversity of buildd hardware, in case of hardware bugs, or malicious implants - a mix of VMs, some real hardware, different CPU manufacturers, different date of manufacture and supplier
- diversity of people - multiple signatures on a .changes file
- diversity of kernels, explained below
Kernel packages
Special features of kernel packages (including bootloaders and hypervisors) - GRUB2, Xen, linux, kfreebsd...
- we put huge trust in them - kernels are the ultimate target of any rootkit, able to completely hide from userland
- a kernel image built for amd64, if the build system is portable and reproducible enough, will be the same whether built from linux-amd64 or kfreebsd-amd64
- or maybe from different kernel versions - for example, a jessie build chroot on a wheezy host system
Then we would be better protected from something that could affect many systems at once, such as a kernel vulnerability; or widespread infection by a rootkit, which now must be compatible with more than one type of kernel to go unnoticed.
References
Mike Perry's discussion of how it took him eight weeks to make the Tor Browser Bundle have this feature: http://people.debian.org/~paulproteus/mike-perry-reproducible-tbb.txt
- Deterministic virtual machines:
"ReVirt: Enabling Intrusion Analysis through Virtual-Machine Logging and Replay" http://web.eecs.umich.edu/virtual/papers/dunlap02.pdf
"Debugging operating systems with time-traveling virtual machines" http://web.eecs.umich.edu/virtual/papers/king05_1.pdf
"A Particular Bug Trap: Execution Replay Using Virtual Machines" http://arxiv.org/pdf/cs.DC/0310030
"ReTrace: Collecting Execution Trace with Virtual Machine Deterministic Replay" http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.84.5732
"Execution Replay for Multiprocessor Virtual Machines" http://www.eecs.umich.edu/~pmchen/papers/dunlap08.slides.ppt
Reflections on Trusting Trust, by Ken Thompson
Fully Countering Trusting Trust through Diverse Double-Compiling (DDC) - a PhD dissertation on how to use reproducible builds to counter the "trusting trust" attack on compilers
Is that really the source code for this software? by Jos van den Oever on blogs.kde.org (2013-06-19). Compare reproducing tar from the Debian, Fedora and OpenSUSE packages.
Deterministic Builds Part One: Cyberwar and Global Compromise by Mike Perry
Deterministic Builds Part Two: Technical Details by Mike Perry
Colin Watson's answer on ubuntu-devel to “Will Ubuntu use "reproducible builds" as debian is planning to do?”
Why and How of Reproducible Builds: Distrusting Our Own Infrastructure for Safer Software Releases, Seth Schoen and Mike Perry at Mozilla San Francisco, 2014-11-05
- Misc. upstream discussions:
Octave: bug report and mailing list thread
groff: mailing list thread
GHC (Glasgow Haskell Compiler): #4012
Presentations
Reproducible Builds for Debian, Distributions devroom, FOSDEM’14, Video, Slides (Sources)
Reproducible Builds, a year later, DebConf14, Video, Slides (Sources)
Publicity
This section lists URLs, people, and dates for when other people have publicly expressed interest, or shared information about, the project.
Mike Perry, 2013-08-20: Deterministic Builds Part One: Cyberwar and Global Compromise
Jake Edge, 2013-08-21: Security software verifiability
Holger Levsen, 2014-09-26: Reproducible builds? I never did any - manually
Related projects
CARE monitors the execution of the specified command to create an archive that contains all the material required to re-execute it in the same context.