The idiot proof guide to setting up Insekta from scratch¶
This installation guide provides step-by-step instructions on how to setup Insekta from scratch.
Requirements¶
- A physical machine (called
insekta host) on which Insekta will be installed. Initial physical access is required for setting up the operating system. A brief guide on setting up SSH access is given below such that physical access is no longer necessary. - Another physical machine (called
local machine) for setting up Insekta from remote. Such a device, e.g., your laptop, is not necessary if you want to perform the setup in front of the insekta host. Note that this guide assumes remote setup. - A working internet connection.
- A USB flash drive with at least 1 GB.
- Roughly 60 minutes of free time.
Additional Files¶
Exemplary configuration file, e.g., for the settings.py is often supplied in the respective project repository. In addition, the following configuration files are directly supplied within this directory:
insekta-vmnginx configuration for insekta-vminsekta-webnginx configuration for insekta-webinsekta-vm.servicesystemd unit file for insekta-vminsekta-web.servicesystemd unit file for insekta-web
Installing Debian on the insekta host¶
- Download the latest Debian image (preferably a netinst version) from https://www.debian.org/CD/netinst/. At the time of writing this guide you could fetch the ISO file by running
wget -c https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.5.0-amd64-netinst.isoon your local machine. - Create a bootable USB flash drive using the ISO file from the previous step. To do so run
sudo dd if=~/debian-9.5.0-amd64-netinst.iso of=/dev/sdb42on your local machine. Note thatofmust be assigned the location of your USB flash drive. You can lookup your already mounted devices viadfand usesudo fdisk -lfor unmounted devices. Double-check the parameters for correctness before running this command. - Plugin the bootable USB flash drive to the insekta host, power up the machine and boot from the USB flash drive. You might have to turn off
Secure Bootin the BIOS before. - Perform a typical Debian installation, but make sure to enable
SSH server. You can disablePrint server; a desktop manager is not required either. - Finally, reboot the machine, boot from the hard disk, and remove the USB flash drive.
Setting up remote SSH access¶
- Login to the insekta host as
rootand create the.sshdirectory viamkdir /root/.ssh. - Create an empty
authorized_keysfile viatouch /root/.ssh/authorized_keys. - Adjust the file mode via
chmod 600 /root/.ssh/. - Append your public key to
/root/.ssh/authorized_keys, e.g., with your editor of choice, i.e.,vim. Hence, installvimviaapt install vim. You can read out the public key of yourlocal machineviacat ~/.ssh/id_rsa.pub(at least this is the default location). In case that this file does not exist you can create a key pair by runningssh-keygen. - Hint: instead of manually writing down your public key into the
authorized_keysfile, you can copy your public key on a USB flash drive, mount it on the insekta host and copy your key to theauthorized_keysfile. Note that you might have to manually mount the USB flash drive usingfdisk -lto list the partition table and themountcommand to actually mount the USB flash drive to a folder. For copying the public key to theauthorized_keysfile you can runvim /the/path/to/id_rsa.pub /root/.ssh/authorized_keys -Oto display both files next to each other. Then, enter visual mode viev, highlight your public key and pressyto copy/yank, switch panes viaCTRL+w+w, and paste viap, then quit and save both files via:wq. - To get the IP of the insekta host run
ip aorifconfig(you might have to runapt install net-toolsbefore). - On your local machine connect to the insekta host via
ssh root@420.420.420.420(replace420.420.420.420with the IP obtained in the previous step). - In case that you do not use the default SSH key location, make sure to adapt your SSH config within file
~/.ssh/config.
Setting up libvirt on the insekta host¶
Install libvirt dependencies via
apt install libvirt-daemon-system.Install OVMF for UEFI image support via
apt install ovmf.The next step is to setup a new storage pool called
insekta, which is used later on to store VM images. This can either be achieved viavirt-manageror by running the following commands on the insekta host:virsh pool-define-as insekta dir - - - - "/var/lib/libvirt/images/insekta/".virsh pool-build insekta.virsh pool-start insekta.virsh pool-autostart insekta.
- Upon running
virsh pool-list --detailsyou should see an output similar to the one below: Name State Autostart Persistent Capacity Allocation Available ----------------------------------------------------------------------------- default running yes yes 436.67 GiB 1.90 GiB 434.77 GiB insekta running yes yes 436.67 GiB 1.90 GiB 434.77 GiB
- Upon running
Setting up the insekta libvirt image¶
- Install
virt-manageron your local machine, e.g., by runningapt install virt-manageron Debian. - Download a Debian image as previously done for the insekta host machine and store it in
/var/lib/libvirt/imageson the insekta host. - Setup a new Debian virtual machine using the wizard provided by
virt-manager. Make sure to checkcustomize configuration before installto enable UEFI firmware and the i440FX chipset. You most likely want to turn onstart vm on host bootas well. - Perform a normal Debian installation as done before.
- Generate a new SSH key pair on the insekta host using
ssh-keygenand setup SSH remote access as shown before such that you can connect from insekta host to the new insekta libvirtd image. - Lookup the IP address of the insekta libvirtd image by running
ifconfigorip aon this machine and connect to it from insekta host via SSH.
Setting up the insekta-web component¶
Note that the following steps must be performed on the insekta libvirt image.
Install dependencies via
apt install git make wget python3 python3-pip unzip gettext curl sudo python3-venv.Install nodejs as npm via
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -andapt install -y nodejs.If not already done before, install pipenv via
pip3 install pipenv.Clone the repository via
cd /opt/; git clone https://github.com/Insekta/insekta-web.git; cd insekta-web.Use the provided example configuration file via
cp /opt/insekta-web/insekta/insekta/settings.py.example /opt/insekta-web/insekta/insekta/settings.pyand adapt it.# domain names or IP address allowed to access this service. Use the machine's IP or the respective domain name. ALLOWED_HOSTS = ['420.420.420.420'] # location where static files are located STATIC_ROOT = "/opt/insekta-static/insekta-web/static-root" # location where media files are located MEDIA_ROOT = "/opt/insekta-static/insekta-web/media-root" # the IP and port of the VPN server VPN_SERVER = {'host': 'localhost', 'port': 1194} # the URI where the insekta-vm API can be found REMOTE_API_URL = 'http://localhost:8001/api/' # authentication for the insekta-vm API REMOTE_API_AUTH = ('api', 'mypassword') # code required to register a new insekta account at insekta-web INVITATION_CODE = 'supergeheim'
Setup the virtualenv environment and generate static files:
- Create a new virtual environment
python3 -m venv /opt/insekta-web/insekta/venv. - Spawn the virtualenv shell at the
venvfolder viasource bin/activate. - Install dependencies via
pipenv install. - We use
gunicornfor serving this application. Hence, runpip install gunicornto install it. - We use
sassfor css file generation. Hence, runnpm install -g sass. - Generate the static files by invoking the Makefile via
cd /opt/insekta-web/insekta; make. - Build the initial environment for the scenarios via
cd /opt/insekta-web/insekta; make testenv. - Run
cd /opt/insekta-web/insekta; python manage.py migrate - Collect and copy the static files to the previously defined location via
cd /opt/insekta-web/insekta; python manage.py collectstatic. - Invoke
deactivateto leave the virtualenv shell.
- Create a new virtual environment
Setup
nginxas a reverse proxy (see the instructions above).If not already done before, create a system account for insekta via
useradd --system insekta.Adapt the rights via
chown -c insekta /opt/insekta-web -R.Copy the provided systemd service file to
/etc/systemd/systemand adapt it if necessary.Enable the service via
systemctl enable insekta-web.serviceand start it viasystemctl start insekta-web.service.
Setting up openvpn¶
Note that the following steps must be performed on the insekta libvirt image.
- Install the following dependencies via
apt install build-essential libvirt-dev qemu-kvm git virtualenv python-libvirt python3-libvirt python3 python3-dev python-dev pkg-config openvpn iptables python3-pip. - Clone the
insekta-vmrepository to/optand enter it viacd /opt/; git clone https://github.com/Insekta/insekta-vm.git; cd insekta-vm. - Copy the openvpn directory from
insekta-vm/insektavm/examples/openvpn/to/etc/openvpnviacp -r /opt/insekta-vm/insektavm/examples/openvpn/* /etc/openvpn/server. - Create a system account for openvpn via
useradd --system openvpn. - Change the file ownership of
/etc/openvpntoopenvpnviachown -R openvpn /etc/openvpn. - Enable the systemd service for openvpn via
systemctl enable openvpn-server@server.
Setting up the CA¶
Enter
/usr/share/easy-rsa, invokemake-cadir cadirand enter the createdcadirdirectory viacd /usr/share/easy-rsa; make-cadir cadir; cd cadir.Adjust the certificate fields in file
vars, e.g., viavim /usr/share/easy-rsa/cadir/vars. The fields that need to be adjusted can be found at the bottom of the file and a sample configuration might look as follows:# These are the default values for fields # which will be placed in the certificate. # Don't leave any of these fields blank. export KEY_COUNTRY="DE" export KEY_PROVINCE="Bayern" export KEY_CITY="Bamberg" export KEY_ORG="PSI" export KEY_EMAIL="services.psi@uni-bamberg.de" export KEY_OU="Insekta"
Create a symlink to openssl via
ln -s openssl-1.0.0.cnf openssl.cnf.Source the
varsfile viasource ./vars.Run
./clean-all.Run
./build-ca. Note that this will ask you to confirm the previously configured certificate fields by pressing enter.Run
./build-key-server server. This might take some time for generating the key pair. It will also ask you again to confirm the previously configured certificate fields. In addition, enteryfor signing,yfor committing, andnfor not challenging.Copy the generated certificates and the server key to
/etc/openvpn/server/via:cp keys/ca.crt /etc/openvpn/server/ cp keys/server.crt /etc/openvpn/server/ cp keys/server.key /etc/openvpn/server/
Copy the certificate and the key of the ca to insekta-web, i.e., by running
cp /etc/openvpn/server/ca.* /opt/insekta-web/insekta/testenv/vpn/.Finally, start the systemd service for openvpn via
systemctl start openvpn-server@server.
Setting up NGINX as a reverse proxy¶
NGINX is used as a reverse proxy to map the requests to the respective services. Note that the following steps must be performed on the insekta libvirt image.
- Install dependencies via
apt install nginx. - Start the service via
service nginx start. - Copy the example nginx configuration file from the repository to
/etc/nginx/sites-availableand adapt if necessary. You will most likely have to adjust theserver_namefield. - Create a symlink in
/etc/nginx/sites-enabledthat points to the file in/etc/nginx/sites-availablevialn -s /etc/nginx/sites-available/filename /etc/nginx/sites-enabled/filename. - You might have to remove the
defaultsymlink in/etc/nginx/sites-enabled. - Restart nginx via
service nginx reloadsuch that the modified configuration is applied.
Setting up the insekta-vm component¶
Note that the following steps must be performed on the insekta libvirt image. It is furthermore assumed that you already have performed the setup of openvpn as described above.
Install pipenv via
pip3 install pipenvand venv viaapt install python3-venv.Copy the provided example settings file via
cp /opt/insekta-vm/insektavm/insektavm/settings.py.example /opt/insekta-vm/insektavm/insektavm/settings.pyand adapt it.# domain names or IP address allowed to access this service. Use the machine's IP or the respective domain name. ALLOWED_HOSTS = ['420.420.420.420'] # Hostname of the physical host machine that is serving the insekta scenario images LIBVIRT_NODES = { 'default': 'qemu+ssh://root@420.420.420.420/system' } # location where scenario images are located on the insekta libvirt image VM_IMAGE_DIR = '/opt/import-scenario-vm' # authentication for the insekta-vm API API_AUTH = ('api', 'mypassword')
Setup a SSH remote access from the running insekta libvirt image to the insekta host machine. Thereby, the insekta libvirt image can communicate with the libvirt daemon running on the insekta host machine.
Setup the virtualenv environment:
- Create a new virtual environment
python3 -m venv /opt/insekta-vm/insektavm/venv. - Spawn the virtualenv shell via
source /opt/insekta-vm/insektavm/venv/bin/activate. - Install dependencies via
pip install -r /opt/insekta-vm/requirements.txt. - We also need
gunicornfor serving this application. To install runpip install gunicorn. - Run
cd /opt/insekta-vm/insektavm; python manage.py migrate. - Invoke
deactivateto leave the virtualenv shell.
- Create a new virtual environment
Copy the systemd service file and adapt the paths if necessary via
cp /opt/insekta-vm/insektavm/examples/systemd/insekta-vm.service /etc/systemd/system/.Create a system account for insekta via
useradd --system insekta.Adapt the rights via
chown -c insekta /opt/insekta-vm -R.Enable the service via
systemctl enable insekta-vm.serviceand start it viasystemctl start insekta-vm.service.Setup
nginxas a reverse proxy (see the instructions above).