Let's Encrypt does not respect changes to `DISCOURSE_DEVELOPER_EMAILS`

AI-generated summary

The discussion addresses a bug where Let’s Encrypt fails to respect changes to LETSENCRYPT_ACCOUNT_EMAIL after the initial setup. User pfaffman reported that modifying the email configuration via DISCOURSE_DEVELOPER_EMAILS resulted in registration errors because the system continued using the original addresses defined in previous configurations, causing Nginx to fail. The immediate workaround was to manually delete the letsencrypt directory (rm /var/discourse/shared/standalone/letsencrypt) before rebuilding.

User mpalmer identified the root cause: the script replacing the ACCOUNT_EMAIL in /shared/letsencrypt/account.conf used a regex pattern that only matched the initial #ACCOUNT_EMAIL= line. Subsequent rebuilds did not match this pattern, preventing the variable from updating. mpalmer suggested adding a ? quantifier to the regex to handle optional matches. This suggestion was clarified with codinghorror and mpalmer briefly. Finally, tgxworld confirmed the fix was implemented in a GitHub commit to the discourse_docker repository.

tl;dr: If you need to change the address LETSENCRYPT_ACCOUNT_EMAIL you need to delete the lets encrypt directory before running it again.

I enabled Let’s Encrypt on a site today. I used a script that copied DISCOURSE_DEVELOPER_EMAILS to LETSENCRYPT_ACCOUNT_EMAIL. I knew it was a bad idea when I wrote the script, but, you know, I was sure that I would never run it when there was more than one email address in DISCOURSE_DEVELOPER_EMAILS. But that’s what I did.

No biggie, I thought, but when I fixed app.yml and rebuilt nginx still wouldn’t come up.

From the logs, @tgxworld, it looks like it’s still trying to register with the original three addresses that were in DISCOURSE_DEVELOPER_EMAILS.

[Tue Mar 14 22:50:34 UTC 2017] Registering account
[Tue Mar 14 22:50:35 UTC 2017] ESC[1;31;40mRegister account Error: {"type":"urn:acme:error:invali
dEmail","detail":"more than one e-mail address","status": 400}ESC[0m
[Tue Mar 14 22:50:35 UTC 2017] ESC[1;31;40mPlease add '--debug' or '--log' to check more details.
ESC[0m
[Tue Mar 14 22:50:35 UTC 2017] ESC[1;31;40mSee: https://github.com/Neilpang/acme.sh/wiki/How-to-d
ebug-acme.shESC[0m
[Tue Mar 14 22:50:35 UTC 2017] Installing key to:/shared/ssl/forum.SITE.org.key
cat: /shared/letsencrypt/forum.SITE.org/forum.SITE.org.key: No such file or directory
[Tue Mar 14 22:50:35 UTC 2017] Installing full chain to:/shared/ssl/forum.SITE.org.cer
cat: /shared/letsencrypt/forum.SITE.org/fullchain.cer: No such file or directory
[Tue Mar 14 22:50:35 UTC 2017] Run Le_ReloadCmd: sv reload nginx
warning: nginx: unable to open supervise/ok: file does not exist
[Tue Mar 14 22:50:35 UTC 2017] ESC[1;31;40mReload error for :forum.SITE.orgESC[0m

and this from the end:

nginx: [emerg] PEM_read_bio_X509_AUX("/shared/ssl/forum.casrai.org.cer") failed (SSL: error:0906D06C:PEM routines:PEM_read_bio:no start line:Expecting: TRUSTED CERTIFICATE)

Finally, I did a rm /var/discourse/shared/standalone/letsencrypt and rebuilt again.

and it worked.

「いいね!」 4

What do you think @tgxworld?

「いいね!」 1

Yep, I see it:

- replace:
   filename: /shared/letsencrypt/account.conf
   from: /#ACCOUNT_EMAIL=.+/
   to: |
     ACCOUNT_EMAIL=$$ENV_LETSENCRYPT_ACCOUNT_EMAIL

That’ll only work on the first rebuild, because after that it isn’t #ACCOUNT_EMAIL= any more. Chuck a ? after # and it’d be fine.

「いいね!」 6

After you mean? Not before.

「いいね!」 3

Yes… that’s what I said… :troll:

「いいね!」 5

Thanks @mpalmer I fixed it in

https://github.com/discourse/discourse_docker/commit/210874a02c56f273eacdbd8aaf288facb97a4894

「いいね!」 6