Iptables in Echtzeit monitoren
Ich hatte grade die mal wieder die angenehme Erfahrung iptables in Echtzeit zu debuggen.
Hier ist ein kleiner Einzeiler, der dabei helfen kann.
watch -n 1 "sudo iptables-save -t nat -c"
iptables-save hat den netten Parameter -c, welcher die Counter der getroffenen Regeln in [packet:byte] anzeigt.
Wenn Ihr wie ich eine Menge web Traffic auf vielen VM habt, wollt Ihr vielleicht noch Traffic zu 443 rausfiltern. Außerdem kann es helfen nur Regeln zu listen, die mindestens einmal getriggert haben.
watch -n 1 "sudo iptables-save -t nat -c | grep -v '0:0' |grep -v '443'"
Das gibt euch eine kompakte Übersicht darüber, welche Regeln greifen und kann fürs Echtzeitdebugging helfen.

Happy hacking :)
Monitoring iptables in realtime
I just had the pleasurable experience of debugging iptables again.
Here is a short oneliner that lets you debug your iptables in realtime.
watch -n 1 "sudo iptables-save -t nat -c"
iptables-save has the convienient flag -c, which is showing it's counters as [packet:byte]
If you have a lot of web traffic on vm's like me you might want to filter out 443. Also rules that do not trigger at all [0:0] can be filtered out.
watch -n 1 "sudo iptables-save -t nat -c | grep -v '0:0' |grep -v '443'"
This gives you a good indication as to wich rules get applied in realtime.
A useful tool for debugging.

Happy hacking :)
Flowerberry
Flowerberry ist der von mir frei erfundene Name für dieses Projekt.
Es geht darum Pflanzensensoren über einen Raspberry Pi auszulesen und die Daten in eine InfluxDB zu packen.
Diese wird dann an ein Garafana angeschlossen um die Daten zu visualisieren und Alarm zu schlagen, sollten die Sensoren erkennen, dass der Boden zu trocken ist oder die Pflanze zu kalt.
Diese Anleitung und das Projekt selbst basieren auf diesem Blogbeitrag.
Einkaufsliste
(bis zu) 20x Flower Care Xiaomi Mi Flora
Vorbereitung
Den Sensor einschalten
Packt die Sensoren aus und öffnet den ersten vorsichtig.
Nehmt einen Fingernagel, eine Plastikkarte oder ein Spezialwerkzeug und hebt den Deckel des Sensors leicht an.

Fahrt dann an der Kante entlang, bis ihr die Kappe abnehmen könnt.

Zieht dann an der Plastiklasche, um den Sensor zu aktivieren.

Raspberry Pi
Gruneinrichtung
Zunächst installiert Ihr das Raspberry Pi OS (ehemals raspbian) Lite image.
dd if if=/Downloads/2020-05-27-raspios-buster-lite-armhf.zip of=/dev/YOUR_SD_CARD bs=1M status=progress
Sorgt dafür, dass er sich mit eurem Wifi verbindet und Ihr euch per SSH mit ihm verbinden könnt.
Wenn Ihr fault seit, schließt einfach einen Monitor und eine Tastatur an den Raspberry an.

Mit dem commandlet raspi-config bekommt Ihr eine leicht verständliches pseudo-grafisches Konfigurationsmenü.
Findet raus, welche IP Adresse der Pi in eurem Netzwerk bekommen hat und gebt ihm einen statischen Lease.
Meldet euch dann per SSH auf dem Gerät an, ändert das Passwort des Users, ladet euren SSH Key hoch, das übliche halt.
Benötigte Software installieren
Wir benutzten den XaiomiMi-Data-Collector um die Daten einzusammeln.
Klont euch also das Repository.
sudo apt update -y ; sudo apt upgrade -y; sudo apt autoremove -y; apt install git openvpn git clone https://github.com/Zentris/XaiomiMi-Data-Collector
Installiert dann die benötigten Python bibliotheken.
sudo apt install python3-pip sudo pip3 install paho-mqtt sudo pip3 install influxdb sudo pip3 install PyMySQL
Jetzt installieren wir eine lokale Datenbank, mit der das script arbeiten kann.
sudo apt install mariadb-server
SQL Datenbank einrichten
Meldet euch an der Datenbank an legt eine SQL Datenbank, einen User an und gebt dem User Rechte auf die Datenbank.
CREATE DATABASE flowerberry; CREATE USER 'floweradmin'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD_HERE'; GRANT ALL PRIVILEGES ON flowerberry.* TO 'floweradmin'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD_HERE'; FLUSH PRIVILEGES;
Dafür sorgen, dass der Pi mit der InfluxDB reden kann
Sollten sich die InfluxDB und der Pi im gleichen Netzwerk befinden, kann dieser Punkt übersprungen werden.
Da das bei mir allerdings nicht der Fall ist, dokumentiere ich ihn mit.
An dieser Stelle möchte ich das Geniale Script openvpn-install empfehlen.
Es richtet auf einem Linux Server ein OpenVPN Gateway ein und bringt eine Zertifikatsverwaltung mit.

