One place for hosting & domains

      Validation

      How To Acquire a Let’s Encrypt Certificate Using DNS Validation with acme-dns-certbot on Ubuntu 18.04


      The author selected the COVID-19 Relief Fund to receive a donation as part of the Write for DOnations program.

      Introduction

      The majority of Let’s Encrypt certificates are issued using HTTP validation, which allows for the easy installation of certificates on a single server. However, HTTP validation is not always suitable for issuing certificates for use on load-balanced websites, nor can it be used to issue wildcard certificates.

      DNS validation allows for certificate issuance requests to be verified using DNS records, rather than by serving content over HTTP. This means that certificates can be issued simultaneously for a cluster of web servers running behind a load balancer, or for a system that isn’t directly accessible over the internet. Wildcard certificates are also supported using DNS validation.

      The acme-dns-certbot tool is used to connect Certbot to a third-party DNS server where the certificate validation records can be set automatically via an API when you request a certificate. The advantage of this is that you don’t need to integrate Certbot directly with your DNS provider account, nor do you need to grant it unrestricted access to your full DNS configuration, which is beneficial to security.

      Delegated DNS zones are used in order to redirect lookups for the certificate verification records to the third-party DNS service, so once the initial setup has been completed, you can request as many certificates as you want without having to perform any manual validation.

      Another key benefit of acme-dns-certbot is that it can be used to issue certificates for individual servers that may be running behind a load balancer, or are otherwise not directly accessible over HTTP. Traditional HTTP certificate validation cannot be used in these cases, unless you set the validation files on each and every server. The acme-dns-certbot tool is also useful if you want to issue a certificate for a server that isn’t accessible over the internet, such as an internal system or staging environment.

      In this tutorial, you will use the acme-dns-certbot hook for Certbot to issue a Let’s Encrypt certificate using DNS validation.

      Prerequisites

      To complete this tutorial, you will need:

      • An Ubuntu 18.04 server set up by following the Initial Server Setup with Ubuntu 18.04, including a sudo non-root user.

      • A domain name for which you can acquire a TLS certificate, including the ability to add DNS records. In this particular example, we will use your-domain and subdomain.your-domain, as well as *.your-domain for a wildcard certificate. However this can be adjusted for other domain, subdomains, or wildcards if required.

      Once you have these ready, log in to your server as your non-root user to begin.

      Step 1 — Installing Certbot

      In this step, you will install Certbot, which is a program used to issue and manage Let’s Encrypt certificates.

      Certbot is available within the official Ubuntu Apt repositories, however, it is instead recommended to use the repository maintained by the Certbot developers, as this always has the most up-to-date version of the software.

      Begin by adding the Certbot repository:

      • sudo apt-add-repository ppa:certbot/certbot

      You’ll need to press ENTER to accept the prompt and add the new repository to your system.

      Next, install the Certbot package:

      Once the installation has completed, you can check that Certbot has been successfully installed:

      This will output something similar to the following:

      Output

      certbot 0.31.0

      In this step you installed Certbot. Next, you will download and install the acme-dns-certbot hook.

      Step 2 — Installing acme-dns-certbot

      Now that the base Certbot program has been installed, you can download and install acme-dns-certbot, which will allow Certbot to operate in DNS validation mode.

      Begin by downloading a copy of the script:

      • wget https://github.com/joohoi/acme-dns-certbot-joohoi/raw/master/acme-dns-auth.py

      Once the download has completed, mark the script as executable:

      • chmod +x acme-dns-auth.py

      Then, edit the file using your favorite text editor and adjust the first line in order to force it to use Python 3:

      Add a 3 to the end of the first line:

      acme-dns-certbot.py

      #!/usr/bin/env python3
      . . .
      

      This is required in order to ensure that the script uses the latest supported version of Python 3, rather than the legacy Python version 2.

      Once complete, save and close the file.

      Finally, move the script into the Certbot Let’s Encrypt directory so that Certbot can load it:

      • sudo mv acme-dns-auth.py /etc/letsencrypt/

      In this step, you downloaded and installed the acme-dns-certbot hook. Next, you can begin the setup process and work toward issuing your first certificate.

      Step 3 — Setting Up acme-dns-certbot

      In order to begin using acme-dns-certbot, you’ll need to complete an initial setup process and issue at least one certificate.

      Start by running Certbot to force it to issue a certificate using DNS validation. This will run the acme-dns-certbot script and trigger the initial setup process:

      • sudo certbot certonly --manual --manual-auth-hook /etc/letsencrypt/acme-dns-auth.py --preferred-challenges dns --debug-challenges -d *.your-domain -d your-domain

      You use the --manual argument to disable all of the automated integration features of Certbot. In this case you’re just issuing a raw certificate, rather than automatically installing it on a service as well.

      You configure Certbot to use the acme-dns-certbot hook via the --manual-auth-hook argument. You run the --preferred-challenges argument so that Certbot will give preference to DNS validation.

      You must also tell Certbot to pause before attempting to validate the certificate, which you do with the --debug-challenges argument. This is to allow you to set the DNS CNAME record(s) required by acme-dns-certbot, which is covered later in this step. Without the --debug-challenges argument, Certbot wouldn’t pause, so you wouldn’t have time to make the required DNS change.

      Remember to substitute each of the domain names that you wish to use using -d arguments. If you want to issue a wildcard certificate, make sure to escape the asterisk (*) with a backslash ().

      After following the standard Certbot steps, you’ll eventually be prompted with a message similar to the following:

      Output

      ... Output from acme-dns-auth.py: Please add the following CNAME record to your main DNS zone: _acme-challenge.your-domain CNAME a15ce5b2-f170-4c91-97bf-09a5764a88f6.auth.acme-dns.io. Waiting for verification... ...

      You’ll need to add the required DNS CNAME record to the DNS configuration for your domain. This will delegate control of the _acme-challenge subdomain to the ACME DNS service, which will allow acme-dns-certbot to set the required DNS records to validate the certificate request.

      If you’re using DigitalOcean as your DNS provider, you can set the DNS record within your control panel:

      A screenshot of the DigitalOcean DNS control panel, showing an example of a CNAME record for ACME DNS

      It is recommended to set the TTL (time-to-live) to around 300 seconds in order to help ensure that any changes to the record are propagated quickly.

      Once you have configured the DNS record, return to Certbot and press ENTER to validate the certificate request and complete the issuance process.

      This will take a few seconds, and you’ll then see a message confirming that the certificate has been issued:

      Output

      ... Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/your-domain/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/your-domain/privkey.pem ...

      You’ve run acme-dns-certbot for the first time, set up the required DNS records, and successfully issued a certificate. Next you’ll set up automatic renewals of your certificate.

      Step 4 — Using acme-dns-certbot

      In this final step, you will use acme-dns-certbot to issue more certificates and renew existing ones.

      Firstly, now that you’ve successfully issued at least one certificate using acme-dns-certbot, you can continue to issue certificates for the same DNS names without having to add another DNS CNAME record. However, if you wish to acquire a certificate for a different subdomain or entirely new domain name, you will be prompted to add another CNAME record.

      For example, you could issue another standalone wildcard certificate without having to perform the verification again:

      • sudo certbot certonly --manual --manual-auth-hook /etc/letsencrypt/acme-dns-auth.py --preferred-challenges dns --debug-challenges -d *.your-domain

      However, if you were to attempt to issue a certificate for a subdomain, you would be prompted to add a CNAME record for the subdomain:

      • sudo certbot certonly --manual --manual-auth-hook /etc/letsencrypt/acme-dns-auth.py --preferred-challenges dns --debug-challenges -d subdomain.your-domain

      This will show an output similar to the initial setup that you carried out in Step 3:

      Output

      ... Please add the following CNAME record to your main DNS zone: _acme-challenge.subdomain.your-domain CNAME 8450fb54-8e01-4bfe-961a-424befd05088.auth.acme-dns.io. Waiting for verification... ...

      Now that you’re able to use acme-dns-certbot to issue certificates, it’s worth considering the renewal process as well.

      Once your certificates are nearing expiry, Certbot can automatically renew them for you:

      The renewal process can run start-to-finish without user interaction, and will remember all of the configuration options that you specified during the initial setup.

      To test that this is working without having to wait until nearer the expiry date, you can trigger a dry run. This will simulate the renewal process without making any actual changes to your configuration.

      You can trigger a dry run using the standard renew command, but with the --dry-run argument:

      • sudo certbot renew --dry-run

      This will output something similar to the following, which will provide assurance that the renewal process is functioning correctly:

      Output

      ... Cert not due for renewal, but simulating renewal for dry run Plugins selected: Authenticator manual, Installer None Renewing an existing certificate Performing the following challenges: dns-01 challenge for your-domain dns-01 challenge for your-domain Waiting for verification... Cleaning up challenges ...

      In this final step, you issued another certificate and then tested the automatic renewal process within Certbot.

      Conclusion

      In this article you set up Certbot with acme-dns-certbot in order to issue certificates using DNS validation. This unlocks the possibility of using wildcard certificates as well as managing a large estate of distinct web servers that may be sitting behind a load balancer.

      Make sure to keep an eye on the acme-dns-certbot repository for any updates to the script, as it’s always recommended to run the latest supported version.

      If you’re interested in learning more about acme-dns-certbot, you may wish to review the documentation for the acme-dns project, which is the server-side element of acme-dns-certbot:

      The acme-dns software can also be self-hosted, which may be beneficial if you’re operating in high-security or complex environments.

      Alternatively, you could dig into the technical details of ACME DNS validation by reviewing the relevant section of the official RFC document which outlines how the process works:



      Source link

      How to Retrieve Let’s Encrypt SSL Wildcard Certificates using CloudFlare Validation on CentOS 7


      The author selected Code.org to receive a donation as part of the Write for DOnations program.

      Introduction

      Let’s Encrypt is a certificate authority (CA) that provides free certificates for Transport Layer Security (TLS) encryption. It provides a software client called Certbot which simplifies the process of certificate creation, validation, signing, installation, and renewal.

      Let’s Encrypt now supports wildcard certificates which allow you to secure all subdomains of a domain with a single certificate. This will be useful if you want to host multiple services, such as web interfaces, APIs, and other sites using a single server.

      To obtain a wildcard certificate from Let’s Encrypt you have to use one of Certbot’s DNS plugins, which include:

      • certbot-dns-cloudflare
      • certbot-dns-route53
      • certbot-dns-google
      • certbot-dns-digitalocean

      The plugin you choose depends on which service hosts your DNS records. In this tutorial you will obtain a wildcard certificate for your domain using CloudFlare validation with Certbot on CentOS 7. You’ll then configure the certificate to renew it when it expires.

      Prerequisites

      To complete this tutorial, you’ll need the following:

      Step 1 — Installing Certbot

      The certbot package is not available through CentOS’s package manager by default. You will need to enable the EPEL repository to install Certbot and its plugins.

      To add the CentOS 7 EPEL repository, run the following command:

      • sudo yum install -y epel-release

      Once the installation completes, you can install certbot:

      • sudo yum install -y certbot

      And then install the CloudFlare plugin for Certbot:

      • sudo yum install -y python2-cloudflare python2-certbot-dns-cloudflare

      If you are using another DNS service, you can find the corresponding plugin using the yum search command:

      • yum search python2-certbot-dns

      You’ve prepared your server to obtain certificates. Now you need to get the API key from CloudFlare.

      Step 2 — Getting the CloudFlare API

      In order for Certbot to automatically renew wildcard certificates, you need to provide it with your CloudFlare login and API key.

      Log in to your Cloudflare account and navigate to the Profile page.

      Click the View button in the Global API Key line.

      CloudFlare Profile - API Keys

      For security reasons, you will be asked to re-enter your Cloudflare account password. Enter it and validate the CAPTCHA. Then click the View button again. You’ll see your API key:

      CloudFlare Profile - API Keys

      Copy this key. You will use it in the next step.

      Now return to your server to continue the process of obtaining the certificate.

      Step 3 — Configuring Certbot

      You have all of the necessary information to tell Certbot how to use Cloudflare, but let’s write it to a configuration file so that Сertbot can use it automatically.

      First run the certbot command without any parameters to create the initial configuration file:

      Next create a configuration file in the /etc/letsencrypt directory which will contain your CloudFlare email and API key:

      • sudo vi /etc/letsencrypt/cloudflareapi.cfg

      Add the following into it, replacing the placeholders with your Cloudflare login and API key:

      /etc/letsencrypt/cloudflareapi.cfg

      dns_cloudflare_email = your_cloudflare_login
      dns_cloudflare_api_key = your_cloudflare_api_key
      

      Save the file and exit the editor.
      With Cloudflare's API key, you can do the same things from the command line that you can do from the Cloudflare UI, so in order to protect your account, make the configuration file readable only by its owner so nobody else can obtain your key:

      • sudo chmod 600 /etc/letsencrypt/cloudflareapi.cfg

      With the configuration files in place, let's obtain a certificate.

      Step 4 — Obtaining the Certificate

      To obtain a certificate, we'll use the certbot command and specify the plugin we want, the credentials file we want to use, and the server we should use to handle the request. By default, Certbot uses Let’s Encrypt’s production servers, which use ACME API version 1, but Certbot uses another protocol for obtaining wildcard certificates, so you need to provide an ACME v2 endpoint.

      Run the following command to obtain the wildcard certificate for your domain:

      • sudo certbot certonly --cert-name your_domain --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflareapi.cfg --server https://acme-v02.api.letsencrypt.org/directory -d "*.your_domain" -d your_domain

      You will be asked to specify the email address that should receive urgent renewal and security notices:

      Output

      ... Plugins selected: Authenticator dns-cloudflare, Installer None Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): your email

      Then you'll be asked to agree to the Terms of Service:

      Output

      ------------------------------------------------------------------------------- Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory ------------------------------------------------------------------------------- (A)gree/(C)ancel: A

      Then you'll be asked to share your email address with the Electronic Frontier
      Foundation:

      Output

      ------------------------------------------------------------------------------- Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about EFF and our work to encrypt the web, protect its users and defend digital rights. ------------------------------------------------------------------------------- (Y)es/(N)o: N

      Then Certbot will obtain your certificates. You will see the following message:

      Output

      IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/your_domain/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/your_domain/privkey.pem Your cert will expire on 2018-07-31. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le

      Now you have your wildcard certificate. Let's take a look at what Certbot has downloaded for you. Use the ls command to see the contents of the directory that holds your keys and certificates:

      • sudo ls /etc/letsencrypt/live/your_domain

      Output

      cert.pem chain.pem fullchain.pem privkey.pem README

      The README file contains information about these files:

      $ cat /etc/letsencrypt/live/your_domain/README
      

      You'll see output like this:

      README

      This directory contains your keys and certificates.
      
      `privkey.pem`  : the private key for your certificate.
      `fullchain.pem`: the certificate file used in most server software.
      `chain.pem`    : used for OCSP stapling in Nginx >=1.3.7.
      `cert.pem`     : will break many server configurations, and should not be used
                       without reading further documentation (see link below).
      
      We recommend not moving these files. For more information, see the Certbot
      User Guide at https://certbot.eff.org/docs/using.html#where-are-my-certificates.
      

      From here, you can configure your servers with the wildcard certificate. You'll usually only need two of these files: fullchain.pem and privkey.pem.

      For example, you can configure several web-based services:

      • wwww.example.com
      • api.example.com
      • mail.example.com

      To do this, you will need a web server, such as Apache or Nginx. The installation and configuration of these servers is beyond the scope of this tutorial, but the following guides will walk you through all the necessary steps to configure the servers and apply your certificates.

      For Nginx, take a look at these tutorials:

      For Apache, consult these tutorials:

      Now let's look at renewing the certificates automatically.

      Step 5 — Renewing certificates

      Let’s Encrypt issues short-lived certificates which are valid for 90 days. We'll need to set up a cron task to check for expiring certificates and renew them automatically.

      Let's create a cron task
      which will run the renewal check daily.

      Use the following command to open the crontab file for editing:

      Add the following line to the file to attempt to renew the certificates daily:

      crontab

      30 2 * * * certbot renew --noninteractive
      
      • 30 2 * * * means "run the following command at 2:30 am, every day".
      • The certbot renew command will check all certificates installed on the system and update any that are set to expire in less than thirty days.
      • --noninteractive tells Certbot not to wait for user input.

      You will need to reload your web server after updating your certificates. The renew command includes hooks for running commands or scripts before or after a certificate is renewed. You can also configure these hooks in the renewal configuration file for your domain.

      For example, to reload your Nginx server, open the renewal configuration file:

      • sudo vi /etc/letsencrypt/renewal/your_domain.conf

      Then add the following line under the [renewalparams] section:

      your_domain.conf'>/etc/letsencrypt/renewal/your_domain.conf

      renew_hook = systemctl reload nginx
      

      Now Certbot will automatically restart your web server after installing the updated certificate.

      Conclusion

      In this tutorial you've installed the Certbot client, obtained your wildcard certificate using DNS validation and enabled automatic renewals. This will allow you to use a single certificate with multiple subdomains of your domain and secure your web services.



      Source link