« Ovh letsencrypt » : différence entre les versions

Aucun résumé des modifications
Ligne 135 : Ligne 135 :


=== Debian 13 pour Certbot + plugin OVH avec Docker ===
=== Debian 13 pour Certbot + plugin OVH avec Docker ===
==== 🔧 Solution A ====
==== 🔧 Solution A ====
-----
-----
Ligne 161 : Ligne 160 :


<syntaxhighlight lang="yaml">version: "3.8"
<syntaxhighlight lang="yaml">version: "3.8"
services:
services:
   certbot:
   certbot:
Ligne 170 : Ligne 168 :
       - "/var/lib/letsencrypt:/var/lib/letsencrypt"
       - "/var/lib/letsencrypt:/var/lib/letsencrypt"
       - "/etc/letsencrypt/.ovhsecrets:/secrets"
       - "/etc/letsencrypt/.ovhsecrets:/secrets"
    entrypoint: >
</syntaxhighlight>
      certbot certonly
      --dns-ovh
      --dns-ovh-credentials /secrets/ovh.ini
      --non-interactive
      --agree-tos
      -d example.com
      -d '*.example.com'</syntaxhighlight>
<blockquote>Remplace <code>example.com</code> par ton domaine réel. Le volume <code>/secrets</code> pointe sur ton fichier OVH existant.
</blockquote>


-----
-----


===== 3️⃣ Construire l’image Docker =====
===== 3️⃣ Script Bash demande initiale `inital.sh` =====
 
<syntaxhighlight lang="bash">cd ~/certbot-docker
docker compose build</syntaxhighlight>
* Cela crée une image <code>certbot-ovh</code> avec le plugin OVH inclus.
 


<syntaxhighlight lang="bash">
docker compose run --rm certbot \
  certonly \
  --dns-ovh \
  --dns-ovh-credentials /secrets/ovh.ini \
  --non-interactive \
  --agree-tos \
  -d example.com -d '*.example.com'
</syntaxhighlight>
-----
-----
<syntaxhighlight lang="bash">docker compose down</syntaxhighlight>


===== 4️⃣ Lancer la génération du certificat =====
===== 4️⃣ Script Bash renew `renew.sh` =====


<syntaxhighlight lang="bash">docker compose up</syntaxhighlight>
<syntaxhighlight lang="bash">
* Les certificats seront dans <code>/etc/letsencrypt/live/example.com/</code>
#!/bin/bash
* Une fois terminé :
# Renew certificat Let's Encrypt via Docker + notification email


<syntaxhighlight lang="bash">docker compose down</syntaxhighlight>
LOGFILE="/var/log/certbot-renew-docker.log"
EMAIL="john@gmail.com"
FROM="cron letsencrypt <john@exemple.com>"


-----
# Nettoyage du log
echo "" > "$LOGFILE"


===== 5️⃣ Renouvellement automatique =====


Créer un script <code>renew.sh</code> à côté de <code>docker-compose.yml</code> :
cd /home/debian/certbot-docker/
# Lancer le renouvellement via Docker Compose
docker compose run --rm certbot renew >> "$LOGFILE" 2>&1
RESULT=$?


<syntaxhighlight lang="bash">#!/bin/bash
# Si renouvellement réussi
docker compose run --rm certbot renew --deploy-hook "systemctl reload mariadb"</syntaxhighlight>
if [ $RESULT -eq 0 ]; then
* Rendre le script exécutable :
    # Recharger Apache sur l’hôte
    systemctl reload apache2


<syntaxhighlight lang="bash">chmod +x renew.sh</syntaxhighlight>
    # Envoyer un mail de succès
* Ajouter un cron quotidien :
    mail -a "From: $FROM" -s "✅ CERTBOT Renew réussi (Docker) pour example.com" "$EMAIL" < "$LOGFILE"
else
    # Envoyer un mail d’erreur
    mail -a "From: $FROM" -s "❌ CERTBOT Renew ÉCHEC (Docker) pour example.com" "$EMAIL" < "$LOGFILE"
fi


<syntaxhighlight lang="bash">sudo crontab -e</syntaxhighlight>
exit 0
<pre class="cron">0 3 * * * /home/debian/certbot-docker/renew.sh &gt;&gt; /var/log/certbot-renew.log 2&gt;&amp;1</pre>


