« Ovh letsencrypt » : différence entre les versions

Aucun résumé des modifications
Aucun résumé des modifications
 
(Une version intermédiaire par le même utilisateur non affichée)
Ligne 137 : Ligne 137 :
=== 🔧 Solution A ===
=== 🔧 Solution A ===
-----
-----
 
`certbot/certbot:v2.9.0`
==== 1️⃣ Créer le Dockerfile ====
==== 1️⃣ Créer le Dockerfile ====


Ligne 220 : Ligne 220 :


</syntaxhighlight>
</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 ===
-----
==== 1️⃣ Créer le Dockerfile ====


Dans un dossier <code>~/certbot-docker</code> :
=== 🔧 Solution B (à tester) ===
`certbot/dns-ovh:latest`
==== ✅ '''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


<syntaxhighlight lang="bash">mkdir -p ~/certbot-docker
RESULT=$?
cd ~/certbot-docker
nano Dockerfile</syntaxhighlight>
Contenu du Dockerfile:


<syntaxhighlight lang="dockerfile"># Dockerfile pour Certbot + plugin OVH
if [ $RESULT -eq 0 ]; then
FROM certbot/certbot:v2.9.0
    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


# Installer le plugin OVH
exit 0</syntaxhighlight>
RUN pip install certbot-dns-ovh</syntaxhighlight>


-----
-----


==== 2️⃣ Créer le docker-compose.yml ====
==== 🔁 '''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


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


<syntaxhighlight lang="yaml">version: "3.8"
# Nettoyage du log
echo "" > "$LOGFILE"


services:
cd /home/debian/certbot-docker/
  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>


-----
# Lancer le renouvellement
docker compose run --rm certbot renew \
  --dns-ovh-credentials /secrets/ovh.ini \
  --dns-ovh-propagation-seconds 60 >> "$LOGFILE" 2>&1


==== 3️⃣ Construire l’image Docker ====
RESULT=$?


<syntaxhighlight lang="bash">cd ~/certbot-docker
if [ $RESULT -eq 0 ]; then
docker compose build</syntaxhighlight>
    systemctl reload apache2
* Cela crée une image <code>certbot-ovh</code> avec le plugin OVH inclus.
    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>


-----
-----


==== 4️⃣ Lancer la génération du certificat ====
==== 🧾 Résumé des étapes à suivre ====


<syntaxhighlight lang="bash">docker compose up</syntaxhighlight>
===== 📁 1. '''Préparer les fichiers''' =====
* Les certificats seront dans <code>/etc/letsencrypt/live/example.com/</code>
* Une fois terminé :


<syntaxhighlight lang="bash">docker compose down</syntaxhighlight>
* 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>


-----
-----


==== 5️⃣ Renouvellement automatique ====
===== 🐳 2. '''Contenu du <code>docker-compose.yml</code>''' =====


Créer un script <code>renew.sh</code> à côté de <code>docker-compose.yml</code> :
<syntaxhighlight lang="yaml">version: "3.8"
 
services:
  certbot:
    image: certbot/dns-ovh:latest
    container_name: certbot-ovh
    volumes:
      - "/etc/letsencrypt:/etc/letsencrypt"
      - "/var/lib/letsencrypt:/var/lib/letsencrypt"
      - "./secrets:/secrets"
    entrypoint: ""</syntaxhighlight>


<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>
===== 🛠️ 3. '''Lancer la création initiale''' =====
* Ajouter un cron quotidien :


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


-----
-----


'''Avantages :'''
===== 🔁 4. '''Configurer le renouvellement automatique'''=====
 
Ajoute dans <code>crontab -e</code> :
 
<syntaxhighlight lang="bash">0 3 * * * /home/debian/certbot-docker/renew.sh</syntaxhighlight>


* 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
-----
-----


[[category:ovh]] [[category:Docker]] [[category:Debian]]
[[category:ovh]] [[category:Docker]] [[category:Debian]]