Pour gérer les retours de DMARC, on peut utiliser parsedmarc, graphana et postgresql

Pré-requis:

  • Postfix
  • Dovecot
  • OpenDKIM,
  • OpenDMARC,
  • Apache 2.4,
  • PHP 8.4 FPM,
  • Python 3.13.5.
  • PostgreSQL
  • doivent être fonctionnel

Partie base de données:
2 utilisateurs, un sera en lecture seule qui sera utilisé pour le web
CREATE ROLE parsedmarc LOGIN PASSWORD 'MOT_DE_PASSE_PG';
CREATE DATABASE parsedmarc OWNER parsedmarc;
CREATE ROLE dmarcweb LOGIN PASSWORD 'MOT_DE_PASSE_WEB';
GRANT CONNECT ON DATABASE parsedmarc TO dmarcweb;
GRANT USAGE ON SCHEMA public TO dmarcweb;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO dmarcweb;
ALTER DEFAULT PRIVILEGES FOR ROLE parsedmarc IN SCHEMA public
GRANT SELECT ON TABLES TO dmarcweb;
Penser à donner les droits dans pg_hba.conf
 
Partie parsedmarc:
Compte et paquet parsedmarc:
useradd --system --create-home --home-dir /opt/parsedmarc  --shell /usr/sbin/nologin parsedmarc
python3 -m venv /opt/parsedmarc/venv
/opt/parsedmarc/venv/bin/pip install --upgrade pip
/opt/parsedmarc/venv/bin/pip install parsedmarc
chown -R parsedmarc:parsedmarc /opt/parsedmarc
Le binaire est /opt/parsedmarc/venv/bin/parsedmarc. Le cache de la base IP est /opt/parsedmarc/.cache/parsedmarc.
Configuration parsedmarc:
/etc/parsedmarc/parsedmarc.ini:

[general]
save_aggregate = True
save_failure = True
save_smtp_tls = True
always_use_local_files = True

[mailbox]
reports_folder = FBL/DMARC
archive_folder = FBL/DMARC-Archive
delete = False
batch_size = 10

[imap]
host = 127.0.0.1
user = Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.
password = MOT_DE_PASSE_IMAP
ssl = True

[postgresql]
host = pg.leclosdulys.pra.rip
port = 5435
user = parsedmarc
password = MOT_DE_PASSE_PG
database = parsedmarc
sslmode = require
sslrootcert = /etc/ssl/certs/ca-certificates.crt

Pensez à mettre un certificat signé par une autorité de certification pour postfix, vous pouvez regarder : PostgreSQL: utiliser un certificat signé par une autorité de certification
propriétaire / groupe / droits:
chown root:parsedmarc /etc/parsedmarc/parsedmarc.ini
chmod 640 /etc/parsedmarc/parsedmarc.ini
Service et timer pour parsedmarc:
service: /etc/systemd/system/parsedmarc.service

[Unit]
Description=parsedmarc
After=network-online.target postgresql.service
Wants=network-online.target

[Service]
Type=oneshot
User=parsedmarc
Group=parsedmarc
Environment=HOME=/opt/parsedmarc
ExecStart=/opt/parsedmarc/venv/bin/parsedmarc -c /etc/parsedmarc/parsedmarc.ini --verbose
TimeoutStartSec=30min
Nice=10

(Environment=HOME=/opt/parsedmarc est nécessaire : le cache de la base IP est cherché sous ~/.cache/parsedmarc.)
timer: /etc/systemd/system/parsedmarc.timer:

[Unit]
Description=parsedmarc toutes les 15 minutes

[Timer]
OnBootSec=5min
OnUnitActiveSec=15min
Persistent=true

[Install]
WantedBy=timers.target

activation:
systemctl daemon-reload
systemctl enable --now parsedmarc.timer
 
Partie graphana:
Installation: paquets et dépôts
apt install -y apt-transport-https gnupg curl
mkdir -p /etc/apt/keyrings
curl -fsSL https://apt.grafana.com/gpg.key | gpg --dearmor -o /etc/apt/keyrings/grafana.gpg
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main"  > /etc/apt/sources.list.d/grafana.list
apt update
apt install -y grafana
systemctl enable --now grafana-server
configuration:
/etc/grafana/grafana.ini, dans la section `[server]`:
[server]
http_addr = 127.0.0.1
http_port = 3000
domain = votre-domaine.tld
root_url = https://votre-domaine.tld/
/etc/grafana/provisioning/datasources/parsedmarc.yaml:

apiVersion: 1

datasources:
  - name: parsedmarc-pg
    uid: parsedmarc-pg
    type: postgres
    url: your_postgres_server:port
    user: dmarcweb
    secureJsonData:
      password: 'MOT_DE_PASSE_WEB'
    jsonData:
      database: parsedmarc
      sslmode: require
      postgresVersion: 1800

tableau de bord
curl -L -o /root/dmarc-pg.json \
  https://raw.githubusercontent.com/domainaware/parsedmarc/master/dashboards/grafana/Grafana-DMARC_Reports-PostgreSQL.json
mkdir -p /var/lib/grafana/dashboards
sed 's/${DS_POSTGRESQL}/parsedmarc-pg/g' /root/dmarc-pg.json > /var/lib/grafana/dashboards/dmarc-pg.json
chown -R grafana:grafana /var/lib/grafana/dashboards
/etc/grafana/provisioning/dashboards/parsedmarc.yaml:
apiVersion: 1
providers:
  - name: parsedmarc
    orgId: 1
    folder: DMARC
    type: file
    updateIntervalSeconds: 30
    options:
      path: /var/lib/grafana/dashboards
Activation / mise en service:
systemctl restart grafana-server
Réinitialisation du mot de passe admin:
grafana cli admin reset-admin-password 'NOUVEAU_MOT_DE_PASSE'
systemctl restart grafana-server
 
Partie Apache:
Activation du module proxy d'apache:
a2enmod proxy proxy_http
Votre vhost: /etc/apache2/sites-available/<votre_vhost>.conf
<VirtualHost *:443>
    ServerName <votre_sous-domaine.tld>
    SSLEngine on
    SSLCertificateFile      <votre_certificat_au_format_pem>
    SSLCertificateKeyFile   <votre_cle_privé>
    SSLCertificateChainFile <votre_certificat_intermédiaire>
    SSLUseStapling on
    Protocols h2 http/1.1
    ProxyPreserveHost On
    ProxyPass        / http://127.0.0.1:3000/
    ProxyPassReverse / http://127.0.0.1:3000/
    ErrorLog  ${APACHE_LOG_DIR}/<votre_vhost>error.log
    CustomLog ${APACHE_LOG_DIR}/<votre_vhost>-access.log combined
</VirtualHost>
Activation du vhost:
a2ensite rapport-dmarc
apache2ctl configtest && systemctl reload apache2