HOAB

History of a bug

Raspberry as network monitor

Rédigé par gorki Aucun commentaire

Problem :

I built a network monitoring solution following this guides :

Truly, a great job.

But I has build the solution at home for another network, I would like that my raspberry start and monitor at boot. And I missed in the comments or text a few thing.

Solution :

I created services as described in the comment for prometheus, add another for the tcpdump. Don't forget prometheus working directory in this configuration (no specific user for prometheus).
 

[Unit]
Description=Prometheus
After=tcpdump.service

[Service]
User=pi
Group=pi
Type=simple
WorkingDirectory=/home/pi/prometheus/prometheus-2.23.0.linux-armv7
ExecStart=/home/pi/prometheus/prometheus-2.23.0.linux-armv7/prometheus \
    --config.file /home/pi/prometheus/prometheus.yml

[Install]
WantedBy=multi-user.target
/etc/systemd/system/tcpdump.service

[Unit]
Description=TCPDump service for traffic monitoring
After=network-online.target
[Service]
Type=idle
ExecStart=python3 /home/pi/network-traffic-metrics/network-traffic-metrics.py "(src net 192.168.10.0/24 and not dst net 192.168.10.0/24) or (dst net 192.168.10.0/24 and not src net 192.168.10.0/24)"
[Install]
WantedBy=default.target

But I had some network issues :

First, disable dhcpcd and install isc-dhcp-server

In my case, I keep dhcpcd as it mount the network interfaces eth0 & eth1. I also put a no gateway on eth0 (my lan part)

My dhcpcd.conf configuration for interfaces :


interface eth1
static ip_address=192.168.1.10
static routers=192.168.1.1
static domain_name_servers=1.1.1.1
static domain_search=1.1.1.1

interface eth0
static ip_address=192.168.10.1
static routers=192.168.10.1
static domain_name_servers=1.1.1.1
static domain_search=1.1.1.1
nogateway

But with this configuration, at boot :

  • isc-dhcp-server and tcpdump

were not started because eth0 was not up or plugged. In my case, I could plug eth0 later.

So I took a while, but I found the network hook that works (forget all /etc/network thing, dhcpcd do not use it).

Create a file (not a directory...) called /etc/dhcpcd.exit-hook with

#!/bin/bash

if [ "$interface" = "eth0" & "$reason" = "STATIC" & "$if_up" = "true" ]
then
	systemctl start tcpdump
	systemctl start isc-dhcp-server.service
fi 

And all is starting when eth0 is going up.

Monitoring des processus

Rédigé par gorki Aucun commentaire

Le problème :

Légèrement décrit ici : http://hoab.fr/shaarli/?TrwlkA

En réalité suivant le mode de protection, la solution ci-dessus ne marche pas.

Solution :

Si on a un noyau normal, alors hidepid n'est pas *encore* activé par défaut. Dans ce cas, tous les utilisateurs voient les processus et le problème n'existe pas.

Si le mode hidepid a été activé, l'activation de l'option gid permet d'avoir un groupe priviligé qui permet ceci.

Si le patch grsecurity est activé (si on trouve un -grs dans le nom du noyau "uname -a") c'est plus compliqué :

  • si le noyau a été compilé avec un groupe priviligié : retrouver ce groupe et on a le même comportement que le hidepid
  • sinon :
    • recompiler le noyau pour l'ajouter
    • changer de noyau pour avoir une version sans grs
    • utiliser les mécanismes des sudoers (http://hoab.fr/shaarli/?qBeGWA)

J'ai choisi la dernière solution dans un premier temps, le problème étant de reprendre un noyau avec les mêmes options que celui qui existe...

 

Fil RSS des articles de ce mot clé