2022-04-06 07:09:48 +02:00
|
|
|
# Reproducible builds for Core Lightning
|
2020-09-08 19:27:20 +02:00
|
|
|
|
2022-04-06 07:09:48 +02:00
|
|
|
This document describes the steps involved to build Core Lightning in a
|
2020-09-08 19:27:20 +02:00
|
|
|
reproducible way. Reproducible builds close the final gap in the lifecycle of
|
|
|
|
open-source projects by allowing maintainers to verify and certify that a
|
|
|
|
given binary was indeed produced by compiling an unmodified version of the
|
|
|
|
publicly available source. In particular the maintainer certifies that the
|
|
|
|
binary corresponds a) to the exact version of the and b) that no malicious
|
|
|
|
changes have been applied before or after the compilation.
|
|
|
|
|
2022-04-06 07:09:48 +02:00
|
|
|
Core Lightning has provided a manifest of the binaries included in a release,
|
2020-09-08 19:27:20 +02:00
|
|
|
along with signatures from the maintainers since version 0.6.2.
|
|
|
|
|
|
|
|
The steps involved in creating reproducible builds are:
|
|
|
|
|
|
|
|
- Creation of a known environment in which to build the source code
|
|
|
|
- Removal of variance during the compilation (randomness, timestamps, etc)
|
|
|
|
- Packaging of binaries
|
|
|
|
- Creation of a manifest (`SHA256SUMS` file containing the crytographic
|
|
|
|
hashes of the binaries and packages)
|
|
|
|
- Signing of the manifest by maintainers and volunteers that have reproduced
|
|
|
|
the files in the manifest starting from the source.
|
|
|
|
|
|
|
|
The bulk of these operations is handled by the [`repro-build.sh`][script]
|
|
|
|
script, but some manual operations are required to setup the build
|
|
|
|
environment. Since a binary is built against platorm specific libraries we
|
|
|
|
also need to replicate the steps once for each OS distribution and
|
|
|
|
architecture, so the majority of this guide will describe how to set up those
|
|
|
|
starting from a minimal trusted base. This minimal trusted base in most cases
|
|
|
|
is the official installation medium from the OS provider.
|
|
|
|
|
|
|
|
Note: Since your signature certifies the integrity of the resulting binaries,
|
|
|
|
please familiarize youself with both the [`repro-build.sh`][script] script, as
|
|
|
|
well as with the setup instructions for the build environments before signing
|
|
|
|
anything.
|
|
|
|
|
|
|
|
[script]: https://github.com/ElementsProject/lightning/blob/master/tools/repro-build.sh
|
|
|
|
|
|
|
|
# Build Environment Setup
|
|
|
|
|
|
|
|
The build environments are a set of docker images that are created directly
|
|
|
|
from the installation mediums and repositories from the OS provider. The
|
|
|
|
following sections describe how to create those images. Don't worry, you only
|
|
|
|
have to create each image once and can then reuse the images for future
|
|
|
|
builds.
|
|
|
|
|
|
|
|
## Base image creation
|
|
|
|
|
|
|
|
Depending on the distribution that we want to build for the instructions to
|
|
|
|
create a base image can vary. In the following sections we discuss the
|
|
|
|
specific instructions for each distribution, whereas the instructions are
|
|
|
|
identical again once we have the base image.
|
|
|
|
|
|
|
|
### Debian / Ubuntu and derivative OSs
|
|
|
|
|
|
|
|
For operating systems derived from Debian we can use the `debootstrap` tool to
|
|
|
|
build a minimal OS image, that can then be transformed into a docker
|
|
|
|
image. The packages for the minimal OS image are directly downloaded from the
|
|
|
|
installation repositories operated by the OS provider.
|
|
|
|
|
|
|
|
We cannot really use the `debian` and `ubuntu` images from the docker hub,
|
|
|
|
mainly because it'd be yet another trusted third party, but it is also
|
|
|
|
complicated by the fact that the images have some of the packages updated. The
|
|
|
|
latter means that if we disable the `updates` and `security` repositories for
|
|
|
|
`apt` we find ourselves in a situation where we can't install any additional
|
|
|
|
packages (wrongly updated packages depending on the versions not available in
|
|
|
|
the non-updated repos).
|
|
|
|
|
2022-04-25 18:23:18 +02:00
|
|
|
The following table lists the codenames of distributions that we
|
|
|
|
currently support:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
| Distribution Version | Codename |
|
2022-07-21 14:50:53 +02:00
|
|
|
|:---------------------|:---------|
|
2020-09-08 19:27:20 +02:00
|
|
|
| Ubuntu 18.04 | bionic |
|
|
|
|
| Ubuntu 20.04 | focal |
|
2022-04-25 18:23:18 +02:00
|
|
|
| Ubuntu 22.04 | jammy |
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2022-04-25 18:23:18 +02:00
|
|
|
Depending on your host OS release you migh not have `debootstrap`
|
|
|
|
manifests for versions newer than your host OS. Due to this we run the
|
|
|
|
`debootstrap` commands in a container of the latest version itself:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
```bash
|
2022-04-25 18:23:18 +02:00
|
|
|
for v in bionic focal jammy; do
|
|
|
|
echo "Building base image for $v"
|
|
|
|
sudo docker run --rm -v $(pwd):/build ubuntu:22.04 \
|
|
|
|
bash -c "apt-get update && apt-get install -y debootstrap && debootstrap $v /build/$v"
|
|
|
|
sudo tar -C $v -c . | sudo docker import - $v
|
|
|
|
done
|
2020-09-08 19:27:20 +02:00
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Verify that the image corresponds to our expectation and is runnable:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
```bash
|
|
|
|
sudo docker run bionic cat /etc/lsb-release
|
|
|
|
```
|
|
|
|
Which should result in the following output for `bionic`:
|
|
|
|
|
|
|
|
```text
|
|
|
|
DISTRIB_ID=Ubuntu
|
|
|
|
DISTRIB_RELEASE=18.04
|
|
|
|
DISTRIB_CODENAME=bionic
|
|
|
|
DISTRIB_DESCRIPTION="Ubuntu 18.04 LTS"
|
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
## Builder image setup
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Once we have the clean base image we need to customize it to be able to build
|
2022-04-06 07:09:48 +02:00
|
|
|
Core Lightning. This includes disabling the update repositories, downloading the
|
2020-09-08 19:27:20 +02:00
|
|
|
build dependencies and specifying the steps required to perform the build.
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
For this purpose we have a number of Dockerfiles in the
|
|
|
|
[`contrib/reprobuild`][repro-dir] directory that have the specific
|
|
|
|
instructions for each base image.
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
We can then build the builder image by calling `docker build` and passing it
|
|
|
|
the `Dockerfile`:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
```bash
|
2022-07-21 14:50:53 +02:00
|
|
|
sudo docker build -t cl-repro-bionic - < contrib/reprobuild/Dockerfile.bionic
|
|
|
|
sudo docker build -t cl-repro-focal - < contrib/reprobuild/Dockerfile.focal
|
|
|
|
sudo docker build -t cl-repro-jammy - < contrib/reprobuild/Dockerfile.jammy
|
2020-09-08 19:27:20 +02:00
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Since we pass the `Dockerfile` through `stdin` the build command will not
|
|
|
|
create a context, i.e., the current directory is not passed to `docker` and
|
|
|
|
it'll be independent of the currently checked out version. This also means
|
|
|
|
that you will be able to reuse the docker image for future builds, and don't
|
|
|
|
have to repeat this dance every time. Verifying the `Dockerfile` therefore is
|
|
|
|
sufficient to ensure that the resulting `cl-repro-<codename>` image is
|
|
|
|
reproducible.
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
The dockerfiles assume that the base image has the codename as its image name.
|
2019-02-28 10:59:46 +01:00
|
|
|
|
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
[repro-dir]: https://github.com/ElementsProject/lightning/tree/master/contrib/reprobuild
|
2019-02-28 10:59:46 +01:00
|
|
|
|
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
# Building using the builder image
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Finally, after this rather lengthy setup we can perform the actual build. At
|
|
|
|
this point we have a container image that has been prepared to build
|
|
|
|
reproducibly. As you can see from the `Dockerfile` above we assume the source
|
|
|
|
git repository gets mounted as `/repo` in the docker container. The container
|
|
|
|
will clone the repository to an internal path, in order to keep the repository
|
|
|
|
clean, build the artifacts there, and then copy them back to
|
|
|
|
`/repo/release`. We can simply execute the following command inside the git
|
|
|
|
repository (remember to checkout the tag you are trying to build):
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
```bash
|
|
|
|
sudo docker run --rm -v $(pwd):/repo -ti cl-repro-bionic
|
2022-07-21 14:50:53 +02:00
|
|
|
sudo docker run --rm -v $(pwd):/repo -ti cl-repro-focal
|
|
|
|
sudo docker run --rm -v $(pwd):/repo -ti cl-repro-jammy
|
2019-02-28 10:59:46 +01:00
|
|
|
```
|
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
The last few lines of output also contain the `sha256sum` hashes of all
|
|
|
|
artifacts, so if you're just verifying the build those are the lines that are
|
|
|
|
of interest to you:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
```text
|
|
|
|
ee83cf4948228ab1f644dbd9d28541fd8ef7c453a3fec90462b08371a8686df8 /repo/release/clightning-v0.9.0rc1-Ubuntu-18.04.tar.xz
|
|
|
|
94bd77f400c332ac7571532c9f85b141a266941057e8fe1bfa04f054918d8c33 /repo/release/clightning-v0.9.0rc1.zip
|
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Repeat this step for each distribution and each architecture you wish to
|
|
|
|
sign. Once all the binaries are in the `release/` subdirectory we can sign the
|
|
|
|
hashes:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
# (Co-)Signing the release manifest
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
The release captain is in charge of creating the manifest, whereas
|
|
|
|
contributors and interested bystanders may contribute their signatures to
|
|
|
|
further increase trust in the binaries.
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
The release captain creates the manifest as follows:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
```bash
|
|
|
|
cd release/
|
|
|
|
sha256sum *v0.9.0* > SHA256SUMS
|
|
|
|
gpg -sb --armor SHA256SUMS
|
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Co-maintainers and contributors wishing to add their own signature verify that
|
|
|
|
the `SHA256SUMS` and `SHA256SUMS.asc` files created by the release captain
|
|
|
|
matches their binaries before also signing the manifest:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
```bash
|
|
|
|
cd release/
|
|
|
|
gpg --verify SHA256SUMS.asc
|
|
|
|
sha256sum -c SHA256SUMS
|
|
|
|
cat SHA256SUMS | gpg -sb --armor > SHA256SUMS.new
|
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Then send the resulting `SHA256SUMS.new` file to the release captain so it can
|
|
|
|
be merged with the other signatures into `SHASUMS.asc`.
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
# Verifying a reproducible build
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
You can verify the reproducible build in two ways:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
- Repeating the entire reproducible build, making sure from scratch that the
|
|
|
|
binaries match. Just follow the instructions above for this.
|
|
|
|
- Verifying that the downloaded binaries match match the hashes in
|
|
|
|
`SHA256SUMS` and that the signatures in `SHA256SUMS.asc` are valid.
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Assuming you have downloaded the binaries, the manifest and the signatures
|
|
|
|
into the same directory, you can verify the signatures with the following:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
```bash
|
|
|
|
gpg --verify SHA256SUMS.asc
|
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
And you should see a list of messages like the following:
|
|
|
|
|
|
|
|
```text
|
|
|
|
gpg: assuming signed data in 'SHA256SUMS'
|
|
|
|
gpg: Signature made Fr 08 Mai 2020 07:46:38 CEST
|
|
|
|
gpg: using RSA key 15EE8D6CAB0E7F0CF999BFCBD9200E6CD1ADB8F1
|
|
|
|
gpg: Good signature from "Rusty Russell <rusty@rustcorp.com.au>" [full]
|
|
|
|
gpg: Signature made Fr 08 Mai 2020 12:30:10 CEST
|
|
|
|
gpg: using RSA key B7C4BE81184FC203D52C35C51416D83DC4F0E86D
|
|
|
|
gpg: Good signature from "Christian Decker <decker.christian@gmail.com>" [ultimate]
|
|
|
|
gpg: Signature made Fr 08 Mai 2020 21:35:28 CEST
|
|
|
|
gpg: using RSA key 30DE693AE0DE9E37B3E7EB6BBFF0F67810C1EED1
|
|
|
|
gpg: Good signature from "Lisa Neigut <niftynei@gmail.com>" [full]
|
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
If there are any issues `gpg` will print `Bad signature`, it might be because
|
|
|
|
the signatures in `SHA256SUMS.asc` do not match the `SHA256SUMS` file, and
|
|
|
|
could be the result of a filename change. Do not continue using the binaries,
|
|
|
|
and contact the maintainers, if this is not the case, a failure here means
|
|
|
|
that the verification failed.
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Next we verify that the binaries match the ones in the manifest:
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
```bash
|
|
|
|
sha256sum -c SHA256SUMS
|
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Producing output similar to the following:
|
|
|
|
```
|
|
|
|
sha256sum: clightning-v0.9.0-Fedora-28-amd64.tar.gz: No such file or directory
|
|
|
|
clightning-v0.9.0-Fedora-28-amd64.tar.gz: FAILED open or read
|
|
|
|
clightning-v0.9.0-Ubuntu-18.04.tar.xz: OK
|
|
|
|
clightning-v0.9.0.zip: OK
|
|
|
|
sha256sum: WARNING: 1 listed file could not be read
|
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
Notice that the two files we downloaded are marked as `OK`, but we're missing
|
|
|
|
one file. If you didn't download that file this is to be expected, and is
|
|
|
|
nothing to worry about. A failure to verify the hash would give a warning like
|
|
|
|
the following:
|
|
|
|
|
|
|
|
```text
|
|
|
|
sha256sum: WARNING: 1 computed checksum did NOT match
|
|
|
|
```
|
2019-02-28 10:59:46 +01:00
|
|
|
|
2020-09-08 19:27:20 +02:00
|
|
|
If both the signature verification and the manifest checksum verification
|
|
|
|
succeeded, then you have just successfully verified a reproducible build and,
|
|
|
|
assuming you trust the maintainers, are good to install and use the
|
|
|
|
binaries. Congratulations! 🎉🥳
|