
Caddy will generate a completely new configuration directory and default CA certificate for each “user” you start the service as. The trap gets set if you are attempting to get system trust for the CA configured by running “caddy trust” or start caddy as root on a system. But then you go back to starting caddy using systemctl and the default unit file for it which defines running as user “caddy”. You are showing us symptoms of falling into this trap.
I’m guessing that are importing the caddy root CA certificate from the wrong location. I’m noticing you are focused on /root/.local/* path for the file in what you are sharing , but your systemd unit file is indicating the service is running as caddy. This means you have divergent root CA’s present on the system. When caddy is running, its most likely using its CA config from the /var/lib/caddy/.local/* path instead.
So go check the /var/lib/caddy/.local/* path to verify your root CA is not represented there instead. You can run into issues because the default certificate subject CN for caddy stays the same, but the fingerprint is different, making it hard to identify which certificate is the right one. And if you are “picking” the wrong one you will not be able to establish trust for a TLS connection.
IF YOU DO FIND MORE THAN ONE root.crt, and are confused as to “which one is being used”. You can verify the chain of trust, comparing the “versions” of the root CA you find with the following command:
openssl s_client -connect your.server.ip.or.fqdn:port -CAfile /path/to/file/you/want/to/test/root.crt
You will see a return code of 0 when you are using the proper root CA for the connection,
Here is an example of what I’m talking about from the command line, remember to use ctrl-d to exit the openssl s_client command’s interactive shell.
BAD TEST CASE: First we look at a connection that is failing to establish trust… Note towards the end of the output for the openssl s_client comment indicates failure to get issuers certificate (with a return code of 20, you want that to be 0 to be a proper TLS configuration. We are mapping the CA certificate file out of root’s path with the -CAfile switch to the command. Openssl will apply the root CA certificate you provide it to establish trust.
$ sudo openssl s_client -connect 192.167.37.122:443 -CAfile /root/.local/share/caddy/pki/authorities/local/root.crt
depth=1 CN = Caddy Local Authority - ECC Intermediate
verify error:num=20:unable to get local issuer certificate
CONNECTED(00000003)
---
Certificate chain
0 s:
i:/CN=Caddy Local Authority - ECC Intermediate
1 s:/CN=Caddy Local Authority - ECC Intermediate
i:/CN=Caddy Local Authority - 2021 ECC Root
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIBuDCCAV6gAwIBAgIQbVwt7gPBuMi/SExAxHg2yDAKBggqhkjOPQQDAjAzMTEw
LwYDVQQDEyhDYWRkeSBMb2NhbCBBdXRob3JpdHkgLSBFQ0MgSW50ZXJtZWRpYXRl
MB4XDTIxMDkwNDE4MjYzOVoXDTIxMDkwNTA2MjYzOVowADBZMBMGByqGSM49AgEG
CCqGSM49AwEHA0IABH2vwCTWHz+GuujV8jsI5QTrwnAPmMlgnYm/rbV7mRzL1M3T
kYLlh8z79jGiRu/FWSKOq7K5JIkJk5LNrDoaoL2jgYYwgYMwDgYDVR0PAQH/BAQD
AgeAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAdBgNVHQ4EFgQUdd2z
p/imZXhC3unyF2gp/y4ML1UwHwYDVR0jBBgwFoAUv6yXKX103AhkLraxhQCI9/y3
K24wEgYDVR0RAQH/BAgwBocEwKglejAKBggqhkjOPQQDAgNIADBFAiEAq53etBpH
Uk+FNWSSFOzcp9qK6eT/KsRkaCmRSFy7rV0CIFzU0bpA2GGWQcW8/ACio1OXYLam
XPH9bHskeOAJ+vKp
-----END CERTIFICATE-----
subject=
issuer=/CN=Caddy Local Authority - ECC Intermediate
---
No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 1342 bytes and written 391 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-ECDSA-AES256-GCM-SHA384
Server public key is 256 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-ECDSA-AES256-GCM-SHA384
Session-ID: C4B799F4BD309BCACE15D817228AD614C14C17E9D2490D75867E5A1133864C85
Session-ID-ctx:
Master-Key: 63E3BFBDE712683D56C8EB2AFB2C4B58FE9A79E9A8A4802CBA0FA60374AAF02BFBEFA0BFCFBC751B12976F86355A866E
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket:
0000 - 64 70 33 ee ef 99 97 2b-93 11 37 b7 0c b4 60 ba dp3....+..7...`.
0010 - a7 1b 03 81 69 93 23 35-97 0e 4a 82 bb e5 ab 66 ....i.#5..J....f
0020 - 18 45 48 6a 49 ba 4e ff-59 29 d1 fc 26 f9 b4 ed .EHjI.N.Y)..&...
0030 - 22 d6 80 45 04 82 50 36-d4 91 8e 53 dd 48 45 7d "..E..P6...S.HE}
0040 - 0d e0 f7 da fe 80 ef 67-35 ff 75 c0 4d 37 9e 95 .......g5.u.M7..
0050 - 22 4d 32 26 f7 a8 3a 37-1f 36 a4 f0 7a 0c 98 e0 "M2&..:7.6..z...
0060 - b9 b6 7f 90 ab 0d c9 01-37 a5 6d aa ff 46 7e b3 ........7.m..F~.
0070 - 57 f5 90 a9 a7 aa fa de-d1 ef 2d c1 3f 5e 52 df W.........-.?^R.
0080 - 56 V
Start Time: 1630780585
Timeout : 300 (sec)
Verify return code: 20 (unable to get local issuer certificate)
---
DONE
Now for the “GOOD TEST” using the actual root CA certificate that caddy is actually starting with by default from the systemctl command.
$ sudo openssl s_client -connect 192.167.37.122:443 -CAfile /var/lib/caddy/.local/share/caddy/pki/authorities/local/root.crt
depth=2 CN = Caddy Local Authority - 2021 ECC Root
verify return:1
depth=1 CN = Caddy Local Authority - ECC Intermediate
verify return:1
depth=0
verify return:1
CONNECTED(00000003)
---
Certificate chain
0 s:
i:/CN=Caddy Local Authority - ECC Intermediate
1 s:/CN=Caddy Local Authority - ECC Intermediate
i:/CN=Caddy Local Authority - 2021 ECC Root
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIBuDCCAV6gAwIBAgIQbVwt7gPBuMi/SExAxHg2yDAKBggqhkjOPQQDAjAzMTEw
LwYDVQQDEyhDYWRkeSBMb2NhbCBBdXRob3JpdHkgLSBFQ0MgSW50ZXJtZWRpYXRl
MB4XDTIxMDkwNDE4MjYzOVoXDTIxMDkwNTA2MjYzOVowADBZMBMGByqGSM49AgEG
CCqGSM49AwEHA0IABH2vwCTWHz+GuujV8jsI5QTrwnAPmMlgnYm/rbV7mRzL1M3T
kYLlh8z79jGiRu/FWSKOq7K5JIkJk5LNrDoaoL2jgYYwgYMwDgYDVR0PAQH/BAQD
AgeAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAdBgNVHQ4EFgQUdd2z
p/imZXhC3unyF2gp/y4ML1UwHwYDVR0jBBgwFoAUv6yXKX103AhkLraxhQCI9/y3
K24wEgYDVR0RAQH/BAgwBocEwKglejAKBggqhkjOPQQDAgNIADBFAiEAq53etBpH
Uk+FNWSSFOzcp9qK6eT/KsRkaCmRSFy7rV0CIFzU0bpA2GGWQcW8/ACio1OXYLam
XPH9bHskeOAJ+vKp
-----END CERTIFICATE-----
subject=
issuer=/CN=Caddy Local Authority - ECC Intermediate
---
No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 1343 bytes and written 391 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-ECDSA-AES256-GCM-SHA384
Server public key is 256 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-ECDSA-AES256-GCM-SHA384
Session-ID: BECFE09719FCEB2C9B1A4423AD874E88B82AD78FE1C996147AB535EBA5BC6DD6
Session-ID-ctx:
Master-Key: 3CCB7FFD5A38EC7433B7FFF646FB269C41024A1FF81E7179F8098A6207C34E1BB0587BAA5AB5F710035971B4C251FE71
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket:
0000 - 64 70 33 ee ef 99 97 2b-93 11 37 b7 0c b4 60 ba dp3....+..7...`.
0010 - fb 2d 83 37 a3 2c 94 90-0d d3 7f 85 50 5b 48 1d .-.7.,......P[H.
0020 - 72 b5 5d b8 7c be e8 04-be 3c ac 9a 18 a1 26 fe r.].|....<....&.
0030 - 4d 67 08 ee 69 25 17 f0-3a a7 cb 9e 94 61 c3 63 Mg..i%..:....a.c
0040 - ba 7b a4 1b cc 0b dd e6-6c bb a7 9b a6 d4 e5 91 .{......l.......
0050 - 02 df b4 82 b8 e8 e7 ce-94 bb bb 54 8b 09 20 b2 ...........T.. .
0060 - 87 c9 37 da 35 4c ea 3d-fa 54 56 79 3f 85 aa 24 ..7.5L.=.TVy?..$
0070 - 8e 2b e6 e1 ce d4 0f ca-de f9 06 6a 63 81 c2 b5 .+.........jc...
0080 - f2 .
Start Time: 1630780564
Timeout : 300 (sec)
Verify return code: 0 (ok)
---
DONE