Verschiebt dieses Zertifikat dann auf dem Pi nach /etc/openvpn/ und nennt es client.conf
sudo mv /home/pi/flowerchan.ovpn /etc/openvpn/client.conf
Legt dann die Datei /etc/systemd/system/multi-user.target.wants/openvpn@client.service mit folgendem Inhalt an, um ein systemd unit file zu erzeugen.
[Unit] Description=OpenVPN connection to %i PartOf=openvpn.service ReloadPropagatedFrom=openvpn.service Before=systemd-user-sessions.service After=network-online.target Wants=network-online.target Documentation=man:openvpn(8) Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO [Service] Type=notify PrivateTmp=true WorkingDirectory=/etc/openvpn ExecStart=/usr/sbin/openvpn --daemon ovpn-%i --status /run/openvpn/%i.status 10 --cd /etc/openvpn --config /etc/openvpn/%i.conf --writepid /run/openvpn/%i.pid PIDFile=/run/openvpn/%i.pid KillMode=process ExecReload=/bin/kill -HUP $MAINPID CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE CAP_AUDIT_WRITE LimitNPROC=100 DeviceAllow=/dev/null rw DeviceAllow=/dev/net/tun rw ProtectSystem=true ProtectHome=true RestartSec=5s Restart=on-failure [Install] WantedBy=multi-user.target
Anschießend starten wir den service und schauen uns seinen Status an.
sudo systemctl start openvpn@client.service sudo systemctl status openvpn@client.service

Zuletzt müsst Ihr noch in /etc/default/openvpn die Zeile "AUTOSTART=ALL" einkommentieren:
Damit ist sichergestellt, dass der Pi sich wieder ins VPN einwählt, sollte er neu gestartet werden.
Konfiguration anpassen
Den Sensor finden
Meldet euch bei eurem Raspberry an und sucht nach der MAC Adresse eures Sensors.
1 sudo hcitool lescan

Schreibt euch diese MAC auf und markiert euch den Sensor, damit ihr ihn später irgendwie zuordnen könnt.
Wiederholt diesen Vorgang für alle Sensoren.
Konfigurationsdatei anpassen
Ändert in der Datei /home/pi/XaiomiMi-Data-Collector/Raspi/config.cfg folgende Werte:
Eine IP die in eurem LAN erreichbar ist und die MAC Addressen der Sensoren.
pingip = <pinable address into our home network> sens_1 = <mac of first sensor> sens_2 = <mac of second sensor> ...
Die InfluxDB Zugangsdaten:
influxHost = <IP of your influx DB> influxUser = <our admin user> influxPassword = <our admin password> influxDbName = <our influx db name for the measurement data> influxDbUser = <our influx db user for the measurement data> influxDbPassword = <our influx db password for the measurement data> influxMeasurement = <our influx measurement section name>
Die Datenbank Zugangsdaten:
DbHost = 127.0.0.1 DbUser = floweradmin DbPassword = YOUR_PASSWORD_HERE DbName = flowerberry DbTableName = Sensordaten
Sensordaten manuell auslesen
Geht nach /home/pi/XaiomiMi-Data-Collector/Raspi/ und ruft das python script XiaomiMiReader.py auf.

ACHTUNG: es ist wichtig, dass ihr vorher in das Verzeichnis wechselt. Das script ist da sehr penibel und ihr könnt keinen absoluten oder relativen Pfad verwenden.

