Add option to disable DNS ACME provider#290

Merged
momar merged 10 commits from histausse/pages-server:main into main 2024-04-18 19:05:20 +02:00
Contributor

This PR add the $NO_DNS_01 option (disabled by default) that removes the DNS ACME provider, and replaces the wildcard certificate by individual certificates obtained using the TLS ACME provider.

This option allows an instance to work without having to manage access tokens for the DNS provider. On the flip side, this means that a certificate can be requested for each subdomains. To limit the risk of DOS, the existence of the user/org corresponding to a subdomain is checked before requesting a cert, however, this limitation is not enough for an forge with a high number of users/orgs.

This PR add the `$NO_DNS_01` option (disabled by default) that removes the DNS ACME provider, and replaces the wildcard certificate by individual certificates obtained using the TLS ACME provider. This option allows an instance to work without having to manage access tokens for the DNS provider. On the flip side, this means that a certificate can be requested for each subdomains. To limit the risk of DOS, the existence of the user/org corresponding to a subdomain is checked before requesting a cert, however, this limitation is not enough for an forge with a high number of users/orgs.
rename ownerExistance->ownerExistanceKeyPrefix
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
75499672fd
Author
Contributor

I cannot see the comment on the interface. I guessed the issue from the content of the notification mail but that's quite inconvenient.
Is the comment problem just with me?

I cannot see the comment on the interface. I guessed the issue from the content of the notification mail but that's quite inconvenient. Is the comment problem just with me?
Owner

That's a really funny behavior: I started a review and then got interrupted by real world stuff and couldn't finish it, sorry.

image

I think that's a bug, I'll talk to the forgejo people and open a ticket if they also think that's a bug.

That's a really funny behavior: I started a review and then got interrupted by real world stuff and couldn't finish it, sorry. ![image](/attachments/274da6ae-b3fb-48e7-a590-519c4c83fd7f) I think that's a bug, I'll talk to the forgejo people and open a ticket if they also think that's a bug.
existance->existence
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
51d331d658
crapStone requested review from 6543 2024-02-26 14:54:16 +01:00
Owner

LGTM!

I don't know much about the acme code so I requested a review from @6543, because he has much more knowledge than me.

@histausse sorry for the long delay

LGTM! I don't know much about the acme code so I requested a review from @6543, because he has much more knowledge than me. @histausse sorry for the long delay
Author
Contributor

Any news?

Any news?
Owner

ping @6543

ping @6543
@ -33,6 +33,8 @@ func TLSConfig(mainDomainSuffix string,
firstDefaultBranch string,
keyCache, challengeCache, dnsLookupCache, canonicalDomainCache cache.ICache,
certDB database.CertDB,
noDNS01 bool,
Contributor

well I dont like to see this func get more args ... but well whatever

well I dont like to see this func get more args ... but well whatever
crapStone marked this conversation as resolved
@ -67,3 +69,2 @@
if strings.HasSuffix(domain, mainDomainSuffix) || strings.EqualFold(domain, mainDomainSuffix[1:]) {
// deliver default certificate for the main domain (*.codeberg.page)
domain = mainDomainSuffix
Contributor

instead of use domain and let it be not set to mainDomainSuffix I would rather create a dedicated bool value that we do check against ...

instead of use `domain` and let it be not set to `mainDomainSuffix` I would rather create a dedicated bool value that we do check against ...
Contributor

the current code works like that ... but I would say it's a technical debt and should be cleaned up anyway

the current code works like that ... but I would say it's a technical debt and should be cleaned up anyway
Author
Contributor

What information would the bool value contain? Whether or not to use the wildcard cert? I can try to do that but it will probably lead to modifying some part of the code I'm not sure to understand.

What information would the bool value contain? Whether or not to use the wildcard cert? I can try to do that but it will probably lead to modifying some part of the code I'm not sure to understand.
Owner

I think we can leave it like it is. Nobody understands the reasoning of every last bit of this code, so we shouldn't introduce large changes.

I think we can leave it like it is. Nobody understands the reasoning of every last bit of this code, so we shouldn't introduce large changes.
Contributor

ok in that case let it merge and i try to send a smal patch to make it bit better

ok in that case let it merge and i try to send a smal patch to make it bit better
@ -223,0 +241,4 @@
if name == mainDomainSuffix {
mock_domain = "*" + mainDomainSuffix
}
return mockCert(mock_domain, "DNS ACME client is not defined", mainDomainSuffix, keyDatabase)
Author
Contributor

This if can be remove if we remove

if useDnsProvider && domains[0] != "" && domains[0][0] == '*' {
domains = domains[1:]
}

@6543 do you know what the test at L202 is for? I'm guessing it was for the dummy provider in the CI that does not suport DNS 01 but this PR replace the calls to the DNS 01 provider by a self signed certificat when it is not defined so it is not a problem anymore. (And this has the benefit of fixing #235, but I don't know if there are any hidden side-effects)

This if can be remove if we remove https://codeberg.org/Codeberg/pages-server/src/commit/7e80ade24b8aac072804122b343a2a1a70667983/server/certificates/certificates.go#L202-L204 @6543 do you know what the test at L202 is for? I'm guessing it was for the dummy provider in the CI that does not suport DNS 01 but this PR replace the calls to the DNS 01 provider by a self signed certificat when it is not defined so it is not a problem anymore. (And this has the benefit of fixing #235, but I don't know if there are any hidden side-effects)
Contributor

yes that's correct

yes that's correct
Merge branch 'main' into main
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
376d4e0b7c
histausse force-pushed main from 9e5df1ab05
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
to 6fc224b359
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
2024-03-26 13:12:25 +01:00
Compare
fix lint
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful
ec2a9e6f28
Author
Contributor

Sorry about the commit mess, I'm not on my usual computer.
This simplify a little the handling of wildcard certificate and fix #235 without breaking the integration tests.

Sorry about the commit mess, I'm not on my usual computer. This simplify a little the handling of wildcard certificate and fix #235 without breaking the integration tests.
Owner

No worries, and thank you for working on this! I had a quick look 2 days ago and stumbled upon some issues where I'll yet have to confirm whether or not they're caused by this PR; I think they probably have been caused somewhere earlier.

From my point of view, we can remove all mentions of acme.mock.directory from the code (and just leave it in the docs) with this PR.

No worries, and thank you for working on this! I had a quick look 2 days ago and stumbled upon some issues where I'll yet have to confirm whether or not they're caused by this PR; I think they probably have been caused somewhere earlier. From my point of view, we can remove all mentions of acme.mock.directory from the code (and just leave it in the docs) with this PR.
Owner

Alright, I've tried it out, issues were due to misconfiguration on my side, but now it seems to work fine. No errors in local development without NO_DNS_01, and no issues with NO_DNS_01 and no provider, and no issues with NO_DNS_01 and a provider being set. It helps a lot that the PAGES_DOMAIN is since some time only treated as a suffix and when called directly is handled completely as a custom domain - the earlier approach is where the code mentioned in #296 is coming from.

Alright, I've tried it out, issues were due to misconfiguration on my side, but now it seems to work fine. No errors in local development without NO_DNS_01, and no issues with NO_DNS_01 and no provider, and no issues with NO_DNS_01 and a provider being set. It helps a lot that the PAGES_DOMAIN is since some time only treated as a suffix and when called directly is handled completely as a custom domain - the earlier approach is where the code mentioned in #296 is coming from.
momar approved these changes 2024-03-29 22:41:23 +01:00
momar merged commit 03881382a4 into main 2024-04-18 19:05:20 +02:00
Sign in to join this conversation.
No description provided.