npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

acme-dns-01-cloudflare

v1.2.5

Published

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

Downloads

821

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: "[email protected]"
});

greenlock.manager.defaults({
	agreeToTerms: true,
	subscriberEmail: "[email protected]",
	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: '[email protected]',
	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