Sensordaten automatisiert auslesen
Wegen der grade beschrieben Problematik, wenden wir allerdings einen kleinen Hack an.
Erzeugt die Datei /home/pi/XaiomiMi-Data-Collector/Raspi/hack.sh mit folgendem Inhalt.
#!/bin/sh cd /home/pi/XaiomiMi-Data-Collector/Raspi python3.7 XiaomiMiReader.py
Dann fügen der Datei /etc/crontab eine Zeile hinzu, mit der das Script einmal pro Minute ausgeführt und unsere Daten in die InfluxDB gepusht werden.
#Get all the flowery data :) *<nowiki>* * * * root /home/pi/XaiomiMi-Data-Collector/Raspi/hack.sh > /dev/null 2>&1</nowiki>
Grafana
Daten auslesen
Um die Daten nun anzeigen zu lassen, bauen wir uns ein Board in Grafana.
Hier wäre mal eine View die alle verfügbaren Daten für zwei Sensoren ausliest.
Bachtet, dass in der Fusszeile ein Zeitintervall von 1m ausgewählt ist.

Für eine Vergleichsübersicht ist das ganz nett.
Hier mal die Daten über eine Woche.

Allerdings vergleichen wir hier, wie mein Mathelehrer immer sagte "Äpfel mit Birnen".
Also bauen wir uns für alle Werte eigene Boards.
Daten interpretieren
Hier mal beispielhaft die Query für Feuchtigkeit.

Auf der Linken Seite ist der Reiter "Visualsation" ausgewählt und ich habe die Achsbeschriftung auf "percent(0-100) gestellt.
Damit ergibt der Graph auch Sinn. Er zeigt den Feuchtigkeitsgehalt des Bodens in Prozent an.
Lesenswerte Links zu dem Thema "was für Daten bekomme ich da eigentlich"
https://blog.endaq.com/how-light-sensors-work
https://www.lampenwelt.de/ratgeber/lux-einfach-erklaert.html
http://citrusindustry.net/2017/07/10/understanding-soil-moisture-sensor-data/
Alarme definieren
Damit Ihr eine Mail bekommt, wenn eure Blumen durstig sind, könnt Ihr folgendermaßen einen Alarm definieren.
Das sind Erfahrungswerte. Ich habe bei den Werten bereits mehrfach nachjustiert.

Cheers,
Ori
Externe mit LUKS vollverschlüsselte Festplatte unter Ubuntu 20 mounten
Komfortabler Weise nimmt einem Ubuntu die meiste Arbeit bereits ab, wenn es um das Mounten verschlüsselter Platten geht.
Schließt man eine solche an, so begrüßt einen ein Passwort prompt und mountet dann die /boot partition

Die anderen Partitionen werden allerdings nicht gemountet.

Darum sehr Ihr auf der Platte erstmal nur den Kernel, die InitRD, Grub etc.
Um die anderen Partitionen zu mounten, macht zunächst ein lvscan um auf angeschlossenen Block Devices nach logical volumes zu suchen.

Ihr könnt sehen, dass es aktive, nicht gemountete LVMs gibt.
Mit vgchange -ay könnt Ihr die aktiven Volumegroups listen, dadurch bekommt Ihr die namen der LGs raus.
In /dev/mapper sind softlinks, die auf devices pointen.
Mountet dann das Device, dessen Softlink vom Namen her zu der Partition Passt, die Ihr mounten wollt.

Jetzt könnt Ihr auf die Daten der Partition zugreifen :)
Cheers,
Ori
Mounting external LUKS encrypted drive on Ubuntu 20
Conveniently in Ubuntu Desktop OS's if you connect an external whole disk encrypted drive, it will ask you to input a password and mount it.

So far so convenient.
However it does not mount all partitions, but ony the boot partition.

This is why you can only see the the kernel, the init ramdisk, grub etc.
To mount the other partitions first use lvscan to scan for logical volumes on all connected block devices.

You can see that one LG (logical group) is currently mounted, the other is not. Using vgchange -ay you can list the active volumegroups to get thier label.
The label is a softlink for a device. You need the devicename to mount the partition. Then check the content of /dev/mapper to see the device name.
Then create a mountpoint and mount the partition.

And now you can access the content of that partition :)
Cheers,
Ori
Integration of collabora online on a Nextcloud behind NAT on a KVM hypervisor
This one had me struggle quite a bit.
I felt like this is something that cannot possibly be super hard to setup.
Before running Nextcloud in a VM I remember the setup to be quite trivial.
And once again it has proven to be true that there are only three networking issues. DNS DNS and DNS. But lets take a step back.
I am running a Nextcloud for my family and wanted to integrate collabora.
This is the How-To I used: https://www.linuxbabe.com/cloud-storage/integrate-collabora-online-server-nextcloud-ubuntu-16-04
Collabora, much like Google Docs or Office365, enables you to edit documents online in your browser. Collabora is a child of Libreoffice Online. The Idea is to still perform well even if 20 people or more are working on a document simultaneously.
The average collabora installation guide is using the collabora\code docker container. It expect you to run it in a "classical" nextcloud setup in wich the Apache or Nginx Server is run on the Aplication Layer of the Host Operating System of the Server.

