Error during parsing: Setting up DNS provider 'googlecloud': googlecloud: project name missing

I am trying to setup Caddy to use Googlecloud DNS on my GCP VM.
Looking at the docs, I need to setup these env vars:

  1. GCE_PROJECT
  2. GCE_DOMAIN
  3. GOOGLE_APPLICATION_CREDENTIALS
  4. (or GCE_SERVICE_ACCOUNT_FILE)

I have used the vultr DNS plugin in the past and it worked fine, Caddy runs as the http user on the Arch linux VM.

$ sudo -u http echo $GCE_PROJECT
Asia Wg server
$ sudo -u http echo $GCE_DOMAIN
wsrpna.io
$ sudo -u http echo $GCE_SERVICE_ACCOUNT_FILE
/etc/caddy/gcp.json
$ sudo -u http echo $GOOGLE_APPLICATION_CREDENTIALS
/etc/caddy/gcp.json
$ ls -l /etc/caddy/gcp.json 
-rw-r--r-- 1 http http 2347 Mar  8 13:26 /etc/caddy/gcp.json
$ sudo -u http cat /etc/caddy/gcp.json 
    {
      "type": "service_account",
      "project_id": "Asia-Wg-server",
      "private_key_id": "XXX",
      "private_key": "-----BEGIN PRIVATE KEY-----
      ***snipped***
    }

Caddy error:

Mar 10 18:48:52 systemd[1]: Started Caddy HTTP/2 web server.
Mar 10 18:48:53 caddy[285]: 2019/03/10 18:48:53 [INFO][FileStorage:/var/lib/caddy] Started certificate maintenance routine
Mar 10 18:48:53 caddy[285]: 2019/03/10 18:48:53 /etc/caddy/caddy.conf.d/smokeping.conf:162 - Error during parsing: Setting up DNS provider 'googlecloud': googlecloud: project name missing
Mar 10 18:48:53 systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
Mar 10 18:48:53 systemd[1]: caddy.service: Failed with result 'exit-code'.

I have tried setting GCE_PROJECT to the Project Name and Project ID, the error remains.
It appears the http user can see the env vars and read the credential json, what am I missing here?

How are you setting the env vars, exactly?

You might find that the environment systemd creates for the process is different to what you expect.

On my Arch linux system, I am setting the vars in /etc/bash.bashrc
The sudo -u http xxx tests above indicate the user can read the vars?
I don’t see an option to set env vars in systemd unit files.

A user’s bashrc is read by bash itself when creating a shell for a user. It’s not read by systemd, at least not automatically; systemd doesn’t run programs via a shell.

As for getting those details into your unit file, you can source the bashrc itself, but I’d recommend against that.

You’ll find this reference useful for setting environmental variables for a unit file:

EnvironmentFile= was the solution and if I’d taken some more time to review the supplied caddy systemd unit file, it even points to the non-existent EnvironmentFile=-/etc/caddy/envfile

Thank you!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.