-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Certificate for catch-all site is used for requests to other sites #5933
Comments
Had an oversight and missed a debugging step. Will close for now, until more accurate information is available. |
Finished up the missing debugging and adjusted the content, information, explanation, and title of the issue. Hopefully, I expressed this edge-case clearly and in a helpful way. |
I also tried to add a simple tls directive to the site blocks that didn't have any before: tls email@example.com Unfortunately, this didn't resolve the issue. |
Thanks, will look into this soon! (A little busy with new baby, heh) |
Sounds great! Both of the statements. So, congratulations. |
You might need to play with |
Same issue here, i have my Caddyfile configured like this
Unfortunately, This happens on |
I tried out Maybe it's also because the
Not the main domain, as it is usually the case.
|
As a workaround we switched all hosted sites to using Cloudflares Origin Certificates and the one site that isn't using them doesn't have strict checking of certificates enabled, which also works. Edit: As long as we know the domains that need to be accepted by the site before the first request, we could also use the REST API to add them on the fly. This is the case for us, as customers register them in the application and we send to Cloudflare for SaaS via the API. |
Thanks for the update. Sorry I've been very behind. Turns out an early baby can set you back a few months :) Someone else is welcome to tackle this for a faster resolution. What I'd suggest doing is getting the JSON config, examining it to see if there's an obvious reason why this might be happening. If not, then sprinkle some |
Thanks for giving this issue some visibility in the feature discussion #6146 (comment) @polarathene. @mholt family comes first, I know this too well. Thanks for responding and providing some starting points for people with the skills and will to tackle this, even though nobody picked it up for now. |
Reproducing the behaviorCaddyfile config{
debug
#auto_https ignore_loaded_certs
}
subdomain.example.localhost {
respond "Subdomain!"
}
*.example.localhost {
tls cert.pem key.pem
respond "Wildcard!"
} Generate key pairCreated a cert/key pair: Running Caddy, no certificate is obtained for Validating ignore_loaded_certsUn-commenting the
This is expected because Adapted configThen running: ...
"tls_connection_policies": [
{
"match": {
"sni": [
"*.example.localhost"
]
},
"certificate_selection": {
"any_tag": [
"cert0"
]
}
},
{}
],
"automatic_https": {
"ignore_loaded_certificates": true
}
}
}
},
"tls": {
"certificates": {
"load_files": [
{
"certificate": "cert.pem",
"key": "key.pem",
"tags": [
"cert0"
]
}
]
}
}
}
} you can see the The second policy is empty/default, meaning "use automated certificates to handle everything else". Analysis
The issue may be unexpected behavior coming from the adapted JSON config, which programs Caddy to use the manually-loaded cert first, then try automated certs later. Technically, I don't think there is a bug here. But I can see how it is unexpected. I am not sure I see a clear/obvious solution though. @francislavoie do you have any ideas? |
I am familiar with JSON in general, but have never used Caddy to configure it that way, and I am not skilled in reading/interpreting it. The config options of the Caddyfile have always been sufficient to me. My assumption was, that the most specific configuration will "win" and a specific site's configuration will be used over a wildcard one. |
Yeah IMO that config is working as intended. But we should probably add an option in the Caddyfile which forces issuance & adds a connection policy for a particular domain, which would take priority over other loaded certs which might overlap. I had started an implementation of that a couple months ago but never finished it (sidetracked, life happened, worked on other things). I don't think I pushed that branch anywhere yet. I had set up the Caddyfile wiring but I didn't finish applying it to the output JSON correctly yet. I'll see if I can do that in the coming days. But anyway iirc the config looked something like |
Thank you and great to hear, that there is already something in the works to get this working. I think the default behaviour of using loaded certs generally makes sense, but not if they have not been loaded for that specific site. |
If you run |
Okay I have an implementation now: #6712, I'd appreciate if it could be tested out. Basically, just add |
@francislavoie thank you for that. I have already built and tested it with success: #6712 (comment) To get a better understanding of the resulting JSON config, I tried the caddy's
A curious thing I saw was, only the domains of "app2" being listed in
At the same time, all domains from all sites are listed in
Here is a reduced (2 sites instead of 15) and redacted (PII removed) excerpt: https://gist.github.com/SimJoSt/fdeb88cc35333952d1e2b75a2c3a4658 |
The issue is that the certificate loaded via the tls directive from files in the second site block for website2, containing a catch-all, is used for all request to caddy. Only the certificate is used.
The content is still used from the requested domain/site/block. Meaning, each request returns the wanted content from the requested application, just the certificate is from completely different site block.
For example,
https://subdomain.website1.com
returns certificate 2, when certificate 1 is expected.Expected behaviour would be:
https://subdomain.website1.com
-> certificate 1https://www.website1.com
-> certificate 2https://www.website2.com
-> certificate 2https://www.example.com
-> certificate 2https://test.website2.com
-> certificate 2However, certificate 2 is returned every time.
Caddy is only hit with
https
requests.http
requests orhttp
tohttps
redirects don't play a role.The following docs lead me to believe, I configured this correctly and like it was intended:
Things that were tried:
:443
withhttps://
Main Caddyfile:
website1 Caddyfile (uses automatic https, no tls directive is configured):
subdomain.website1.com { ... }
website2 Caddyfile:
Caddy version: v2.7.5
Modules:
The text was updated successfully, but these errors were encountered: