Skip to content

ACME certificate fails to renew (incorrect directory) #32191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Jburso opened this issue Oct 4, 2024 · 9 comments · Fixed by #33072, #33668 or #33807
Closed

ACME certificate fails to renew (incorrect directory) #32191

Jburso opened this issue Oct 4, 2024 · 9 comments · Fixed by #33072, #33668 or #33807
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug

Comments

@Jburso
Copy link

Jburso commented Oct 4, 2024

Description

ACME renewal fails due to certmagic trying to find the certificate in the wrong directory. Initial issuance works just fine though. Certificates located in /var/lib/gitea/https/certificates/ca.mydomain.com-acme-acme-directory/ but renewals check for the certificate in /var/lib/gitea/.local/share/certmagic/certificates/acme-v02.api.letsencrypt.org-directory/.

certmagic prints: error while checking if stored certificate is also expiring soon

Relevant parts of my config are below:

; ACME support

PROTOCOL = https
ENABLE_ACME = true
ACME_ACCEPTTOS = true
ACME_URL = https://ca.mydomain.com/acme/acme/directory
ACME_DIRECTORY = https
ACME_EMAIL = nan@nan

Gitea Version

1.21.9

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

https://gist.github.com/Jburso/5004c35ad7f4a0260a85a9044c3802f5

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Running on Alpine 3.20.3 and installed through the community v3.20 repo

Database

SQLite

@Jburso Jburso added the type/bug label Oct 4, 2024
@EmperorEarth
Copy link

Got the same on Forgejo 7.x/Gitea 1.21.x. Converting to Gitea paths, I was able to bandaid until bugfix with something like:

	sudo cp -r /var/lib/gitea/https/certificates /var/lib/gitea/.local/share/certmagic/certificates
	sudo systemctl stop gitea
	sudo systemctl start gitea

Both directories were updated during the certificate renewal.

Note: I'm not sure manually stopping and starting the SystemD daemon was necessary.

@wxiaoguang
Copy link
Contributor

I think this will fix: Try to fix ACME directory problem #33072

@lunny
Copy link
Member

lunny commented Jan 2, 2025

It seems that for some reason, magic.Storage = &certmagic.FileStorage{Path: setting.AcmeLiveDirectory} doesn’t appear to be taking effect.

@wxiaoguang
Copy link
Contributor

doesn’t appear to be taking effect.

Actually it takes effect.

wxiaoguang added a commit that referenced this issue Jan 2, 2025
Backport #33072 by wxiaoguang

Haven't really confirmed, but I think it might fix #32191

Co-authored-by: wxiaoguang <[email protected]>
@Jburso
Copy link
Author

Jburso commented Feb 21, 2025

After testing on v1.23.3, where the above fix was merged, I am still getting an incorrect path when a certificate renewal is being attempted. /var/lib/gitea/https/certificates/ca.mydomain.com-acme-acme-directory/ is the correct directory but the renewal attempts to access /var/lib/gitea/https/certificates/acme-v02.api.letsencrypt.org-directory/. The root directory is now correct, but it seems like there's an assumption that LetsEncrypt is being used when that's not the case.

This issue does not seem to occur immediately after gitea is restarted.

I think this issue should be reopened.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Feb 21, 2025

/var/lib/gitea/https/certificates/ca.mydomain.com-acme-acme-directory/ is the correct directory but the renewal attempts to access /var/lib/gitea/https/certificates/acme-v02.api.letsencrypt.org-directory/. The root directory is now correct, but it seems like there's an assumption that LetsEncrypt is being used when that's not the case.

If I understand correctly, that directory is from CA (aka setting.AcmeURL => ACME_URL). If you use the default ACME service (letsencpryt), then the URL is https://acme-v02.api.letsencrypt.org/directory, then it uses .../https/certificates/acme-v02.api.letsencrypt.org-directory. If you use a customized ACME service https://ca.mydomain.com/acme/acme/directory, then it becomes .../https/certificates/ca.mydomain.com-acme-acme-directory.

At the moment, I don't see the logic on Gitea side is changed. #33072 and its following up fix only set the global default storage path.

So maybe it is a misconfiguration or the ACME package's problem?

@wxiaoguang
Copy link
Contributor

The best guess from my side is like this " Fix ACEM path when renew #33668 "(see the comment)

And @techknowlogick , the certmagic code is from "Use caddy's certmagic library for extensible/robust ACME handling (#14177)"

wxiaoguang added a commit that referenced this issue Feb 23, 2025
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Feb 23, 2025
wxiaoguang added a commit that referenced this issue Feb 23, 2025
Backport #33668 by wxiaoguang

Try to fix #32191

Co-authored-by: wxiaoguang <[email protected]>
@wxiaoguang

This comment has been minimized.

@wxiaoguang wxiaoguang reopened this Mar 5, 2025
@wxiaoguang wxiaoguang changed the title ACME certificate fails to renew ACME certificate fails to renew (incorrect directory) Mar 5, 2025
@wxiaoguang wxiaoguang added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Mar 5, 2025
@wxiaoguang
Copy link
Contributor

The last try: Try to fix ACME (3rd) #33807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug
Projects
None yet
4 participants