-
-
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
auto managed domain mistakenly using self-signed #6694
Comments
Seems to be a duplicate of #5933. |
the problem is when I visit |
@mholt Please re-open the issue, Please understand the fully before closing it |
@arpitjindal97 Not sure what I am missing here, please enlighten me. This seems to be a duplicate, as I said. The other issue will track this. |
Because you used
You haven't presented evidence of this.
We haven't seen evidence of this. |
Ignore @mholt @mohammed90 Here is the evidence of this:
|
The certificate CN is literally |
What's the difference between this issue and #5933? |
I have configured the self-signed certificate under for It shouldn't matter what the CN of certificates are. |
@mholt My apologies, you are correct it is related to that issue. I didn't have a closer look earlier. When can we expect a fix? |
|
Even after using 2.9, it doesn't seem to work. wildcard cert is still being picked
|
Caddy 2.9 works fine. You can try reproduce with the following example below to troubleshoot what is going wrong for your actual setup :)
networks:
default:
name: example-net
volumes:
custom-certs:
name: example-tls
services:
reverse-proxy:
image: caddy:2.9
depends_on:
- get-certs
volumes:
- custom-certs:/srv/tls
# Config is embedded for copy/paste of single `compose.yaml` to run example:
configs:
- source: caddy-config
target: /etc/caddy/Caddyfile
# For this example, DNS lookups from containers on this network
# will resolve these FQDN to this Caddy container:
networks:
default:
aliases:
- caddy.example.test
- wild.example.test
- example.test
- sub.example.test
- also-wild.example.test
# Since Caddy depends on this service before it starts,
# compose will first run this service to provision the external certificates:
get-certs:
image: smallstep/step-ca
volumes:
- custom-certs:/tmp/certs/
# This service runs as non-root (1000:1000) by default,
# change to desired UID/GID ownership of certs generated:
user: root
# Support for running the custom script below:
working_dir: /tmp/certs
entrypoint: /tmp/generate-certs.sh
configs:
- source: generate-certs
target: /tmp/generate-certs.sh
# Make script executable:
mode: 500
configs:
caddy-config:
content: |
# Global Settings
{
# Optional: For testing purposes (otherwise defaults to a public CA)
# Have Caddy provision certs locally (self-signed):
local_certs
}
caddy.example.test {
tls force_automate
respond "I am using a certificate provisioned by Caddy"
}
wild.example.test {
respond <<HEREDOC
I am using the external wildcard cert loaded
from the tls directive of another site block
HEREDOC
}
example.test, sub.example.test, also-wild.example.test {
tls /srv/tls/example.test/cert.pem /srv/tls/example.test/key.pem
respond "I am using an externally loaded certificate"
}
# NOTE: For `smallstep/step-ca` container to run it's `step` CLI to create a cert:
generate-certs:
content: |
#!/usr/bin/env bash
mkdir -p ca example.test
step certificate create 'Smallstep Root CA' ca/cert.pem ca/key.pem \
--profile root-ca --no-password --insecure --force
step certificate create 'Smallstep Leaf' example.test/cert.pem example.test/key.pem \
--san 'sub.example.test' --san '*.example.test' \
--ca ca/cert.pem --ca-key ca/key.pem \
--profile leaf --no-password --insecure --force Verify: $ docker compose up -d --force-recreate
$ docker run --rm -it --volume example-tls:/srv/tls --network example-net alpine
$ apk add curl step-cli jq
#
## All sites responding:
#
# NOTE: Insecure flag is used due to Caddy's `local_certs` self-signed CA cert missing:
$ curl --insecure https://caddy.example.test
I am using a certificate provisioned by Caddy
$ curl --insecure https://wild.example.test
I am using the external wildcard cert loaded
from the tls directive of another site block
$ curl --cacert /srv/tls/ca/cert.pem https://sub.example.test
I am using an externally loaded certificate
#
## Certificates used are the ones expected:
#
$ step certificate inspect --insecure --format json https://caddy.example.test \
| jq '{ issuer_dn, subject_dn, names }'
{
"issuer_dn": "CN=Caddy Local Authority - ECC Intermediate",
"subject_dn": null,
"names": [
"caddy.example.test"
]
}
$ step certificate inspect --roots /srv/tls/ca --format json https://wild.example.test \
| jq '{ issuer_dn, subject_dn, names }'
{
"issuer_dn": "CN=Smallstep Root CA",
"subject_dn": "CN=Smallstep Leaf",
"names": [
"sub.example.test",
"*.example.test"
]
}
$ step certificate inspect --roots /srv/tls/ca --format json https://sub.example.test \
| jq '{ issuer_dn, subject_dn, names }'
{
"issuer_dn": "CN=Smallstep Root CA",
"subject_dn": "CN=Smallstep Leaf",
"names": [
"sub.example.test",
"*.example.test"
]
}
# Due to the site-block forcing external via `tls` directive, this will return an invalid cert:
$ step certificate inspect --insecure --format json https://example.test \
| jq '{ issuer_dn, subject_dn, names }'
{
"issuer_dn": "CN=Smallstep Root CA",
"subject_dn": "CN=Smallstep Leaf",
"names": [
"sub.example.test",
"*.example.test"
]
} NOTE: If the site-block with I do not know for |
The wild card certificate I use has |
@arpitjindal97 yes, sorry I missed that 😅 Prior to using SANs for provisioning, the FQDN could be in the leaf certificate That is, yes Caddy would select that externally loaded certificate instead of provisioning a separate one, even if there was no wildcard with that certificate, I also verified that if the FQDN is an explicit SAN as well, this would use the external certificate (or any other one provisioned by Caddy), even with So for your ReferenceThis is a variant of the earlier reference above, specifically tailored to replicate your FQDN + wildcard scenario. I self-contained the networks:
default:
name: example-net
volumes:
custom-certs:
name: example-tls
services:
reverse-proxy:
image: caddy:2.9
depends_on:
- certs
volumes:
- custom-certs:/srv/tls
configs:
- source: caddy-config
target: /etc/caddy/Caddyfile
networks:
default:
aliases:
- arpit.msmartpay.in
- arpit-test.msmartpay.in
# Provision the externally loaded wildcard cert + provide cert inspection:
certs:
image: localhost/certs
volumes:
- custom-certs:/srv/tls
pull_policy: build
build:
dockerfile_inline: |
FROM alpine:3.21
RUN <<HEREDOC
apk add curl jq step-cli
mkdir /srv/tls
HEREDOC
# This is a small shell script that you can with: docker compose run --rm certs cert-info arpit.msmartpay.in
# NOTE: The `$$` is required to escape `$` from the Docker Compose variable interpolation feature.
COPY --chmod=755 <<"HEREDOC" /usr/local/bin/cert-info
#! /usr/bin/env sh
FQDN="$${1}"
curl -w '\n' --insecure "https://$${FQDN}"
step certificate inspect --format json --insecure "https://$${FQDN}" | jq '{ issuer_dn, subject_dn, names }'
HEREDOC
# Provision a locally signed certificate with a private CA root:
# This command is provided via the `exec` format instead of `shell`,
# Thus `ash -c '<string>'` is the equivalent form:
command:
- ash
- -c
- |
cd /srv/tls
mkdir -p ca msmartpay.in
step certificate create 'Smallstep Root CA' ca/cert.pem ca/key.pem \
--profile root-ca --no-password --insecure --force
step certificate create 'Smallstep Leaf' msmartpay.in/cert.pem msmartpay.in/key.pem \
--san 'arpit.msmartpay.in' --san '*.msmartpay.in' \
--ca ca/cert.pem --ca-key ca/key.pem \
--profile leaf --no-password --insecure --force
configs:
caddy-config:
content: |
{
local_certs
auto_https prefer_wildcard
}
# If the wildcard certificate has this site-address as an explicit CN or SAN,
# Caddy will use that certificate instead of provisioning a separate certificate:
arpit.msmartpay.in {
tls force_automate
respond "I should be using a certificate provisioned by Caddy"
}
arpit-test.msmartpay.in {
tls /srv/tls/msmartpay.in/cert.pem /srv/tls/msmartpay.in/key.pem
respond "I am using an externally loaded certificate"
} The CN $ docker compose up -d --force-recreate
$ docker compose run --rm certs cert-info arpit.msmartpay.in
I am using a certificate provisioned by Caddy
{
"issuer_dn": "CN=Smallstep Root CA",
"subject_dn": "CN=Smallstep Leaf",
"names": [
"arpit.msmartpay.in",
"*.msmartpay.in"
]
}
# If you swap the SAN for the leaf cert CN instead:
$ docker compose up -d --force-recreate
$ docker compose run --rm certs cert-info arpit.msmartpay.in
I am using a certificate provisioned by Caddy
{
"issuer_dn": "CN=Smallstep Root CA",
"subject_dn": "CN=arpit.msmartpay.in",
"names": [
"arpit.msmartpay.in",
"*.msmartpay.in"
]
} |
I can't really change wildcard certificate in my production because the impact is bigger. When can we expect a fix for this? |
I'm not a developer for Caddy, I just helped you to properly identify and reproduce the problem. If you do not get a response from a maintainer by like Monday, maybe it's because the issue was close as "Not Planned" and you'd need to open a new issue. If so, just link to my comment above which details what appears to be a bug. Your external certificate has a 10 year expiry and given the CN is clearly self-signed? So I'm not sure why the impact of correcting your certificate is a blocker sorry? It'd be faster to resolve that then wait on a fix to be formally released.
Provisioning a certificate locally without LetsEncrypt is quite simple, as shown above. |
Yes. Caddy sees it as a certificate that already serves that domain. |
Expected Behaviour:
I want to use self-signed certificate for
arpit-test.msmartpay.in
domain only. I want caddy to automatically manage other domains.When i visit
arpit.msmartpay.in
, I should be presented with let's encrypt certificatewhen I visit
arpit-test.msmartpay.in
, I should be presented with self-signed certificateActual Behaviour:
Caddyfile:
domain.crt:
The text was updated successfully, but these errors were encountered: