mirror of
https://github.com/deunix-educ/Fail2banMqttActionBanishment.git
synced 2026-08-24 03:11:58 +02:00
40 lines
1.5 KiB
Bash
Executable File
40 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# master-ca-init.sh — initialise la CA privée du broker master (Phase 3),
|
|
# utilisée uniquement pour signer les certificats clients des noeuds (mTLS).
|
|
# Distincte du certificat Let's Encrypt du broker (qui sert l'identité TLS
|
|
# serveur, pas l'authentification des clients).
|
|
#
|
|
# À lancer UNE SEULE FOIS sur le VPS master. Usage : sudo ./master-ca-init.sh [répertoire CA]
|
|
|
|
set -euo pipefail
|
|
|
|
CA_DIR="${1:-/etc/mosquitto/master-ca}"
|
|
|
|
if [ -f "$CA_DIR/ca.key" ]; then
|
|
echo "CA déjà présente dans $CA_DIR — rien à faire." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! getent group mosquitto >/dev/null; then
|
|
echo "Groupe système 'mosquitto' introuvable — le paquet mosquitto doit être installé avant." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Le process mosquitto (utilisateur dédié 'mosquitto', pas root) doit pouvoir
|
|
# lire ca.crt pour vérifier les certificats clients (cafile du listener
|
|
# 8883) — d'où le groupe 'mosquitto' sur le répertoire et sur ce fichier.
|
|
# ca.key (la clé privée de la CA, qui sert à SIGNER de nouveaux certificats
|
|
# clients via generate-node-cert.sh) reste root-only : mosquitto n'en a
|
|
# jamais besoin.
|
|
install -d -o root -g mosquitto -m 750 "$CA_DIR"
|
|
openssl genrsa -out "$CA_DIR/ca.key" 4096
|
|
openssl req -x509 -new -nodes -key "$CA_DIR/ca.key" -sha256 -days 3650 \
|
|
-subj "/CN=Fail2banActionBanishment Master CA" \
|
|
-out "$CA_DIR/ca.crt"
|
|
chown root:root "$CA_DIR/ca.key"
|
|
chmod 600 "$CA_DIR/ca.key"
|
|
chown root:mosquitto "$CA_DIR/ca.crt"
|
|
chmod 640 "$CA_DIR/ca.crt"
|
|
|
|
echo "CA créée dans $CA_DIR (ca.crt à référencer comme cafile du listener 8883)."
|