-
Notifications
You must be signed in to change notification settings - Fork 159
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
overlay: Add 21dhcp-chrony to set default DHCP NTP settings #412
overlay: Add 21dhcp-chrony to set default DHCP NTP settings #412
Conversation
As I said in the BZ I believe this applies to not just all of Fedora/RHEL, but any distribution combining NetworkManager and chrony and using the Another option is for this to be directly built into the NM sources - dynamically detect if chrony is running and if so talk to it. |
To be clear I'm opposed to landing this here first, but it seems like it shouldn't be too hard to land in e.g. https://git.tuxfamily.org/chrony/chrony.git/tree/contrib |
👍 - aiming to upstream the Another option for the short term is installing Will focus on getting the upstream patch approved first, then we could either carry the patch in an overlay, or install |
I'm totally fine carrying this work in this repo while we wait for the upstream bits to land and percolate!
Yeah, the NM developers also have had hesitation about the But...man at one point I also had occasion to read the dhclient code and...it's not the most beautiful. I'd take systemd code over that any day - and part of that I think is pushing for NM and systemd-networkd share more code. (Of course what we really want is a nice clean dhcp library/process in Rust 😉 ) |
I think this should be handled okay - from local testing, the But agreed - we do want to make sure to remove this shortly after upstream patches land (maybe a note in the overlay.d README will be visible enough for now). I wonder if some general automation/notification would be useful for detecting when patches have made it downstream too (I remember some mention of automation for notifying when bodhi updates for lockfile overrides land). Difficult part would be detecting where a patch is, would probably just require checking for new upstream changes (e.g. a bot that subscribes to the
Thank you for the extra context! Just to clarify the option I mentioned - installing the
Heh - I see the Overall, will finish testing the upstream patch, and will update this PR with the same patch to have an updated copy here ready. |
fe31be7
to
764efd6
Compare
Updated with latest changes which have been tested with FCOS - I have received feedback on the ML since proposing these changes, and will be revising. |
764efd6
to
92d6c37
Compare
Saw Updated this PR with the latest changes proposed to upstream, with an additional edit to prevent running if the upstream changes land while this is overlaid. The two files can be generated by:
Manually applying these files to
Will now check these changes using the |
The changes proposed for the downstream package (includes the proposed upstream patches sent to the chrony-dev mailing list): https://src.fedoraproject.org/rpms/chrony/pull-request/3 |
dd3ee16
to
d71f5de
Compare
This is debatable, but I think we should generally defer to the platform chrony config over DHCP. I don't know if we get NTP via DHCP on any of those platforms, but I can't think of any downside of using the link-local NTP (or in Azure's case the even better virtual PHC). IOW, let's add a:
in here. (And that won't race because the former runs as a generator, before we do DHCP) |
d8134d4
to
49bfeed
Compare
Makes sense - added now! With the upstream patches in their present state (https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00027.html, https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00028.html), I realize the upstream change should also address the need to override platform specific config. Otherwise, As long as the upstream changes to use dropins when handling DHCP-specified NTP servers are made, we should be safe carrying this without the introducing a regression later on where the check on |
49bfeed
to
8846697
Compare
This one is ready for review - lifted WIP. The steps I used to test this (no need to run through unless verifying), but posting here for a record / in case it helps. High level: configure a custom DHCP server statically routed within a NAT network in libvirt, have other hosts obtain an IP address from the custom DHCP server, and check whether the hosts receive the NTP servers set on the DHCP server. This will require:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few optional changes; overall I'm OK to merge as is too!
overlay.d/21dhcp-chrony/etc/NetworkManager/dispatcher.d/20-coreos-chrony
Outdated
Show resolved
Hide resolved
echo " list-static-sources" | ||
echo " set-static-sources < sources.list" | ||
echo " is-running" | ||
echo " command CHRONYC-COMMAND" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow a lot going on here. But I guess we're just copying the bits that came from upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - decided to just keep all of the bits from the chrony.helper
script, which the same between Fedora 32, 33 and RHEL8. The only part we really need is update-daemon
. Should have included a diff earlier - this is the diff between the original and this PR:
diff --git a/helper-f33 b/overlay.d/21dhcp-chrony/usr/libexec/coreos-chrony-helper
old mode 100644
new mode 100755
index 95414af..46784a3
--- a/helper-f33
+++ b/overlay.d/21dhcp-chrony/usr/libexec/coreos-chrony-helper
@@ -1,4 +1,12 @@
#!/bin/bash
+
+# This is a copy of /usr/libexec/chrony-helper carried in FCOS/RHCOS
+# temporarily while upstream changes and the package update to
+# chrony-helper percolate (see
+# https://src.fedoraproject.org/rpms/chrony/pull-request/3). It should
+# not by used by any script other than the 20-coreos-chrony NM
+# dispatcher script.
+
# This script configures running chronyd to use NTP servers obtained from
# DHCP and _ntp._udp DNS SRV records. Files with servers from DHCP are managed
# externally (e.g. by a dhclient script). Files with servers from DNS SRV
@@ -9,10 +17,20 @@ chronyc=/usr/bin/chronyc
chrony_conf=/etc/chrony.conf
chrony_service=chronyd.service
helper_dir=/var/run/chrony-helper
-added_servers_file=$helper_dir/added_servers
+server_dir=/var/lib/chrony/servers
+
+# If dhclient is installed, the 11-dhclient NetworkManager dispatcher script
+# will have the necessary integration to bring NTP servers from NM/DHCP into
+# chrony. The chrony dispatcher script (20-chrony) will not take action when
+# a dhclient installation is detected. Therefore, make sure we are using the
+# dhclient state directory `/var/lib/dhclient`.
+if [ -e /usr/sbin/dhclient ]; then
+ server_dir=/var/lib/dhclient
+fi
network_sysconfig_file=/etc/sysconfig/network
-dhclient_servers_files="/var/lib/dhclient/chrony.servers.*"
+dhcp_servers_files="${server_dir}/chrony.servers.*"
+added_servers_file=$helper_dir/added_servers
dnssrv_servers_files="$helper_dir/dnssrv@*"
dnssrv_timer_prefix=chrony-dnssrv@
@@ -27,7 +45,7 @@ is_running() {
}
get_servers_files() {
- [ "$PEERNTP" != "no" ] && echo "$dhclient_servers_files"
+ [ "$PEERNTP" != "no" ] && echo "$dhcp_servers_files"
echo "$dnssrv_servers_files"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part I added to the original
+if [ -e /usr/sbin/dhclient ]; then
+ server_dir=/var/lib/dhclient
+fi
is also dead code, as the NM dispatcher script will not run coreos-chrony-helper
at all if dclient
is detected, but my aim was to keep it in line with the proposal in: https://src.fedoraproject.org/rpms/chrony/pull-request/3#_4__30, such that coreos-chrony-helper
could replace chrony-helper
and still work with dhclient if we needed. Will leave it in for now - we will be coming back to this for sure when landing changes from chrony upstream.
rm -f "$dhcp_server_file" | ||
|
||
# Don't add NTP servers if PEERNTP=no specified; return early. | ||
[ "$PEERNTP" = "no" ] && return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this is dead code for FCOS which doesn't support /etc/sysconfig/network-scripts
(that's fine, we need it for RHCOS), and other Fedora editions need it too even.
It also doesn't support NM keyfiles but that's something we can investigate later.
overlay.d/21dhcp-chrony/etc/NetworkManager/dispatcher.d/20-coreos-chrony
Outdated
Show resolved
Hide resolved
8846697
to
95f6d3d
Compare
Realized having the generator write Also confirmed that the upstream dispatcher name will be Did some tests to check the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't validate the details here...a lot going on and I'd be much more confident if we had even a manual test for this. But overall seems sane.
# TODO: once https://bugzilla.redhat.com/show_bug.cgi?id=1828434 is | ||
# resolved, this won't be required. | ||
if [ ! -e /etc/sysconfig/network ] || ! grep -q "PEERNTP" /etc/sysconfig/network; then | ||
cat <<EOF >> /etc/sysconfig/network |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait but...is this file actually read on FCOS today? That's part of the "initscripts networking" bits...which NetworkManager might read...let me see.
It does look like it reads /etc/sysconfig/network
, but rg -i peerntp
has zero hits in NM git.
Ahh but I see, we're sourcing that ourselves in the other script. OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - as far as I could tell, only the script added here, and the dhclient handler shipped in chrony, https://src.fedoraproject.org/rpms/chrony/blob/cafc2b7a759c623057666ae578e847c78b6e7811/f/chrony.dhclient#_7, will read that environment variable. If something else is installed and happens to read and parse PEERNTP=no
and not propagate the time sources (e.g. dhclient
or ntpd
), it should be expected behavior that the cloud time source is used by default when on the cloud platform and DHCP sources are not propagated.
echo "$server" | ||
done) | sort -u) | ||
|
||
comm -23 <(echo -n "$added_servers") <(echo -n "$all_servers") | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a comm
ent here, I have never seen comm
used before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was a first for me too :)
update_daemon() { | ||
local all_servers_with_args all_servers added_servers | ||
|
||
if ! is_running; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, won't this potentially race if NM and chrony start up at the same time?
The closest I got to a manual test is this - #412 (comment) which checks that DHCP -> chrony propagation of NTP sources works. Unfortunately it is quite long-winded and heavyweight using multiple VMs - never got a test using dummy interfaces (like the Debian chrony package has) working https://gist.github.com/rfairley/0a126d583636ab7d14113cb60397ab86. There should also really be another test that runs on a cloud where a time source is provided ( Automating both of the scenarios above are really what's left to tie off this work - then the bits upstream (the effect of https://git.tuxfamily.org/chrony/chrony.git/commit/?id=bf7f63eaed83a271ba1eeefdd21f187e3999962b and https://src.fedoraproject.org/rpms/chrony/pull-request/3) should trickle down and eventually replace the |
Thanks @rfairley. @sohankunkerkar is picking up this work and moving it forward. If there are any needed changes to this PR he'll probably open a new PR with commits on top of what you've got here. He's digging in to the problem now. |
overlay.d/21dhcp-chrony/etc/NetworkManager/dispatcher.d/20-coreos-chrony-dhcp
Show resolved
Hide resolved
Writing this test to verify coreos/fedora-coreos-config#412 change to enable DHCP propagation of NTP servers. We don't need this test once the upstream/downstream patch merges. upstream patch: https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00023.html downstream patch: https://src.fedoraproject.org/rpms/chrony/pull-request/3
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers. We don't need this test once the upstream/downstream patch merges. upstream patch: https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00023.html downstream patch: https://src.fedoraproject.org/rpms/chrony/pull-request/3
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers. We don't need this test once the upstream/downstream patch merges. upstream patch: https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00023.html downstream patch: https://src.fedoraproject.org/rpms/chrony/pull-request/3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
waiting for coreos/coreos-assembler#1667 to get in before we merge this PR.
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers. We don't need this test once the upstream/downstream patch merges. upstream patch: https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00023.html downstream patch: https://src.fedoraproject.org/rpms/chrony/pull-request/3
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers. We don't need this test once the upstream/downstream patch merges. upstream patch: https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00023.html downstream patch: https://src.fedoraproject.org/rpms/chrony/pull-request/3
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers. We don't need this test once the upstream/downstream patch merges. upstream patch: https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00023.html downstream patch: https://src.fedoraproject.org/rpms/chrony/pull-request/3
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers. We don't need this test once the upstream/downstream patch merges. upstream patch: https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00023.html downstream patch: https://src.fedoraproject.org/rpms/chrony/pull-request/3
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers. We don't need this test once the upstream/downstream patch merges. upstream patch: https://listengine.tuxfamily.org/chrony.tuxfamily.org/chrony-dev/2020/05/msg00023.html downstream patch: https://src.fedoraproject.org/rpms/chrony/pull-request/3
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers.
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers.This will also avoid any regression that might cause in RHCOS or FCOS when the upstream changes come down and obsolete the temporary work.
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers.This will also avoid any regression that might cause in RHCOS or FCOS when the upstream changes come down and obsolete the temporary work.
Writing this test to verify coreos/fedora-coreos-config#412 to enable the DHCP propagation of NTP servers.This will also avoid any regression that might cause in RHCOS or FCOS when the upstream changes come down and obsolete the temporary work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - will give it another few hours for review and then will merge.
In order to make chrony use NTP settings from DHCP (#412), we need to chmod the following files to unset the writable permissions. Git tracks only the executable bit of the permissions so when the files get pulled locally they could have the group write bit set. When that happens we get an error like: `Cannot execute '/etc/NetworkManager/dispatcher.d/20-coreos-chrony-dhcp': writable by group or other`
…vers Writing this test to verify #412 to enable the DHCP propagation of NTP servers. This will also avoid any regression that might cause in RHCOS or FCOS whenthe upstream changes come down and obsolete the temporary work.
See commit message for details.