Renewal issue when using AppArmor (resolved)

My certificate would not renew either automatically or manually. I did not find an answer when searching the forum or internet in general so I'm posting here so others may be able to find it in the future.

I'm running Ubuntu with Apache and AppArmor. Apparmor. When running certbot -v renew manually, it gave the error

Bad keystroke posted before I was ready...

The error returned was

Domain: www.ixeous.net
Type: unauthorized
Detail: 174.80.174.41: Invalid response from http://www.ixeous.net/.well-known/acme-challenge/SKTokUxW_J8PiAMKdcJUUkmPBL5qiXAbRVtimbLJ2nc: 403

There was also a syslog message of

audit: type=1400 audit(1792765044.930:182): apparmor="DENIED" operation="open" class="file" profile="/usr/sbin/apache2" name="/var/lib/letsencrypt/http_challenges/SKTokUxW_J8PiAMKdcJUUkmPBL5qiXAbRVtimbLJ2nc" pid=70677 comm="apache2" requested_mask="r" denied_mask="r" fsuid=33 ouid=0

I simply needed to add this line to the apparmor profile for apache2

/var/lib/letsencrypt/http_challenges/** r,

And reread via apparmor_parser

Did you add Apache to the AppArmor profile with enforce mode?

Because Apache isn't there by default on Ubuntu (or hasn't been anyway).

If so it is reasonable to need to add that path when using the --apache plugin with Certbot. That is the path it uses for the challenge token files so Apache would need access to that path.

In general, it is a good idea to test Certbot's renewal procedure after a system change.

sudo certbot renew --dry-run

This will not affect any production certs or your Apache config. It is a test only

In addition to the syslog the Apache error and access logs would have had info about the reason it issued a 403 Forbidden.

Yes, I did enable AppArmor. When the certificate did not renew as expected, I was not able to find any info specific to renewal and AppArmor and figured the one-liner fix might be useful. Also, the failure proved AppArmor did it's job so confidence boosted.