Let's Encrypt/LAN

Aus Foxwiki

Let's Encrypt im LAN

Ich habe Home Assistant mit HTTPS-Fernzugriff, aber es ist nicht möglich, Home Assistant im lokalen Netzwerk zu erreichen, ohne die Fehlermeldung "Ihre Verbindung ist nicht privat" zu erhalten.

  • Das liegt daran, dass Ihre lokale IP oder URL nicht im SSL-Zertifikat aufgeführt ist.
  • Und es ist nicht möglich, die Home Assistant-App für Android zu verwenden, weil der SSL-Fehler auftritt.
  • Ich habe keine guten Lösungen im Internet gefunden, aber ich habe eine einfache Lösung gefunden, die in diesem Beitrag beschrieben wird.
  • Natürlich können Sie diese Lösung auch für andere Anwendungen als Home Assistant verwenden.

Was Sie brauchen

  • Eine eigene Domain mit Zugriff auf das DNS
  • Den (Linux-)Server in Ihrem lokalen Netzwerk mit Root-Rechten, in meinem Fall einen Raspberry Pi.

Certbot installieren

Die SSL-Zertifikate werden auf dem Raspberry Pi generiert, melden Sie sich als Benutzer pi über SSH an und installieren Sie certbot:

$ sudo apt install certbot

Überprüfen Sie, ob certbot gut funktioniert mit:

$ certbot --version

Installation von acme-dns-certbot-joohoi

Da ich im Netzwerk keinen Port 80 für die ACME-Verifizierung zur Verfügung habe, verwende ich die DNS-01-Verifizierung.

$ wget https://github.com/joohoi/a,cme-dns-certbot-joohoi/raw/master/acme-dns-auth.py
$ chmod +x acme-dns-auth.py
$ vi acme-dns-auth.py
#!/usr/bin/env python3
sudo mv acme-dns-auth.py /etc/letsencrypt/


Getting the certificates

We’re now going to generate a wildcard certificate on the subdomain home of your domain.

  • I’m using the subdomain home and you’ll get the result
*.home.example.com

Now execute the generation of the wildcard certificate:

# certbot certonly --manual --manual-auth-hook /etc/letsencrypt/acme-dns-auth.py --preferred-challenges dns --debug-challenges -d home.example.com

With this script you’re getting the CNAME record for DNS validation and looks like this:

Output from acme-dns-auth.py:
Please add the following CNAME record to your main DNS zone:
_acme-challenge.home.example.com CNAME a14de1b9-e910-4d91-18bf-07a3763b88e6.auth.acme-dns.io.

Waiting for verification...

Login into your domain provider and add the following records to your domain:

Hostname Type Value
_acme-challenge.home.example.com CNAME a14de1b9-e910-4d91-18bf-07a3763b88e6.auth.acme-dns.io.
home.example.com A
rpi.home.example.com A
extern.home.example.com CNAME home.example.com
Explanation
  • _acme-challenge.home.example.com: for ACME DNS verification (for example: a14de1b9-e910-4d91-18bf-07a3763b88e6.auth.acme-dns.io.).
  • Remark: this could be without a dot after dns.io
  • home.example.com: The public IP of your router
  • rpi.home.example.com: The local IP address of the Raspberry Pi (example: 192.168.1.5)
  • extern.home.example.com: This is the external url to reach your application (example Home Assistant)

After you’ve added the DNS records, you maybe need to wait a while until the new DNS settings are propagated on the internet.

Now you can restart the certbot tool again and you will get the certificates successfully!

  • If it isn’t successful yet, please wait and retry it again or check your DNS records.
  • Maybe you made a mistake with the _acme-challenge.home.example.com record.
# certbot certonly --manual --manual-auth-hook /etc/letsencrypt/acme-dns-auth.py --preferred-challenges dns --debug-challenges -d home.example.com

Testing

If you didn’t do this yet, you need to forward the ports from your router to the Raspberry Pi.

  • For Home Assistant it is 8123/tcp.
Local network

Access Home Assistant now with in this example: https://rpi.home.example.com:8123 and the certificate is valid for the domain your using! Hurray!

External access via the internet

Access Home Assistant now with in this example: https://external.home.example.com:8123 and the certificate is valid for the domain your using again.