# certbot-dns-ispmgr

[ISPmanager](https://www.ispsystem.com/software/ispmanager) DNS Authenticator plugin for [Certbot](https://certbot.eff.org/).

This plugin automates the process of completing a `dns-01` challenge by creating, and subsequently removing, TXT records using the ISPmanager API.

## Configuration of ISPmanager

The user provided to the API must have administrator access to manage DNS domain sublists.

## Installation

```bash
pip install certbot-dns-ispmgr
```

## Named Arguments

To start using DNS authentication for ISPmanager, pass the following arguments on Certbot's command line:

| Argument | Description |
| -------- | ----------- |
| `--authenticator dns-ispmgr` | Select the authenticator plugin (Required) |
| `--dns-ispmgr-credentials` | ISPmanager API credentials INI file. (Required if CLI credentials not provided) |
| `--dns-ispmgr-username` | ISPmanager username. (Alternative to credentials INI file) |
| `--dns-ispmgr-password` | ISPmanager password. (Alternative to credentials INI file) |
| `--dns-ispmgr-endpoint` | ISPmanager API URL. (Alternative to credentials INI file) |
| `--dns-ispmgr-propagation-seconds` | Waiting time for DNS to propagate before asking the ACME server to verify the DNS record. (Default: 120, Recommended: >= 600) |

*(Note that the verbose and seemingly redundant `certbot-dns-ispmgr:` prefix is currently imposed by Certbot for external plugins.)*

## Credentials

An example `credentials.ini` file:

```ini
dns_ispmgr_username = admin
dns_ispmgr_password = mysecretpassword
dns_ispmgr_endpoint = https://you.ispmanager.host:1500/ispmgr
```

The path to this file can be provided interactively or using the `--dns-ispmgr-credentials` command-line argument. Certbot records the path to this file for use during renewal, but does not store the file's contents.

**CAUTION:** You should protect these API credentials as you would the password to your ISPmanager account. Users who can read this file can use these credentials to issue arbitrary API calls on your behalf. Users who can cause Certbot to run using these credentials can complete a `dns-01` challenge to acquire new certificates or revoke existing certificates for associated domains, even if those domains aren't being managed by this server.

Certbot will emit a warning if it detects that the credentials file can be accessed by other users on your system. The warning reads "Unsafe permissions on credentials configuration file", followed by the path to the credentials file. This warning will be emitted each time Certbot uses the credentials file, including for renewal, and cannot be silenced except by addressing the issue (e.g., by using a command like `chmod 600` to restrict access to the file).

## Examples

To acquire a single certificate for both `example.com` and `*.example.com`, waiting 900 seconds for DNS propagation:

```bash
certbot certonly \
  --authenticator dns-ispmgr \
  --dns-ispmgr-credentials /etc/letsencrypt/.secrets/domain.tld.ini \
  --dns-ispmgr-propagation-seconds 900 \
  --server https://acme-v02.api.letsencrypt.org/directory \
  --agree-tos \
  --rsa-key-size 4096 \
  -d 'example.com' \
  -d '*.example.com'
```

To acquire a certificate using direct command line credentials (simplifying scripts but less secure unless wrapped properly):

```bash
certbot certonly \
  --authenticator dns-ispmgr \
  --dns-ispmgr-username admin \
  --dns-ispmgr-password mysecretpassword \
  --dns-ispmgr-endpoint https://you.ispmanager.host:1500/ispmgr \
  --dns-ispmgr-propagation-seconds 900 \
  -d example.com
```

## Docker

In order to create a Docker container with a certbot-dns-ispmgr installation, create an empty directory with the following `Dockerfile`:

```dockerfile
FROM certbot/certbot
RUN pip install certbot-dns-ispmgr
```

Proceed to build the image:

```bash
docker build -t certbot/dns-ispmgr .
```

Once that's finished, the application can be run as follows:

```bash
docker run --rm \
   -v /var/lib/letsencrypt:/var/lib/letsencrypt \
   -v /etc/letsencrypt:/etc/letsencrypt \
   --cap-drop=all \
   certbot/dns-ispmgr certonly \
   --authenticator dns-ispmgr \
   --dns-ispmgr-propagation-seconds 900 \
   --dns-ispmgr-credentials \
       /etc/letsencrypt/.secrets/domain.tld.ini \
   --no-self-upgrade \
   --keep-until-expiring --non-interactive --expand \
   --server https://acme-v02.api.letsencrypt.org/directory \
   -d example.com -d '*.example.com'
```

It is suggested to secure the folder as follows:

```bash
chown root:root /etc/letsencrypt/.secrets
chmod 600 /etc/letsencrypt/.secrets
```