In such a setup the docker container is running in the kernelspace of the host machine that is hooked up to the internet.

If we now add a layer of virtualisation things become a little more tricky.

The docker container is still running in the same kernelspace as the nextcloud instance. However the NAT is having some effects on the DNS resolution.
The docker container gets run using the hostname for the subdomain that will be used by the webserver for the rewrite rules interacting with the docker container.
sudo docker run -t -d -p 127.0.0.1:9980:9980 -e 'domain=nextcloud\\.your-domain\\.com' --restart always --cap-add MKNOD collabora/code
If we run this setup without nat, the docker container can resolve nextcloud.your-domain.com to 127.0.0.1.
Then the container can speak to the nextcloud using the loopback interface.
Behind a nat, this is not working.
A simple change does the trick.
We will have to edit the hosts file inside the docker conainer.
EDIT: Docker has a parameter to perform this task (since version 17) called --add-host. Using this option your changes wont be lost if the container restarts (e.g. if the host reboots). Lets say the IP of your Nextcloud behind the NAT is 192.168.122.10. Then you will have to start the container like this:
sudo docker run -t -d -p 127.0.0.1:9980:9980 -e 'domain=nextcloud\\.your-domain\\.com' --restart always --cap-add MKNOD --add-host=nextcloud.your-domain.com:192.168.122.10 --add-host=office.your-domain.com:192.168.122.10 collabora/code
General container debugging
EDIT: I will leave this bit in for general purpose docker container debugging.
Check docker ps -a to find the name the collabora docker container has been assigned. Then start a shell inside the container using docker exec -i -t <ContainerName> /bin/bash.
There we edit the /etc/hosts file and add two lines.
One for office.your-domain.com and one for nextcloud.your-domain.com. It worked best for me using the IP address of the virtual machine.
Beeing lazy I did run apt update and apt install vi to have an editor inside of the container. You could also just echo it into the hosts file.

Afterwards you also need to edit the /etc/hosts file of the VM.
To be able to properly communicate with the container I had to have office.your-domain.com resolve to 127.0.0.1 rather then my public IP.

Cheers,
Ori
Integration von Collabora Online auf einer Nextcloud hinter NAT auf KVM
Ich habe mir an diesem Thema etwas die Zähne ausgebissen.
Das kann doch nicht so schwer sein dachte ich mir.
Bevor ich Nextcloud virtualisiert habe erinnere ich daran, dass das Setup relativ trivial war.
Ich bin nach folgender Anleitung vorgegangen: https://www.linuxbabe.com/cloud-storage/integrate-collabora-online-server-nextcloud-ubuntu-16-04
Und wieder stellte sich heraus, es gibt nur drei Probleme im Netzwerk.
DNS, DNS und DNS. Aber treten wir einen Schritt zurück.
Ich betreibe eine Nextcloud für meine Familie und wollte dort Collabora Einrichten.
Collabora ermöglicht es, ähnlich wie Google Docs oder Office365, Dokumente online im Browser zu editieren. Vater des Kindes ist Libreoffice Online. Collabora hat zum Ziel auch dann noch gut zu performen, wenn es mehr als 20 Personen Zeitgleich nutzen.
Die standart Collabora Installationsanleitung ist darauf ausgelegt, dass Collabora als Docker Container läuft. Es wird von einem "Klassischen" Nextcloud setup ausgegangen, bei dem der Apache oder Nginx Webserver "Bare Metal" also direkt in der Anwendungsschicht des Hostbetriebssytems läuft.

Bei so einem Setup würde der Docker Container dann im Kernelspace des Hosts laufen.

Wenn wir jetzt allerdings eine Virtualisierungsschicht hinzufügen wird das ganze etwas komplexer.

