Namecheap DNS Authenticator for Certbot

1.0.0 · active · verified Tue Apr 14

Certbot-dns-namecheap is a plugin for Certbot that automates the DNS-01 challenge for Let's Encrypt certificates using the Namecheap API. This allows for obtaining and renewing wildcard certificates by programmatically creating and deleting TXT records on Namecheap DNS. The current version is 1.0.0 and it is part of the Certbot ecosystem.

Warnings

Install

Imports

Quickstart

To quickly get started, first, create a credentials file (e.g., `namecheap.ini`) with your Namecheap API username and API key. Ensure this file has restrictive permissions (e.g., `chmod 600 namecheap.ini`). Then, use the `certbot` command-line tool with the `certbot-dns-namecheap:dns-namecheap` authenticator, pointing to your credentials file. The example includes obtaining a wildcard certificate. Remember to test with `--test-cert` first.

# 1. Create a credentials INI file (e.g., namecheap.ini) with your Namecheap API details.
#    Ensure this file has restricted permissions (e.g., chmod 600 namecheap.ini).
#    You can get your API Key from your Namecheap account's API Management page.
#
# namecheap.ini content:
# dns_namecheap_username = your_namecheap_username
# dns_namecheap_api_key = your_namecheap_api_key

import os

# For demonstration, use environment variables to populate the INI content
# In a real scenario, you'd create the file manually or securely programmatically.
username = os.environ.get('NAMECHEAP_USERNAME', 'your_namecheap_username')
api_key = os.environ.get('NAMECHEAP_API_KEY', 'your_namecheap_api_key')

ini_content = f"""
dns_namecheap_username = {username}
dns_namecheap_api_key = {api_key}
"""

creds_file = 'namecheap.ini'
with open(creds_file, 'w') as f:
    f.write(ini_content)
os.chmod(creds_file, 0o600) # Set restrictive permissions

# 2. Run Certbot with the Namecheap DNS authenticator
#    Replace example.com with your actual domain and your@email.com with your email.
#    Use --test-cert for initial testing to avoid hitting Let's Encrypt rate limits.
print(f"\nNow run this command in your terminal:\n")
print(f"certbot certonly \
  --authenticator certbot-dns-namecheap:dns-namecheap \
  --certbot-dns-namecheap:dns-namecheap-credentials {creds_file} \
  --agree-tos \
  --no-eff-email \
  --email your@email.com \
  -d example.com -d *.example.com \
  --test-cert")
print(f"\nAfter successful testing, remove --test-cert for a live certificate.")

view raw JSON →