You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long. 8.7KB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. # Gitian
  2. Read about the project goals at the [project home page](
  3. This package can do a deterministic build of a package inside a VM.
  4. ## Deterministic build inside a VM
  5. This performs a build inside a VM, with deterministic inputs and outputs. If the build script takes care of all sources of non-determinism (mostly caused by timestamps), the result will always be the same. This allows multiple independent verifiers to sign a binary with the assurance that it really came from the source they reviewed.
  6. ## Prerequisites:
  7. ### Arch:
  8. sudo pacman -S python2-cheetah qemu rsync
  9. sudo pacman -S lxc libvirt bridge-utils # for lxc mode
  10. From AUR:
  11. * [apt-cacher-ng]( (you may have to play with permissions (chown to apt-cacher-ng) on files to get apt-cacher-ng to start)
  12. * [debootstrap](
  13. * [dpkg](
  14. * [gnupg1](
  15. * [multipath-tools]( (for kpartx)
  16. Non-AUR packages:
  17. * [debian-archive-keyring]( (for making Debian guests)
  18. * [ubuntu-keyring]( (for making Ubuntu guests)
  19. From newroco on GitHub:
  20. * [vmbuilder](
  21. Also, I had to modify the default /etc/sudoers file to uncomment the `secure_path` line, because vmbuilder isn't found otherwise when the `env -i ... sudo vmbuilder ...` line is executed (because the i flag resets the environment variables including the PATH).
  22. ### Gentoo:
  23. layman -a luke-jr # needed for vmbuilder
  24. sudo emerge dev-vcs/git net-misc/apt-cacher-ng app-emulation/vmbuilder dev-lang/ruby
  25. sudo emerge app-emulation/qemu
  26. export KVM=qemu-system-x86_64
  27. ### Ubuntu:
  28. This pulls in all pre-requisites for KVM building on Ubuntu:
  29. sudo apt-get install git apache2 apt-cacher-ng python-vm-builder ruby qemu-utils
  30. If you'd like to use LXC mode instead, install it as follows:
  31. sudo apt-get install lxc
  32. If you'd like to use docker mode instead, install it as follows:
  33. sudo apt-get install docker-ce
  34. ### Debian:
  35. See Ubuntu, and also run the following on Debian Jessie or newer:
  36. sudo apt-get install ubuntu-archive-keyring
  37. On Debian Wheezy you run the same command, but you must first add backports to your system, because the package is only available in wheezy-backports.
  38. ### OSX with MacPorts:
  39. sudo port install ruby coreutils
  40. export PATH=$PATH:/opt/local/libexec/gnubin # Needed for sha256sum
  41. ### OSX with Homebrew:
  42. brew install ruby coreutils
  43. export PATH=$PATH:/opt/local/libexec/gnubin
  44. #### VirtualBox:
  45. Install virtualbox from, and make sure `VBoxManage` is in your `$PATH`.
  46. ## Debian Guests
  47. Gitian supports Debian guests in addition to Ubuntu guests. Note that this doesn't mean you can allow the builders to choose to use either Debian or Ubuntu guests. The person creating the Gitian descriptor will need to choose a particular distro and suite for the guest and all builders must use that particular distro and suite, otherwise the software won't reproduce for everyone.
  48. To create a Debian guest:
  49. bin/make-base-vm --distro debian --suite jessie
  50. There is currently no support for LXC Debian guests. There is just KVM support. LXC support for Debian guests is planned to be added soon.
  51. Only Debian Jessie guests have been tested with Gitian. If you have success (or trouble) with other versions of Debian, please let us know.
  52. If you are creating a Gitian descriptor, you can now specify a distro. If no distro is provided, the default is to assume Ubuntu. Since Ubuntu is assumed, older Gitian descriptors that don't specify a distro will still work as they always have.
  53. ## Create the base VM for use in further builds
  54. **NOTE:** requires `sudo`, please review the script
  55. ### KVM
  56. bin/make-base-vm
  57. bin/make-base-vm --arch i386
  58. ### LXC
  59. bin/make-base-vm --lxc
  60. bin/make-base-vm --lxc --arch i386
  61. Set the `USE_LXC` environment variable to use `LXC` instead of `KVM`:
  62. export USE_LXC=1
  63. ### Docker
  64. bin/make-base-vm --docker
  65. bin/make-base-vm --docker --arch i386
  66. Set the `USE_DOCKER` environment variable to use `DOCKER` instead of `KVM`:
  67. export USE_DOCKER=1
  68. ### VirtualBox
  69. Command-line `VBoxManage` must be in your `$PATH`.
  70. #### Setup:
  71. `make-base-vm` cannot yet make VirtualBox virtual machines ( _patches welcome_, it should be possible to use `VBoxManage`, boot-from-network Linux images and PXE booting to do it). So you must either get or manually create VirtualBox machines that:
  72. 1. Are named `Gitian-<suite>-<arch>` -- e.g. Gitian-xenial-i386 for a 32-bit, Ubuntu 16 machine.
  73. 2. Have a booted-up snapshot named `Gitian-Clean` . The build script resets the VM to that snapshot to get reproducible builds.
  74. 3. Has the VM's NAT networking setup to forward port `localhost:2223` on the host machine to port `22` of the VM; e.g.:
  75. ```
  76. VBoxManage modifyvm Gitian-xenial-i386 --natpf1 "guestssh,tcp,,2223,,22"
  77. ```
  78. The final setup needed is to create an `ssh` key that will be used to login to the virtual machine:
  79. ssh-keygen -t rsa -f var/id_rsa -N ""
  80. ssh -p 2223 ubuntu@localhost 'mkdir -p .ssh && chmod 700 .ssh && cat >> .ssh/authorized_keys' < var/
  81. Then log into the vm and copy the `ssh` keys to root's `authorized_keys` file.
  82. ssh -p 2223 ubuntu@localhost
  83. # Now in the vm
  84. sudo bash
  85. mkdir -p .ssh && chmod 700 .ssh && cat ~ubuntu/.ssh/authorized_keys >> .ssh/authorized_keys
  86. Set the `USE_VBOX` environment variable to use `VBOX` instead of `KVM`:
  87. export USE_VBOX=1
  88. ## Sanity-testing
  89. If you have everything set-up properly, you should be able to:
  90. PATH=$PATH:$(pwd)/libexec
  91. make-clean-vm --suite xenial --arch i386
  92. # on-target needs $DISTRO to be set to debian if using a Debian guest
  93. # (when running gbuild, $DISTRO is set based on the descriptor, so this line isn't needed)
  94. DISTRO=debian
  95. # For LXC:
  96. LXC_ARCH=i386 LXC_SUITE=xenial on-target ls -la
  97. # For KVM:
  98. start-target 32 xenial-i386 &
  99. # wait a few seconds for VM to start
  100. on-target ls -la
  101. stop-target
  102. ## Building
  103. Copy any additional build inputs into a directory named _inputs_.
  104. Then execute the build using a `YAML` description file (can be run as non-root):
  105. export USE_LXC=1 # LXC only
  106. bin/gbuild <package>.yml
  107. or if you need to specify a commit for one of the git remotes:
  108. bin/gbuild --commit <dir>=<hash> <package>.yml
  109. The resulting report will appear in `result/<package>-res.yml`
  110. To sign the result, perform:
  111. bin/gsign --signer <signer> --release <release-name> <package>.yml
  112. Where `<signer>` is your signing PGP key ID and `<release-name>` is the name for the current release. This will put the result and signature in the `sigs/<package>/<release-name>`. The `sigs/<package>` directory can be managed through git to coordinate multiple signers.
  113. After you've merged everybody's signatures, verify them:
  114. bin/gverify --release <release-name> <package>.yml
  115. ## Poking around
  116. * Log files are captured to the _var_ directory
  117. * You can run the utilities in libexec by running `PATH="libexec:$PATH"`
  118. * To start the target VM run `start-target 32 xenial-i386` or `start-target 64 xenial-amd64`
  119. * To ssh into the target run `on-target` (after setting $DISTRO to debian if using a Debian guest) or `on-target -u root`
  120. * On the target, the _build_ directory contains the code as it is compiled and _install_ contains intermediate libraries
  121. * By convention, the script in `<package>.yml` starts with any environment setup you would need to manually compile things on the target
  122. TODO:
  123. - disable sudo in target, just in case of a hypervisor exploit
  124. - tar and other archive timestamp setter
  125. ## LXC tips
  126. `bin/gbuild` runs `lxc-execute` or `lxc-start`, which may require root. If you are in the admin group, you can add the following sudoers line to prevent asking for the password every time:
  127. %admin ALL=NOPASSWD: /usr/bin/lxc-execute
  128. %admin ALL=NOPASSWD: /usr/bin/lxc-start
  129. Right now `lxc-start` is the default, but you can force `lxc-execute` (useful for Ubuntu 14.04) with:
  130. export LXC_EXECUTE=lxc-execute
  131. Recent distributions allow lxc-execute / lxc-start to be run by non-privileged users, so you might be able to rip-out the `sudo` calls in `libexec/*`.
  132. If you have a runaway `lxc-start` command, just use `kill -9` on it.
  133. The machine configuration requires access to br0 and assumes that the host address is ``:
  134. sudo brctl addbr br0
  135. sudo ifconfig br0 up
  136. ## Tests
  137. Not very extensive, currently.
  138. `python -m unittest discover test`