Es läuft zwar noch immer der Docker Container im gleichen Kernelspace wie die Nextcloud Instanz, allerdings hat das NAT besondere Auswirkungen auf die DNS Auflösung.
Der Container wird mit dem Hostname der Subdomain für die Collabora Instanz gestartet.
sudo docker run -t -d -p 127.0.0.1:9980:9980 -e 'domain=nextcloud\\.your-domain\\.com' --restart always --cap-add MKNOD collabora/code
Wenn wir dies im Setup ohne NAT ausführen, kann der Docker Container nextcloud.your-domain.com zu 127.0.0.1 auflösen.
Dann kann der Container über die Loopbackaddresse mit der Nextcloud Instanz sprechen. Hinter dem NAT kann er dies allerdings nicht umsetzen.
Eine mögliche Lösung ist es, die Hosts Datei des Docker Containers um eine statische IP Addresse zu erweitern.
EDIT: Docker bietet (seit Version 17) eine Funktion an um dies zu erledigen. Sie nennt sich --add-host. So gehen die Einstellungen auch bei Neustart des Containers (z.b. durch Neustart des Hosts) nicht verloren. Sagen wir die IP eurer Nextcloud hinter dem NAT ist 192.168.122.10. Somit müsst ihr den Container folgendermaßen starten:
sudo docker run -t -d -p 127.0.0.1:9980:9980 -e 'domain=nextcloud\\.your-domain\\.com' --restart always --cap-add MKNOD --add-host=nextcloud.your-domain.com:192.168.122.10 --add-host=office.your-domain.com:192.168.122.10 collabora/code
Generelles Container-debugging
EDIT: Ich lasse diesen Teil mal als generellen Container Debugging Teil in dem Artikel.
Geht auf die Maschine mit dem Docker Container und startet eine bash innerhalb des Containers.
Mit docker ps -a schauen wir uns an, welchen Namen der Container hat.
Anschließend starten wir mit docker exec -i -t <ContainerName> /bin/bash innerhalb des Containers eine shell. Dort editieren wir dann die /etc/hosts datei. Tragt office.your-domain.com und nextcloud.your-domain.com jeweils die IP Adresse der Virtuellen Maschine ein.
Ich habe mir der faulheit halber einfach mit apt update und apt install vi einen Texteditor hierzu im Container nachinstalliert. Ihr könnt es natürlich auch rein echoen.

Anschließend solltet Ihr noch die /etc/hosts datei der VM editieren.
Damit Ihr direkt mit dem Container sprecht, solltet Ihr office.your-domain.com direkt gegen 127.0.0.1 auflösen lassen.
Dann klappts auch mit den Nachbarn.

