Agent DNS - load_config() lit maintenant la section `redis` du config.yaml (host, port, password, ssl, ssl_ca_cert, ssl_certfile, ssl_keyfile) → l'agent ne tombait plus sur localhost:6379 par défaut - Suppression de retry_on_timeout (déprécié redis-py 6.0) - Suppression de socket_keepalive_options (clés string invalides) - int() forcé sur port et db dans run() pour éviter TypeError - Traceback complet sur fatal error - get_state: relativize=False → dnspython conserve les FQDN complets - get_state: parse les enregistrements "; [DISABLED]" pour les inclure avec active=False dans le state retourné - _fmt_value: ne ajoute plus le point final sur les noms relatifs (srvweb → reste srvweb, srvweb.infolix.fr → srvweb.infolix.fr.) - save_zone_raw: named-checkzone + snapshot (même logique qu'apply_zone) - gen_certs.sh: REDIS_HOST obligatoire, détection IP vs FQDN pour le SAN Backend DNS - _sync_zone_from_state: normalise les noms FQDN → court avant _stable_id (mail.infolix.fr. → mail pour correspondre à ce qui est en BDD) - _sync_zone_from_state: active=%s au lieu de COALESCE(active,1) → les enregistrements désactivés importés depuis le fichier de zone sont correctement marqués active=0 en BDD Frontend - App.jsx: VITE_API_BASE prioritaire sur localStorage - validateRecord: accepte les noms relatifs sans point pour CNAME/MX/NS
189 lines
9.2 KiB
Bash
189 lines
9.2 KiB
Bash
#!/bin/bash
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# NetAdmin — Script d'installation SERVEUR PRINCIPAL (front + backend)
|
|
# Usage : sudo bash install.sh
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
set -e
|
|
|
|
NETADMIN_DIR="/opt/netadmin"
|
|
NETADMIN_USER="netadmin"
|
|
LOG_DIR="/var/log/netadmin"
|
|
CONFIG_DIR="/etc/netadmin"
|
|
FRONTEND_DIR="/var/www/netadmin"
|
|
|
|
echo "══════════════════════════════════════════"
|
|
echo " NetAdmin — Installation serveur principal"
|
|
echo "══════════════════════════════════════════"
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "✗ Ce script doit être exécuté en root (sudo)"
|
|
exit 1
|
|
fi
|
|
|
|
# ── Utilisateur système ────────────────────────────────────────────────────
|
|
echo "→ Création de l'utilisateur netadmin..."
|
|
id -u $NETADMIN_USER &>/dev/null || useradd -r -s /bin/false -d $NETADMIN_DIR $NETADMIN_USER
|
|
echo " ✓"
|
|
|
|
# ── Répertoires ────────────────────────────────────────────────────────────
|
|
echo "→ Création des répertoires..."
|
|
mkdir -p $NETADMIN_DIR/{backend,agents,venv}
|
|
mkdir -p $LOG_DIR
|
|
mkdir -p $CONFIG_DIR/certs
|
|
mkdir -p $FRONTEND_DIR
|
|
chown -R $NETADMIN_USER:$NETADMIN_USER $NETADMIN_DIR $LOG_DIR
|
|
chmod 750 $CONFIG_DIR
|
|
echo " ✓"
|
|
|
|
# ── Dépendances système ────────────────────────────────────────────────────
|
|
echo "→ Installation des dépendances..."
|
|
apt-get update -qq
|
|
apt-get install -y -qq python3 python3-venv python3-pip nodejs npm nginx redis-server
|
|
echo " ✓"
|
|
|
|
# ── Redis — configuration mTLS ────────────────────────────────────────────
|
|
echo "→ Configuration Redis..."
|
|
REDIS_CONF="/etc/redis/redis.conf"
|
|
|
|
# Écouter uniquement sur localhost (les agents se connectent via mTLS depuis l'extérieur)
|
|
sed -i 's/^bind 127.0.0.1 -::1/bind 0.0.0.0/' $REDIS_CONF
|
|
|
|
# Port mTLS
|
|
sed -i 's/^port 6379/port 0/' $REDIS_CONF # désactiver port plaintext
|
|
grep -q "^tls-port" $REDIS_CONF || cat >> $REDIS_CONF << 'REDISCONF'
|
|
|
|
# NetAdmin mTLS
|
|
tls-port 6380
|
|
tls-ca-cert-file /etc/netadmin/certs/ca.crt
|
|
tls-cert-file /etc/netadmin/certs/redis-server.crt
|
|
tls-key-file /etc/netadmin/certs/redis-server.key
|
|
tls-auth-clients yes
|
|
tls-protocols "TLSv1.2 TLSv1.3"
|
|
requirepass changeme_redis
|
|
REDISCONF
|
|
|
|
# Redis tourne en user redis:redis — lui donner accès aux certificats
|
|
# Le dossier /etc/netadmin/certs doit être lisible par redis
|
|
chown -R root:redis $CONFIG_DIR/certs
|
|
chmod 750 $CONFIG_DIR/certs
|
|
# La clé privée Redis uniquement lisible par redis
|
|
# (sera appliqué après gen_certs.sh)
|
|
|
|
systemctl enable redis-server
|
|
echo " ✓ Redis configuré sur :6380 (mTLS)"
|
|
echo " ⚠ Adapter 'requirepass' dans /etc/redis/redis.conf"
|
|
echo " ⚠ Après génération des certificats (gen_certs.sh) :"
|
|
echo " cp certs/redis-server.{crt,key} /etc/netadmin/certs/"
|
|
echo " chown redis:redis /etc/netadmin/certs/redis-server.key"
|
|
echo " chmod 640 /etc/netadmin/certs/redis-server.key"
|
|
|
|
# ── Environnement Python ───────────────────────────────────────────────────
|
|
echo "→ Virtualenv Python..."
|
|
python3 -m venv $NETADMIN_DIR/venv
|
|
$NETADMIN_DIR/venv/bin/pip install --quiet --upgrade pip
|
|
$NETADMIN_DIR/venv/bin/pip install --quiet -r $NETADMIN_DIR/backend/requirements.txt
|
|
echo " ✓"
|
|
|
|
# ── Frontend build ─────────────────────────────────────────────────────────
|
|
echo "→ Build du frontend..."
|
|
cd $NETADMIN_DIR/frontend
|
|
npm install --silent
|
|
npm run build --silent # utilise .env.production → VITE_API_BASE=/api
|
|
cp -r dist/* $FRONTEND_DIR/
|
|
chown -R www-data:www-data $FRONTEND_DIR
|
|
echo " ✓"
|
|
|
|
# ── Configuration ──────────────────────────────────────────────────────────
|
|
if [ ! -f $CONFIG_DIR/config.yaml ]; then
|
|
echo "→ Copie config.yaml..."
|
|
cp $NETADMIN_DIR/backend/config.yaml $CONFIG_DIR/config.yaml
|
|
chmod 640 $CONFIG_DIR/config.yaml
|
|
chown root:$NETADMIN_USER $CONFIG_DIR/config.yaml
|
|
echo " ✓ Éditer $CONFIG_DIR/config.yaml avant de démarrer"
|
|
else
|
|
echo "→ Configuration existante conservée."
|
|
fi
|
|
|
|
# ── Certificats mTLS Redis ─────────────────────────────────────────────────
|
|
if [ ! -f $CONFIG_DIR/certs/ca.crt ]; then
|
|
echo "→ Génération des certificats mTLS Redis..."
|
|
cd $CONFIG_DIR/certs
|
|
bash $NETADMIN_DIR/agents/gen_certs.sh .
|
|
# Permissions par défaut : root:netadmin lisible
|
|
chmod 640 *.key *.crt
|
|
chown root:$NETADMIN_USER *.crt *.key
|
|
# La clé Redis doit être lisible par l'user redis (qui démarre redis-server)
|
|
chown root:redis redis-server.key
|
|
chmod 640 redis-server.key
|
|
# Le dossier certs lisible par redis et netadmin
|
|
chown root:redis $CONFIG_DIR/certs
|
|
chmod 750 $CONFIG_DIR/certs
|
|
# L'utilisateur netadmin doit aussi pouvoir lire → ajouter au groupe redis
|
|
usermod -aG redis $NETADMIN_USER 2>/dev/null || true
|
|
echo " ✓ Certificats dans $CONFIG_DIR/certs/"
|
|
echo " ⚠ Copier sur les serveurs distants :"
|
|
echo " DNS : ca.crt + dns-agent.{crt,key}"
|
|
echo " Mail : ca.crt + mail-agent.{crt,key}"
|
|
else
|
|
echo "→ Certificats mTLS existants conservés."
|
|
fi
|
|
|
|
# ── Nginx ──────────────────────────────────────────────────────────────────
|
|
echo "→ Configuration Nginx..."
|
|
cp $NETADMIN_DIR/deploy/nginx-netadmin.conf /etc/nginx/sites-available/netadmin
|
|
[ ! -L /etc/nginx/sites-enabled/netadmin ] && \
|
|
ln -s /etc/nginx/sites-available/netadmin /etc/nginx/sites-enabled/netadmin
|
|
nginx -t && systemctl reload nginx
|
|
echo " ✓ Adapter /etc/nginx/sites-available/netadmin (FQDN, IPs autorisées)"
|
|
|
|
# ── Service systemd backend ────────────────────────────────────────────────
|
|
echo "→ Service systemd backend..."
|
|
cp $NETADMIN_DIR/deploy/netadmin-backend.service /etc/systemd/system/
|
|
cp $NETADMIN_DIR/deploy/log_config.yaml $NETADMIN_DIR/backend/
|
|
systemctl daemon-reload
|
|
systemctl enable netadmin-backend
|
|
echo " ✓"
|
|
|
|
# ── Logrotate ──────────────────────────────────────────────────────────────
|
|
cat > /etc/logrotate.d/netadmin << 'LOGROTATE'
|
|
/var/log/netadmin/*.log {
|
|
daily
|
|
rotate 30
|
|
compress
|
|
delaycompress
|
|
missingok
|
|
notifempty
|
|
create 0640 netadmin netadmin
|
|
postrotate
|
|
systemctl kill -s HUP netadmin-backend 2>/dev/null || true
|
|
endscript
|
|
}
|
|
LOGROTATE
|
|
echo "→ Logrotate ✓"
|
|
|
|
# ── Résumé ─────────────────────────────────────────────────────────────────
|
|
echo ""
|
|
echo "══════════════════════════════════════════"
|
|
echo " Installation terminée !"
|
|
echo "══════════════════════════════════════════"
|
|
echo ""
|
|
echo " Étapes suivantes :"
|
|
echo " 1. Éditer $CONFIG_DIR/config.yaml"
|
|
echo " - MariaDB, Redis, session_secret, NS, SOA admin"
|
|
echo " 2. Adapter Nginx :"
|
|
echo " nano /etc/nginx/sites-available/netadmin"
|
|
echo " → FQDN, IP autorisées"
|
|
echo " 3. Certificat SSL :"
|
|
echo " certbot --nginx -d netadmin.example.fr"
|
|
echo " 4. Démarrer le backend :"
|
|
echo " systemctl start netadmin-backend"
|
|
echo " 5. Distribuer les agents sur les serveurs distants :"
|
|
echo " scp -r agents/ deploy/ root@serveur-dns:/opt/netadmin-agent/"
|
|
echo " scp -r agents/ deploy/ root@serveur-mail:/opt/netadmin-agent/"
|
|
echo " scp $CONFIG_DIR/certs/ca.crt root@serveur-dns:/etc/netadmin/certs/"
|
|
echo " scp $CONFIG_DIR/certs/ca.crt root@serveur-mail:/etc/netadmin/certs/"
|
|
echo " # Puis sur chaque serveur distant :"
|
|
echo " sudo bash /opt/netadmin-agent/deploy/install-agent.sh dns"
|
|
echo " sudo bash /opt/netadmin-agent/deploy/install-agent.sh mail"
|
|
echo ""
|