</syntaxhighlight>
-----
-----
✅ '''Avantages :'''
* Plugin OVH fonctionne immédiatement
* Debian 13 reste intact → pas de pip system-wide ni Snap
* Certificats wildcard Let’s Encrypt générés et renouvelables automatiquement
* Compatible MariaDB, Nginx, Apache
==== 🔧 Solution B ====
==== 🔧 Solution B ====
-----
-----
===== 1️⃣ Créer le Dockerfile =====
===== 1️⃣ Créer le Dockerfile =====


Ligne 250 : Ligne 245 :


<syntaxhighlight lang="yaml">version: "3.8"
<syntaxhighlight lang="yaml">version: "3.8"
services:
services:
   certbot:
   certbot:
Ligne 258 : Ligne 254 :
       - "/var/lib/letsencrypt:/var/lib/letsencrypt"
       - "/var/lib/letsencrypt:/var/lib/letsencrypt"
       - "/etc/letsencrypt/.ovhsecrets:/secrets"
       - "/etc/letsencrypt/.ovhsecrets:/secrets"
</syntaxhighlight>
    entrypoint: >
      certbot certonly
      --dns-ovh
      --dns-ovh-credentials /secrets/ovh.ini
      --non-interactive
      --agree-tos
      -d example.com
      -d '*.example.com'</syntaxhighlight>
<blockquote>Remplace <code>example.com</code> par ton domaine réel. Le volume <code>/secrets</code> pointe sur ton fichier OVH existant.
</blockquote>


-----
-----


===== 3️⃣ Script Bash demande initiale `inital.sh` =====
===== 3️⃣ Construire l’image Docker =====
 
<syntaxhighlight lang="bash">cd ~/certbot-docker
docker compose build</syntaxhighlight>
* Cela crée une image <code>certbot-ovh</code> avec le plugin OVH inclus.
 


<syntaxhighlight lang="bash">
docker compose run --rm certbot \
  certonly \
  --dns-ovh \
  --dns-ovh-credentials /secrets/ovh.ini \
  --non-interactive \
  --agree-tos \
  -d example.com -d '*.example.com'
</syntaxhighlight>
-----
-----
<syntaxhighlight lang="bash">docker compose down</syntaxhighlight>


===== 4️⃣ Script Bash renew `renew.sh` =====
===== 4️⃣ Lancer la génération du certificat =====
 
<syntaxhighlight lang="bash">docker compose up</syntaxhighlight>
* Les certificats seront dans <code>/etc/letsencrypt/live/example.com/</code>
* Une fois terminé :


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">docker compose down</syntaxhighlight>
#!/bin/bash
# Renew certificat Let's Encrypt via Docker + notification email


LOGFILE="/var/log/certbot-renew-docker.log"
-----
EMAIL="john@gmail.com"
FROM="cron letsencrypt <john@exemple.com>"


# Nettoyage du log
===== 5️⃣ Renouvellement automatique =====
echo "" > "$LOGFILE"


Créer un script <code>renew.sh</code> à côté de <code>docker-compose.yml</code> :


cd /home/debian/certbot-docker/
<syntaxhighlight lang="bash">#!/bin/bash
# Lancer le renouvellement via Docker Compose
docker compose run --rm certbot renew --deploy-hook "systemctl reload mariadb"</syntaxhighlight>
docker compose run --rm certbot renew >> "$LOGFILE" 2>&1
* Rendre le script exécutable :
RESULT=$?


# Si renouvellement réussi
<syntaxhighlight lang="bash">chmod +x renew.sh</syntaxhighlight>
if [ $RESULT -eq 0 ]; then
* Ajouter un cron quotidien :
    # Recharger Apache sur l’hôte
    systemctl reload apache2


    # Envoyer un mail de succès
<syntaxhighlight lang="bash">sudo crontab -e</syntaxhighlight>
    mail -a "From: $FROM" -s "✅ CERTBOT Renew réussi (Docker) pour example.com" "$EMAIL" < "$LOGFILE"
<pre class="cron">0 3 * * * /home/debian/certbot-docker/renew.sh &gt;&gt; /var/log/certbot-renew.log 2&gt;&amp;1</pre>
else
    # Envoyer un mail d’erreur
    mail -a "From: $FROM" -s "❌ CERTBOT Renew ÉCHEC (Docker) pour example.com" "$EMAIL" < "$LOGFILE"
fi


exit 0
-----


</syntaxhighlight>
✅ '''Avantages :'''


* Plugin OVH fonctionne immédiatement
* Debian 13 reste intact → pas de pip system-wide ni Snap
* Certificats wildcard Let’s Encrypt générés et renouvelables automatiquement
* Compatible MariaDB, Nginx, Apache
-----
-----