Cheers,
Ori
Setup Grafana on Ubuntu 18.04 with LetsEncrypt
In this article I will show you how to get the data visualisation solution Grafana to work with clean HTTPS on Ubuntu 18.04.
As alwaysI recommend not running the service natively on your server but rather to run it in a VM.
Installation
Simply follow along the instructions of the official guide on the Grafana website.
LetsEncrypt
To secure our webserver with valid SSL certificates we generate an certificate using LetsEncrypt
Ubuntu comes with certbot installed nativley.
sudo certbot certonly -d your.website
Write down the fullchain.pem and privkey.pem path.
You will later put that into the grafana.ini configuration file.
Before we do that, we have to make sure grafana can access these certificates.
To do that we create a new group.
sudo groupadd sslcerts
/etc/letsencrypt is owned by the user root and the group root.
We will change the group ownership recursivley to sslcerts.
user chown -R root:sslcerts /etc/letsencrypt/
Now we will add the user grafana (added when installing grafana) to this grop.
sudo usermod -G sslcerts -a grafana
Now we will have to adjust the permissions of /etc/letsencrypt/live and /etc/letsencrypt/archive
sudo chmod 755 /etc/letsencrypt/live
sudo chmod 755 /etc/letsencrypt/archive
Editing the configfile /etc/grafana/grafana.ini
You will have to change the following lines:
30 [server]
31 # Protocol (http, https, socket)
32 protocol = https
37 # The http port to use
38 http_port = 443
40 # The public facing domain name used to access grafana from a browser
41 domain = your.grafana.url
47 # The full public facing url you use in browser, used for redirects and emails
48 # If you use reverse proxy and sub path specify full url (with sub path)
49 root_url = https://your.grafana.url
60 # https certs & key file
61 cert_file = /etc/letsencrypt/live/your.grafana.url/fullchain.pem
62 cert_key = /etc/letsencrypt/live/your.grafana.url/privkey.pem
Empowering Grafana to bind 443
The grafana service is not running as root.
This is why in the default configuration a ein highport is beeing used for the webserver.
But we want to use 443...
To do this without granting grafana super user, we explicitly allow it to bind ports below 1024 using setcap.
sudo setcap 'cap_net_bind_service=+ep' /usr/sbin/grafana-server
Further read:
https://wiki.apache.org/httpd/NonRootPortBinding
https://wiki.archlinux.org/index.php/Capabilities
Now, finally, restart the grafana service.
sudo systemctl restart grafana-server.service
If you have done everything right, a clean HTTPS should be greeting you.
If it does not work, a look into the logfile can be quite helpful.
sudo tail -f /var/log/grafana/grafana.log
At this webinterface you can now login using admin admin.
You will be asked to change that password on the first login.
Now you can carry on using this guid: https://grafana.com/docs/guides/getting_started/
Cheers,
Ori
Grafana auf Ubuntu 18.04 mit LetsEncrypt einrichten
In diesem Artikel möchte ich kurz darauf eingehen, wie man die Datenvisualisierungslösung Grafana mit sauberem HTTPS auf Ubuntu 18.04 aufsetzen kann.
Ich würde euch wie immer empfehlen Dienste nicht Nativ auf einem Server laufen zu lassen sondern zu Virtualisieren.
Siehe: Virtualisieren mit KVM
Installation
Wir gehen einfach nach der Offiziellen Anleitung auf der Grafana Website vor.
LetsEncrypt
Um unsere Seite mit einem Validen SSL Zertifikat laufen zu lassen, generieren wir ein Zertifikat mit LetsEncrypt.
Certbot ist bei ubuntu 18.04 bereits vorinstalliert.
sudo certbot certonly -d your.website
Die Pfade der fullchain.pem und privkey.pem solltet Ihr euch merken.
Diese tragen wir gleich in die grafana.ini ein.
Zunächst müssen wir aber noch dafür sorgen, dass Grafana auf die Zertifikate zugreifen kann.
Dazu erstellen wir zunächst eine neue Gruppe.
sudo groupadd sslcerts
/etc/letsencrypt gehört dem user root und der gruppe root.
Wir ändern jetzt die Gruppe von /etc/letsencrypt rekursiv auf sslcerts.
user chown -R root:sslcerts /etc/letsencrypt/
Anschließend fürgen wir den Benutzer grafana (wird bei der Grafana Installation angelegt) dieser Gruppe hinzu.
sudo usermod -G sslcerts -a grafana
Jetzt müssen wir noch die Permissions auf /etc/letsencrypt/live und /etc/letsencrypt/archive anpassen.
sudo chmod 755 /etc/letsencrypt/live
sudo chmod 755 /etc/letsencrypt/archive
Anpassung der /etc/grafana/grafana.ini
In der Grafa Konfigurationsdatei müsst ihr nun folgende Zeilen anpassen:
30 [server]
31 # Protocol (http, https, socket)
32 protocol = https
37 # The http port to use
38 http_port = 443
40 # The public facing domain name used to access grafana from a browser
41 domain = your.grafana.url
47 # The full public facing url you use in browser, used for redirects and emails
48 # If you use reverse proxy and sub path specify full url (with sub path)
49 root_url = https://your.grafana.url
60 # https certs & key file
61 cert_file = /etc/letsencrypt/live/your.grafana.url/fullchain.pem
62 cert_key = /etc/letsencrypt/live/your.grafana.url/privkey.pem
Grafana die Möglichkeit geben 443 zu binden
Der Grafana Dienst wird nicht als root ausgeführt, darum wird in der defaultconfig auch ein highport verwendet.
Wir wollen aber 443 nutzen...
Daher erlauben wir grafana explizit, dass es das darf mit setcap.
sudo setcap 'cap_net_bind_service=+ep' /usr/sbin/grafana-server
Siehe:
https://wiki.apache.org/httpd/NonRootPortBinding
https://wiki.archlinux.org/index.php/Capabilities
Startet anschließend den Grafana dienst neu.
sudo systemctl restart grafana-server.service
Wenn Ihr alles richtig gemacht habt, sollte euch ein sauberes HTTPS begrüßen.
Falls nein, hilft es sich das log anzusehen.
sudo tail -f /var/log/grafana/grafana.log
An dieser Weboberfläche solltet Ihr euch jetzt mit admin admin einloggen können.
Ihr werdet daraufhin aufgefordert das Passwort zu ändern.
Jetzt könnt Ihr mit diesem Guide weitermachen: https://grafana.com/docs/guides/getting_started/
Cheers,
Ori
MaSSHandra Installation on Ubuntu 18.04 with LetsEncrypt
In this article I will describe how to get MaSSHandra running on an Ubuntu 18.04.
As alwaysI recommend not running the service natively on your server but rather to run it in a VM.
Preperation
First things first.
Update your sources and install pending updates.
sudo apt update -y && sudo apt upgrade -y
Now we install the following packages:
- Sendmail - will be used to send emails to the MaSSHandra users
- NodeJS - will run the services
- npm - Node packet manager, will be used to update NodeJS
- mysql - an SQL Server, that is going to hold MaSSHandras data
sudo apt install -y sendmail nodejs npm apache2 mysql
Now we empty the npm cache and install the current version of node.
sudo npm cache clean -f
sudo npm install -g n
The command node -v
should now be showing a Version above 10.0.
Clone the git repo to your home diretory.
git clone https://github.com/pablomarle/networkmaps
Now we create a few directories MaSSHandra is going to use.
sudo mkdir /etc/networkmaps/
sudo mkdir /sendmail/
sudo mkdir /sendmail/queue/
sudo mkdir /sendmail/sent/
sudo mkdir /diagrams/
SQL Database
First we are going to harden the SQL Database a bit.
Mysql comes with a script that is going to interactivley ask you a few settings to make it a bit more secure.
sudo mysql_secure_installation
Now login to mysql.
sql -u root -p
Create a database that MaSSHandra will later use to handle users.
create database users;
You can ofcourse use another database name then users if you want.
Just make sure that you use this altered name on the database import and later when configurung the config.json.
Logoff by typing
exit;
Import the sql database included in the git repo.
There are no users in there, however a bunch of tables that will handle users, passwords (binary64 with salt), diagrams and permissions.
mysql -u root -p users < ~/networkmaps/database_schema/users.sql
Now log back into mysql.
sql -u root -p
We will now create a SQL user that MaSSHandra can use to access the database.
Please change "YourMasshandraSqlPassword".
Here you can use a username of your choice that later will be put in the config.json.
CREATE USER 'masshandra'@'localhost' IDENTIFIED BY 'YourMasshandraSqlPassword';
GRANT ALL ON Users.* TO 'masshandra'@'localhost' IDENTIFIED BY 'YourMasshandraSqlPassword' WITH GRANT OPTION;
Then reload the sql permissions and exit mysql.
FLUSH PRIVILEGES;
EXIT;
LetsEncrypt
To secure our webserver with valid SSL certificates we generate an certificate using LetsEncrypt
Ubuntu comes with certbot installed nativley.
sudo certbot certonly -d your.website
MaSSHandra configuration
So far so prepearing.
Lets now head over to tweaking masshandras settings.
MaSSHandra is expecting a configuration file at /etc/networkmaps/config.json
So we copy the example config included in the git repo to that location.
sudo cp ~/networkmaps/docs/sample_config.json /etc/networkmaps/config.json
In it, change the settings marked in red: { "comment": "This file is expected to be in /etc/networkmaps", "timers": { "usertimeout": 3600, "savediagram": 300 }, "use_ssl_socket": true, "use_ssl": true, "socket": { "address": "IP OF YOUR SERVER", "port": "3000", "cert": "/etc/letsencrypt/live/your.website/fullchain.pem", "key": "/etc/letsencrypt/live/your.website/privkey.pem" }, "server": { "hostname": "your.website", "port": 3000 }, "staticserver": { "hostname": "your.website", "port": 443 }, "db": { "users": { "database": "users", "host": "localhost", "user": "masshandra", "password": "YourMasshandraSqlPassword" } }, "diagrams": { "path": "/diagrams/" }, "sendmail": { "queue": "/sendmail/queue/", "sent": "/sendmail/sent/", "server": "your.mailserver", "port": 465, "is_secured": true, "user": "mailuser@your.mailserver", "password": "YourMailPassword", "from": "your.website.url <noreply@your.website.url>" } }
Starting the server
Now we start the services that will open a websocket on :3000 and handle the emails.
sudo node ~/networkmaps/server.js
sudo node ~/networkmaps/smtp_daemon.js
Remember that you can send the processes to the background by appending & to the command.
Leave them as they are if you want to debug.
When you now head over to your MaSSHandra instance and register a user, you sould see some logs.
Once you confirmed the Email you should be able to login and use MaSSHandra.
Cheers,
Ori