2011-01-30 21:12:02 +00:00
# Gitian
2013-08-29 15:16:56 +00:00
Read about the project goals at the [project home page ](https://gitian.org/ ).
2011-01-30 21:12:02 +00:00
This package can do a deterministic build of a package inside a VM.
## Deterministic build inside a VM
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.
2013-02-08 16:50:34 +00:00
## Prerequisites:
2011-01-30 21:12:02 +00:00
2013-08-29 15:16:56 +00:00
### Gentoo:
2013-04-09 07:50:35 +00:00
layman -a luke-jr # needed for vmbuilder
sudo emerge dev-vcs/git net-misc/apt-cacher-ng app-emulation/vmbuilder dev-lang/ruby
sudo emerge app-emulation/qemu
export KVM=qemu-system-x86_64
2013-08-29 15:16:56 +00:00
### Ubuntu:
2011-01-30 21:12:02 +00:00
2013-10-31 22:22:43 +00:00
sudo apt-get install git apache2 apt-cacher-ng python-vm-builder ruby qemu-utils
2013-04-09 07:50:35 +00:00
sudo apt-get install qemu-kvm # for KVM mode
sudo apt-get install debootstrap lxc # for LXC mode
2013-02-08 16:50:34 +00:00
2015-07-07 21:02:35 +00:00
### Debian:
See Ubuntu, and also run the following on Debian Jessie or newer:
sudo apt-get install ubuntu-archive-keyring
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.
2013-08-29 15:16:56 +00:00
### OSX with MacPorts:
2013-02-08 16:50:34 +00:00
sudo port install ruby coreutils
export PATH=$PATH:/opt/local/libexec/gnubin # Needed for sha256sum
2013-08-29 15:16:56 +00:00
#### VirtualBox:
2013-02-08 16:50:34 +00:00
2013-08-29 15:16:56 +00:00
Install virtualbox from http://www.virtualbox.org, and make sure `VBoxManage` is in your `$PATH` .
2013-02-08 16:50:34 +00:00
2013-08-29 15:16:56 +00:00
## Create the base VM for use in further builds
**NOTE:** requires `sudo` , please review the script
2013-02-08 16:50:34 +00:00
### KVM
2011-01-30 21:12:02 +00:00
bin/make-base-vm
2012-04-22 05:44:00 +00:00
bin/make-base-vm --arch i386
2013-02-08 16:50:34 +00:00
### LXC
2012-04-22 05:44:00 +00:00
bin/make-base-vm --lxc
bin/make-base-vm --lxc --arch i386
2011-01-30 21:12:02 +00:00
2013-08-29 15:16:56 +00:00
Set the `USE_LXC` environment variable to use `LXC` instead of `KVM` :
2013-02-08 16:50:34 +00:00
export USE_LXC=1
### VirtualBox
2013-08-29 15:16:56 +00:00
Command-line `VBoxManage` must be in your `$PATH` .
#### Setup:
2013-02-08 16:50:34 +00:00
2013-08-29 15:16:56 +00:00
`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:
2013-02-08 16:50:34 +00:00
2013-08-29 15:16:56 +00:00
1. Are named `Gitian-<suite>-<arch>` -- e.g. Gitian-lucid-i386 for a 32-bit, Ubuntu 10 machine.
2. Have a booted-up snapshot named `Gitian-Clean` . The build script resets the VM to that snapshot to get reproducible builds.
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.:
2013-02-08 16:50:34 +00:00
2013-08-29 15:16:56 +00:00
```
2013-02-08 16:50:34 +00:00
VBoxManage modifyvm Gitian-lucid-i386 --natpf1 "guestssh,tcp,,2223,,22"
2013-08-29 15:16:56 +00:00
```
2013-02-08 16:50:34 +00:00
2013-08-29 15:16:56 +00:00
The final setup needed is to create an `ssh` key that will be used to login to the virtual machine:
2013-02-08 16:50:34 +00:00
ssh-keygen -t dsa -f var/id_dsa -N ""
ssh -p 2223 ubuntu@localhost 'mkdir -p .ssh & & chmod 700 .ssh & & cat >> .ssh/authorized_keys' < var / id_dsa . pub
2013-08-29 15:16:56 +00:00
Then log into the vm and copy the `ssh` keys to root's `authorized_keys` file.
2013-02-08 16:50:34 +00:00
ssh -p 2223 ubuntu@localhost
2013-08-29 15:16:56 +00:00
# Now in the vm
sudo bash
mkdir -p .ssh & & chmod 700 .ssh & & cat ~ubuntu/.ssh/authorized_keys >> .ssh/authorized_keys
Set the `USE_VBOX` environment variable to use `VBOX` instead of `KVM` :
2013-02-08 16:50:34 +00:00
export USE_VBOX=1
## Sanity-testing
If you have everything set-up properly, you should be able to:
2013-08-29 15:16:56 +00:00
PATH=$PATH:$(pwd)/libexec
make-clean-vm --suite lucid --arch i386
2013-09-24 18:25:56 +00:00
# For LXC:
LXC_ARCH=i386 LXC_SUITE=lucid on-target ls -la
# For KVM:
2014-02-03 18:27:02 +00:00
start-target 32 lucid-i386 &
2014-07-12 07:10:05 +00:00
# wait a few seconds for VM to start
2013-08-29 15:16:56 +00:00
on-target ls -la
stop-target
2013-02-08 16:50:34 +00:00
## Building
2011-01-30 23:31:33 +00:00
Copy any additional build inputs into a directory named _inputs_ .
2011-01-30 21:12:02 +00:00
2013-08-29 15:16:56 +00:00
Then execute the build using a `YAML` description file (can be run as non-root):
2011-01-30 21:12:02 +00:00
2012-04-22 05:44:00 +00:00
export USE_LXC=1 # LXC only
2011-03-27 19:24:22 +00:00
bin/gbuild < package > .yml
2011-01-30 23:31:33 +00:00
2011-02-01 17:48:33 +00:00
or if you need to specify a commit for one of the git remotes:
2011-03-27 19:24:22 +00:00
bin/gbuild --commit < dir > =< hash > < package > .yml
2011-02-01 17:48:33 +00:00
2013-08-29 15:16:56 +00:00
The resulting report will appear in `result/<package>-res.yml`
2011-02-01 07:50:59 +00:00
2011-03-27 19:24:22 +00:00
To sign the result, perform:
bin/gsign --signer < signer > --release < release-name > < package > .yml
2013-08-29 15:16:56 +00:00
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.
2011-03-27 19:24:22 +00:00
After you've merged everybody's signatures, verify them:
bin/gverify --release < release-name > < package > .yml
2013-02-08 16:50:34 +00:00
2011-02-01 07:50:59 +00:00
## Poking around
* Log files are captured to the _var_ directory
* You can run the utilities in libexec by running `PATH="libexec:$PATH"`
2011-03-22 16:02:53 +00:00
* To start the target VM run `start-target 32 lucid-i386` or `start-target 64 lucid-amd64`
2011-02-01 07:50:59 +00:00
* To ssh into the target run `on-target` or `on-target -u root`
* On the target, the _build_ directory contains the code as it is compiled and _install_ contains intermediate libraries
2013-08-29 15:16:56 +00:00
* By convention, the script in `<package>.yml` starts with any environment setup you would need to manually compile things on the target
2011-02-01 07:50:59 +00:00
TODO:
- disable sudo in target, just in case of a hypervisor exploit
- tar and other archive timestamp setter
2012-04-22 19:37:11 +00:00
## LXC tips
2014-09-22 22:10:33 +00:00
`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:
2012-04-22 19:37:11 +00:00
2014-09-04 20:54:05 +00:00
%admin ALL=NOPASSWD: /usr/bin/lxc-execute
2014-09-22 22:10:33 +00:00
%admin ALL=NOPASSWD: /usr/bin/lxc-start
2012-04-22 19:37:11 +00:00
2014-09-22 22:10:33 +00:00
Right now `lxc-start` is the default, but you can force `lxc-execute` (useful for Ubuntu 14.04) with:
2012-04-22 19:37:11 +00:00
2014-09-22 22:10:33 +00:00
export LXC_EXECUTE=lxc-execute
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/*` .
If you have a runaway `lxc-start` command, just use `kill -9` on it.
2012-04-22 19:37:11 +00:00
2013-08-29 15:16:56 +00:00
The machine configuration requires access to br0 and assumes that the host address is `10.0.2.2` :
2012-04-22 19:37:11 +00:00
2012-08-03 22:02:11 +00:00
sudo brctl addbr br0
2012-04-22 19:37:11 +00:00
sudo ifconfig br0 10.0.2.2/24 up
2012-08-09 03:57:29 +00:00
## Tests
Not very extensive, currently.
`python -m unittest discover test`