Two different env Cloudflare email and key => Caddyfile

Hello guys,
I have tried to use supervisor plugin to set env, doesn’t work. The goal was set different EMAIL and APIKEY to different websites/accounts into Cloudflare.

When I use only one CF account into caddy.service, for example, exerything works like a charm. But I have different domains in different CF accounts.

How to solve it? Thanks in advanced.

Caddy only ever reads from one set of ENV vars, so using the environment with multiple accounts isn’t possible.

That said, you can actually set the credentials inside the Caddyfile, on a per-site basis.

tls {
  dns cloudflare email@example.com apikey
}

syslog:

/etc/caddy/cloudflare.Caddyfile:13 - Error during parsing: Wrong argument count or unexpected line ending after '_myapikey_hidden_of_course_'
caddy.service: Main process exited, code=exited, status=1/FAILURE
caddy.service: Failed with result 'exit-code'.

My cloudflare.Caddyfile imported into Caddyfile

(cf_tls) {
        tls {
                dns cloudflare my@email.hidden my_api_37_chars_hidden
        }
}

Edit: I have tried to not use snippets and insert the tls directly, doesn’t work also.

What I’m doing wrong?

Ahh, damn… I think I was wrong about that one.

The DNS provider plugin for Cloudflare supports it in code:

But the dns subdirective is programmed to error on >1 argument:

https://github.com/mholt/caddy/blob/6115a462c76b375902a790f49f4669f55f9692d6/caddytls/setup.go#L233-L237

So it never gets there. With that being the case, it’s not possible to have more than one account per DNS provider, it seems.

Easy enhancement to make, fortunately.

2 Likes