Détail du package

acme-dns-01-cloudflare

nodecraft535MIT1.2.5

Cloudflare DNS for Let's Encrypt / ACME dns-01 challenges with Greenlock.js and ACME.js

acme, cloudflare, dns, dns-01

readme

acme-dns-01-cloudflare

npm version Actions Status

Cloudflare DNS + Let's Encrypt. This module handles ACME dns-01 challenges, compatible with Greenlock.js and ACME.js. It passes acme-dns-01-test.

Install

npm install acme-dns-01-cloudflare --save

Cloudflare API Token

Whilst you can use a global API key and email to generate certs, we heavily encourage that you use a Cloudflare API token for increased security.

From your Cloudflare Profile page, create an API Token with the following permissions:

  • Zone -> Zone: Read
  • Zone -> DNS: Edit

Unfortunately at this time, there is no way to acquire the com.cloudflare.api.account.zone.list permission needed to list zones without giving the key Zone: Read access to all zones. Further discussion of this can be found here and hopefully there'll be a better solution in the future.

The resulting API token should look something like this:

Cloudflare API Token generation

Usage

First, create an instance of the library with your Cloudflare API credentials or an API token. See the instructions above for more information.

const acmeDnsCloudflare = require('acme-dns-01-cloudflare');

const cloudflareDns01 = new acmeDnsCloudflare({
    token: 'xxxxxx',
    verifyPropagation: true,
    verbose: true // log propagation delays and other debug information
});
`

Other options include waitFor and retries which control the number of propagation retries, and delay between retries. You probably won't need to tweak these unless you're seeing regular DNS related failures.

Then you can use it with any compatible ACME library, such as Greenlock.js or ACME.js.

Greenlock.js v4

See the Greenlock.js documentation for more information.

const Greenlock = require('greenlock');
const pkg = require('./package.json');

const greenlock = Greenlock.create({
    packageAgent: pkg.name + '/' + pkg.version,
    configDir: "./store",
    maintainerEmail: "example@example.com"
});

greenlock.manager.defaults({
    agreeToTerms: true,
    subscriberEmail: "example@example.com",
    store: {
        module: "greenlock-store-fs",
        basePath: "./store/certs"
    },
    challenges: {
        "dns-01": cloudflareDns01
    }
});

greenlock.add({
    subject: "example.com",
    altnames: ["example.com", "www.example.com"]
}).then(function(){
    console.log("SUCCESS");
}).catch(console.error);

Greenlock.js v2

The example below uses the greenlock-store-fs module to write these certs to disk for demonstration.

const Greenlock = require('greenlock'),
    greenlockStore = require('greenlock-store-fs');

const store = greenlockStore.create({
    configDir: './store/certs',
    debug: true
});

const greenlock = Greenlock.create({
    server: 'https://acme-staging-v02.api.letsencrypt.org/directory',
    store: store,
    challenges: {
        'dns-01': cloudflareDns01
    },
    challengeType: 'dns-01',
    debug: true
});

greenlock.register({
    domains: ['example.com'],
    email: 'example@example.com',
    agreeTos: true,
    rsaKeySize: 2048,
    debug: true
}).then(() => {
    console.log('SUCCESS');
}).catch((err) => {
    console.error(err);
});

ACME.js

// TODO

Tests

# CLOUDFLARE_TOKEN or both CLOUDFLARE_EMAIL and CLOUDFLARE_APIKEY env vars must be set, as well as DOMAIN
node ./test.js

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

[1.2.4] - 2021-04-027

[1.2.3] - 2020-06-07

  • Fix over-eager zone matching that could cause certs for testing-example.com to fail if domain example.com was available

[1.2.2] - 2020-05-09

  • Improve Cloudflare error response handling

[1.2.1] - 2020-04-26

  • Fix promise rejections to always return an Error instance for better compatibility with ACME.js

[1.2.0] - 2020-04-26

  • Add ACME.js propagationDelay support
  • Wait 10 seconds before attempting first propagation check, to prevent polluting the DNS cache with an invalid result

[1.1.1] - 2020-02-04

  • Simplify promise handlers

[1.1.0] - 2020-01-15

  • Bump cloudflare to 2.7.0
  • Enable using an API token for Cloudflare instead of email + API Key
  • Bump acme-dns-01-test to 3.3.2
  • init function returns a Promise
  • Add Greenlock v3 example to docs

[1.0.2] - 2019-07-15

  • Bump dependencies

[1.0.1] - 2019-06-17

  • Fix issue where invalid Cloudflare credentials wouldn't be caught and rejected in zones
  • Bump acme-dns-01-test to 3.3.0
  • Add init function to pass new test requirements

[1.0.0] - 2019-06-15

  • Initial production release