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.6KB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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. * [debian-archive-keyring]( (for making Debian guests)
  13. * [debootstrap](
  14. * [dpkg](
  15. * [gnupg1](
  16. * [multipath-tools]( (for kpartx)
  17. * [ubuntu-keyring]( (for making Ubuntu guests)
  18. From Launchpad:
  19. * [vmbuilder](
  20. 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).
  21. ### Gentoo:
  22. layman -a luke-jr # needed for vmbuilder
  23. sudo emerge dev-vcs/git net-misc/apt-cacher-ng app-emulation/vmbuilder dev-lang/ruby
  24. sudo emerge app-emulation/qemu
  25. export KVM=qemu-system-x86_64
  26. ### Ubuntu:
  27. This pulls in all pre-requisites for KVM building on Ubuntu:
  28. sudo apt-get install git apache2 apt-cacher-ng python-vm-builder ruby qemu-utils
  29. If you'd like to use LXC mode instead, install it as follows:
  30. sudo apt-get install lxc
  31. ### Debian:
  32. See Ubuntu, and also run the following on Debian Jessie or newer:
  33. sudo apt-get install ubuntu-archive-keyring
  34. 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.
  35. ### OSX with MacPorts:
  36. sudo port install ruby coreutils
  37. export PATH=$PATH:/opt/local/libexec/gnubin # Needed for sha256sum
  38. ### OSX with Homebrew:
  39. brew install ruby coreutils
  40. export PATH=$PATH:/opt/local/libexec/gnubin
  41. #### VirtualBox:
  42. Install virtualbox from, and make sure `VBoxManage` is in your `$PATH`.
  43. ## Debian Guests
  44. Gitian now 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.
  45. The official vmbuilder only includes support for Ubuntu guests, so you need to install [Joseph Bisch's fork of vmbuilder](, which adds a Debian plugin.
  46. To create a Debian guest:
  47. bin/make-base-vm --distro debian --suite jessie
  48. 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.
  49. Only Debian Jessie guests have been tested with Gitian. Debian Jessie is the current stable release of Debian at this time. If you have success (or trouble) with other versions of Debian, please let us know.
  50. 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.
  51. ## Create the base VM for use in further builds
  52. **NOTE:** requires `sudo`, please review the script
  53. ### KVM
  54. bin/make-base-vm
  55. bin/make-base-vm --arch i386
  56. ### LXC
  57. bin/make-base-vm --lxc
  58. bin/make-base-vm --lxc --arch i386
  59. Set the `USE_LXC` environment variable to use `LXC` instead of `KVM`:
  60. export USE_LXC=1
  61. ### VirtualBox
  62. Command-line `VBoxManage` must be in your `$PATH`.
  63. #### Setup:
  64. `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:
  65. 1. Are named `Gitian-<suite>-<arch>` -- e.g. Gitian-xenial-i386 for a 32-bit, Ubuntu 16 machine.
  66. 2. Have a booted-up snapshot named `Gitian-Clean` . The build script resets the VM to that snapshot to get reproducible builds.
  67. 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.:
  68. ```
  69. VBoxManage modifyvm Gitian-xenial-i386 --natpf1 "guestssh,tcp,,2223,,22"
  70. ```
  71. The final setup needed is to create an `ssh` key that will be used to login to the virtual machine:
  72. ssh-keygen -t rsa -f var/id_rsa -N ""
  73. ssh -p 2223 ubuntu@localhost 'mkdir -p .ssh && chmod 700 .ssh && cat >> .ssh/authorized_keys' < var/
  74. Then log into the vm and copy the `ssh` keys to root's `authorized_keys` file.
  75. ssh -p 2223 ubuntu@localhost
  76. # Now in the vm
  77. sudo bash
  78. mkdir -p .ssh && chmod 700 .ssh && cat ~ubuntu/.ssh/authorized_keys >> .ssh/authorized_keys
  79. Set the `USE_VBOX` environment variable to use `VBOX` instead of `KVM`:
  80. export USE_VBOX=1
  81. ## Sanity-testing
  82. If you have everything set-up properly, you should be able to:
  83. PATH=$PATH:$(pwd)/libexec
  84. make-clean-vm --suite xenial --arch i386
  85. # on-target needs $DISTRO to be set to debian if using a Debian guest
  86. # (when running gbuild, $DISTRO is set based on the descriptor, so this line isn't needed)
  87. DiSTRO=debian
  88. # For LXC:
  89. LXC_ARCH=i386 LXC_SUITE=xenial on-target ls -la
  90. # For KVM:
  91. start-target 32 xenial-i386 &
  92. # wait a few seconds for VM to start
  93. on-target ls -la
  94. stop-target
  95. ## Building
  96. Copy any additional build inputs into a directory named _inputs_.
  97. Then execute the build using a `YAML` description file (can be run as non-root):
  98. export USE_LXC=1 # LXC only
  99. bin/gbuild <package>.yml
  100. or if you need to specify a commit for one of the git remotes:
  101. bin/gbuild --commit <dir>=<hash> <package>.yml
  102. The resulting report will appear in `result/<package>-res.yml`
  103. To sign the result, perform:
  104. bin/gsign --signer <signer> --release <release-name> <package>.yml
  105. 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.
  106. After you've merged everybody's signatures, verify them:
  107. bin/gverify --release <release-name> <package>.yml
  108. ## Poking around
  109. * Log files are captured to the _var_ directory
  110. * You can run the utilities in libexec by running `PATH="libexec:$PATH"`
  111. * To start the target VM run `start-target 32 xenial-i386` or `start-target 64 xenial-amd64`
  112. * To ssh into the target run `on-target` (after setting $DISTRO to debian if using a Debian guest) or `on-target -u root`
  113. * On the target, the _build_ directory contains the code as it is compiled and _install_ contains intermediate libraries
  114. * By convention, the script in `<package>.yml` starts with any environment setup you would need to manually compile things on the target
  115. TODO:
  116. - disable sudo in target, just in case of a hypervisor exploit
  117. - tar and other archive timestamp setter
  118. ## LXC tips
  119. `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:
  120. %admin ALL=NOPASSWD: /usr/bin/lxc-execute
  121. %admin ALL=NOPASSWD: /usr/bin/lxc-start
  122. Right now `lxc-start` is the default, but you can force `lxc-execute` (useful for Ubuntu 14.04) with:
  123. export LXC_EXECUTE=lxc-execute
  124. Recent distributions allow lxc-execute / lxc-start to be run by non-priviledged users, so you might be able to rip-out the `sudo` calls in `libexec/*`.
  125. If you have a runaway `lxc-start` command, just use `kill -9` on it.
  126. The machine configuration requires access to br0 and assumes that the host address is ``:
  127. sudo brctl addbr br0
  128. sudo ifconfig br0 up
  129. ## Tests
  130. Not very extensive, currently.
  131. `python -m unittest discover test`