0

I have configured Chrony server and client on two Centos 9 Stream machines. Without NTS everything is fine and the time is being synced. However, when I enable NTS, and configure the server to use certificate, the sync is failing. Any idea what the issue might be? Below is the server and client config:

Server:

[root@server1 ~]# cat /etc/chrony.conf
pool 2.centos.pool.ntp.org iburst
sourcedir /run/chrony-dhcp
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 192.168.11.0/24
keyfile /etc/chrony.keys
ntsdumpdir /var/lib/chrony
leapsectz right/UTC
logdir /var/log/chrony

ntsserverkey /etc/certs/chrony.key
ntsservercert /etc/certs/chrony.crt
[root@server1 ~]# cat /etc/chrony.keys
1 MD5 AVeryLongAndRandomPassword

Client:

[root@client1 ~]# cat /etc/chrony.conf
sourcedir /run/chrony-dhcp
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
keyfile /etc/chrony.keys
ntsdumpdir /var/lib/chrony
leapsectz right/UTC
logdir /var/log/chrony
server server1 iburst nts
[root@client1 ~]# cat /etc/chrony.keys
1 MD5 AVeryLongAndRandomPassword

Sync test:

[root@client1 ~]# chronyd -Q -t 3 'server server1 iburst nts maxsamples 1'
2022-08-06T23:23:52Z chronyd version 4.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +NTS +SECHASH +IPV6 +DEBUG)
2022-08-06T23:23:52Z Disabled control of system clock
2022-08-06T23:23:52Z TLS handshake with 192.168.11.29:4460 (server1) failed : The TLS connection was non-properly terminated.
2022-08-06T23:23:55Z chronyd exiting

When checking the capture, it seems that the server terminates the connection after receiving the client hello:

enter image description here

1 Answer 1

1

Is the certificate used by your NTS server trusted by your client? I tried to reproduce your configuration and I was able to get things working.

Server setup

I started by generating a self-signed certificate for use by the server:

server# cd /etc/chrony
server# openssl req -x509 -nodes -newkey rsa:4096 \
  -keyout chrony.key -out chrony.crt \
  -sha256 -days 365 -subj /CN=server1

I configured the server like this:

pool 2.centos.pool.ntp.org iburst
sourcedir /run/chrony-dhcp
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 192.168.11.0/24
keyfile /etc/chrony.keys
ntsdumpdir /var/lib/chrony
leapsectz right/UTC
logdir /var/log/chrony

ntsserverkey /etc/certs/chrony.key
ntsservercert /etc/certs/chrony.crt

I started the server in debug mode to test it out and saw an error ("Could not set credentials").

server# chronyd -d
2022-08-08T00:54:52Z chronyd version 4.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +NTS +SECHASH +IPV6 +DEBUG)
2022-08-08T00:54:52Z Frequency 0.765 +/- 3.876 ppm read from /var/lib/chrony/drift
2022-08-08T00:54:52Z Could not set credentials : Error while reading file.
2022-08-08T00:54:52Z Using right/UTC timezone to obtain leap second data

The error was caused by the permissions on /etc/certs/chrony.key, which was owned by root and mode 0600. I made it owned by the chrony user:

server# chown chrony /etc/certs/*

Now when I start chronyd -d on the server it runs without errors.

Client setup

On the client, I used your config file:

sourcedir /run/chrony-dhcp
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
keyfile /etc/chrony.keys
ntsdumpdir /var/lib/chrony
leapsectz right/UTC
logdir /var/log/chrony
server server1 iburst nts

When I first tried start chronyd -d, I saw the following error:

2022-08-08T01:01:06Z TLS handshake with 192.168.122.17:4460 (server1)
failed : Error in the certificate verification. The certificate is NOT
trusted. The certificate issuer is unknown.

That's expected, since I'm using a self-signed certificate. To fix that, we can install the certificate as a trusted certificate. On my system (Fedora, which should match your CentOS system), that means installing it into /etc/pki/ca-trust/source/anchors and then running update-ca-trust:

client# cat > /etc/pki/ca-trust/source/anchors/server1.crt
<paste certificate here>
^D
client# update-ca-trust

Now when I run chronyd -d I don't see any errors. Additionally, the client successfully connects to the server:

2022-08-08T01:03:36Z Selected source 192.168.122.17 (server1)

And running chronyc -N authdata shows:

client# chronyc -N authdata
Name/IP address             Mode KeyID Type KLen Last Atmp  NAK Cook CLen
=========================================================================
server1                      NTS     1   15  256   45    0    0    8  100
8
  • Thank you @larsks. In my case, the CA certificate is trusted by the client. Actually before posting the question, I tested with self-signed certificate as well. In that case, I am receiving a different error: 2022-08-07T00:28:11Z TLS handshake with 192.168.11.29:4460 (server1) failed : Error in the certificate verification. The certificate is NOT trusted. The certificate chain uses not yet valid certificate. When checking the capture, this time server does send Server Hello and Change Cipher Spec, but the Server Certificate is missing!
    – Reza
    Commented Aug 8, 2022 at 20:42
  • [root@client1 ~]# ll /etc/pki/ca-trust/source/anchors/selfsigned.crt -rw-r--r-- 1 root root 1801 Aug 7 03:21 /etc/pki/ca-trust/source/anchors/selfsigned.crt [root@client1 ~]# update-ca-trust [root@client1 ~]# chronyd -Q -t 3 'server server1 iburst nts maxsamples 1' ...skipping... 2022-08-07T00:28:11Z Disabled control of system clock 2022-08-07T00:28:11Z TLS handshake with 192.168.11.29:4460 (server1) failed : Error in the certificate verification. The certificate is NOT trusted. The certificate chain uses not yet valid certificate. 2022-08-07T00:28:14Z chronyd exiting
    – Reza
    Commented Aug 8, 2022 at 20:43
  • This all worked for me. It's not clear from your comments what you've done that's different. I've repeated this test on a pair of centos 9 hosts and it worked fine there, also. The only way I can generate the "The TLS connection was non-properly terminated." is by having an incorrect allow configuration on the server, causing it to reject the client and terminate the connection.
    – larsks
    Commented Aug 9, 2022 at 2:34
  • Larsks if you still have this setup, could you please check if the sync stops in case of key mismatch?
    – Reza
    Commented Sep 16, 2022 at 20:03
  • 1
    I believe that static keys (as configured with keyfile and the server ... key ... option) are unused when you have configured NTS security.
    – larsks
    Commented Sep 17, 2022 at 21:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .