« Ovh letsencrypt » : différence entre les versions

Aucun résumé des modifications
 
(4 versions intermédiaires par le même utilisateur non affichées)
Ligne 135 : Ligne 135 :


== Debian 13 pour Certbot + plugin OVH avec Docker ==
== Debian 13 pour Certbot + plugin OVH avec Docker ==
=== 🔧 Solution A ===
=== 🔧 Solution A (BEST)===
`certbot/dns-ovh:latest`
 
*[https://github.com/marmits/certbot-docker-ovh PROJET GITHUB => DOCKER CERTBOT OVH]*
 
==== ✅ '''1. Script <code>initial.sh</code> – Création initiale du certificat''' ====
 
Ce script va lancer la commande <code>certonly</code> avec les bons paramètres pour générer un certificat wildcard via OVH :
 
<syntaxhighlight lang="bash">#!/bin/bash
# Création initiale du certificat Let's Encrypt via Docker
 
DOMAIN="example.com"
EMAIL="john@gmail.com"
LOGFILE="/var/log/certbot-initial-docker.log"
FROM="cron letsencrypt <john@exemple.com>"
 
# Nettoyage du log
echo "" > "$LOGFILE"
 
cd /home/debian/certbot-docker/
 
# Lancer la création du certificat
docker compose run --rm certbot certonly \
  --dns-ovh \
  --dns-ovh-credentials /secrets/ovh.ini \
  --dns-ovh-propagation-seconds 60 \
  --non-interactive \
  --agree-tos \
  -d "$DOMAIN" \
  -d "*.$DOMAIN" \
  --email "$EMAIL" \
  --no-eff-email >> "$LOGFILE" 2>&1
 
RESULT=$?
 
if [ $RESULT -eq 0 ]; then
    systemctl reload apache2
    mail -a "From: $FROM" -s "✅ CERTBOT Création réussie (Docker) pour $DOMAIN" "$EMAIL" < "$LOGFILE"
else
    mail -a "From: $FROM" -s "❌ CERTBOT Création ÉCHEC (Docker) pour $DOMAIN" "$EMAIL" < "$LOGFILE"
fi
 
exit 0</syntaxhighlight>
 
-----
 
==== 🔁 '''2. Script <code>renew.sh</code> – Renouvellement automatique''' ====
 
Voici une version adaptée à l’image <code>certbot/dns-ovh:latest</code> :
 
<syntaxhighlight lang="bash">#!/bin/bash
# Renouvellement du certificat Let's Encrypt via Docker
 
LOGFILE="/var/log/certbot-renew-docker.log"
EMAIL="john@gmail.com"
FROM="cron letsencrypt <john@exemple.com>"
 
# Nettoyage du log
echo "" > "$LOGFILE"
 
cd /home/debian/certbot-docker/
 
# Lancer le renouvellement
docker compose run --rm certbot renew \
  --dns-ovh-credentials /secrets/ovh.ini \
  --dns-ovh-propagation-seconds 60 >> "$LOGFILE" 2>&1
 
RESULT=$?
 
if [ $RESULT -eq 0 ]; then
    systemctl reload apache2
    mail -a "From: $FROM" -s "✅ CERTBOT Renew réussi (Docker)" "$EMAIL" < "$LOGFILE"
else
    mail -a "From: $FROM" -s "❌ CERTBOT Renew ÉCHEC (Docker)" "$EMAIL" < "$LOGFILE"
fi
 
exit 0</syntaxhighlight>
 
-----
 
==== 🧾 Résumé des étapes à suivre ====
 
===== 📁 1. '''Préparer les fichiers''' =====
 
* Crée un dossier <code>certbot-docker</code> avec :
** <code>docker-compose.yml</code>
** <code>initial.sh</code>
** <code>renew.sh</code>
** Un dossier <code>secrets/</code> contenant <code>ovh.ini</code> avec les clés API :
 
<syntaxhighlight lang="ini">dns_ovh_endpoint = ovh-eu
dns_ovh_application_key = xxx
dns_ovh_application_secret = xxx
dns_ovh_consumer_key = xxx</syntaxhighlight>
<blockquote>⚠️ Donne les bons droits : <code>chmod 600 secrets/ovh.ini</code>
</blockquote>
 
-----
 
===== 🐳 2. '''Contenu du <code>docker-compose.yml</code>''' =====
 
<syntaxhighlight lang="yaml">
services:
  certbot:
    image: certbot/dns-ovh
    container_name: certbot-ovh
    volumes:
      - "/etc/letsencrypt:/etc/letsencrypt"
      - "/var/lib/letsencrypt:/var/lib/letsencrypt"
      - "/etc/letsencrypt/.ovhsecrets:/secrets"
    restart: "no"
</syntaxhighlight>
 
-----
 
===== 🛠️ 3. '''Lancer la création initiale''' =====
 
<syntaxhighlight lang="bash">chmod +x initial.sh
./initial.sh</syntaxhighlight>
 
-----
 
===== 🔁 4. '''Configurer le renouvellement automatique'''=====
 
Ajoute dans <code>crontab -e</code> :
 
<syntaxhighlight lang="bash">0 3 * * * /home/debian/certbot-docker/renew.sh</syntaxhighlight>
 
-----
-----


=== 🔧 Solution B (Old) ===
-----
`certbot/certbot:v2.9.0`
==== 1️⃣ Créer le Dockerfile ====
==== 1️⃣ Créer le Dockerfile ====


Ligne 220 : Ligne 354 :


</syntaxhighlight>
</syntaxhighlight>
-----
=== 🔧 Solution B ===
-----
==== 1️⃣ Créer le Dockerfile ====
Dans un dossier <code>~/certbot-docker</code> :
<syntaxhighlight lang="bash">mkdir -p ~/certbot-docker
cd ~/certbot-docker
nano Dockerfile</syntaxhighlight>
Contenu du Dockerfile:
<syntaxhighlight lang="dockerfile"># Dockerfile pour Certbot + plugin OVH
FROM certbot/certbot:v2.9.0
# Installer le plugin OVH
RUN pip install certbot-dns-ovh</syntaxhighlight>
-----
==== 2️⃣ Créer le docker-compose.yml ====
Toujours dans <code>~/certbot-docker</code> :
<syntaxhighlight lang="yaml">version: "3.8"
services:
  certbot:
    build: .
    container_name: certbot-ovh
    volumes:
      - "/etc/letsencrypt:/etc/letsencrypt"
      - "/var/lib/letsencrypt:/var/lib/letsencrypt"
      - "/etc/letsencrypt/.ovhsecrets:/secrets"
    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️⃣ 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.
-----
==== 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">docker compose down</syntaxhighlight>
-----
==== 5️⃣ Renouvellement automatique ====
Créer un script <code>renew.sh</code> à côté de <code>docker-compose.yml</code> :
<syntaxhighlight lang="bash">#!/bin/bash
docker compose run --rm certbot renew --deploy-hook "systemctl reload mariadb"</syntaxhighlight>
* Rendre le script exécutable :
<syntaxhighlight lang="bash">chmod +x renew.sh</syntaxhighlight>
* Ajouter un cron quotidien :
<syntaxhighlight lang="bash">sudo crontab -e</syntaxhighlight>
<pre class="cron">0 3 * * * /home/debian/certbot-docker/renew.sh &gt;&gt; /var/log/certbot-renew.log 2&gt;&amp;1</pre>
-----


✅ '''Avantages :'''
✅ '''Avantages :'''
Ligne 308 : Ligne 361 :
* Certificats wildcard Let’s Encrypt générés et renouvelables automatiquement
* Certificats wildcard Let’s Encrypt générés et renouvelables automatiquement
* Compatible MariaDB, Nginx, Apache
* Compatible MariaDB, Nginx, Apache
-----
-----
[[category:ovh]] [[category:Docker]] [[category:Debian]]
[[category:ovh]] [[category:Docker]] [[category:Debian]]