burmilla / os

Tiny Linux distro that runs the entire OS as Docker containers
https://burmillaos.org
Apache License 2.0
210 stars 13 forks source link

Add support for ntp server configuration from dhcp #158

Open netsandbox opened 1 year ago

netsandbox commented 1 year ago

BurmillaOS Version: (ros os version) v1.9.6

If you are using dhcp, it is quite common to also send a ntp_servers option (42) with the dhcp response. But currently the dhcpcd don't even request the ntp_servers option (it is commented out):

$ sudo system-docker exec network grep ntp /etc/dhcpcd.conf
#option ntp_servers

It would be great if configuring ntp servers from dhcp could be implemented.

olljanat commented 1 year ago

We use https://github.com/NetworkConfiguration/dhcpcd inside of network system container this feature would need to be implemented in there.

netsandbox commented 1 year ago

Actually it is there, but you have to provide a hook, see: https://github.com/NetworkConfiguration/dhcpcd/blob/master/hooks/50-ntp.conf

olljanat commented 1 year ago

Ah, but that is not enough because ntp client is running on different container. If you want to use custom NTP you need to configure those with cloud-init like this https://burmillaos.org/docs/configuration/advanced/write-files/#writing-files-in-specific-system-services

netsandbox commented 1 year ago

Using cloud-init would make our deployment over complicated, because we have isolated networks, which all have their own ntp server. So I would need to create a cloud-init for each network and let our deployment pick the right cloud-init for the new host.

Maybe for the future it makes sense to put the ntp client inside the network container, as this is also a network service, and would make it possible to distribute the ntp server by dhcp.

olljanat commented 1 year ago

Using cloud-init would make our deployment over complicated, because we have isolated networks, which all have their own ntp server. So I would need to create a cloud-init for each network and let our deployment pick the right cloud-init for the new host.

What is purpose to use so overly complicated ntp server setup?

Maybe for the future it makes sense to put the ntp client inside the network container, as this is also a network service, and would make it possible to distribute the ntp server by dhcp.

In general best practice is have just one process per containers so this would need process which can handle both dhcp client and ntp client.

Anyway, if this is critical for you then perhaps you can try what happens when you enable option ntp_servers in /etc/dhcpcd.conf? (which you can also do by utilizing write_files in cloud-init.

Where dhcpcd will write that information about ntp servers and it ntp client able read it then? Both network and ntp system containers can see same file system so in theory it might work with that one.

If you can proof that it works then perhaps we can fix it to v2.0.0 release version. Now when I'm looking there looks to be bug somewhere on build process anyway because on template config that option is actually already enabled: https://github.com/burmilla/os/blob/615b3d4f7c4710580ba689e515082baa132548ea/images/01-base/etc/dhcpcd.conf.tpl#L29-L30

netsandbox commented 1 year ago

I have enabled option ntp_servers in /etc/dhcpcd.conf of the network container, restarted the container and run:

$ sudo system-docker exec network dhcpcd -MA4 -U eth0 | grep ntp
ntp_servers=x.x.x.x

So yes there is the dhcp provided ntp server.

netsandbox commented 1 year ago

Now when I'm looking there looks to be bug somewhere on build process anyway because on template config that option is actually already enabled

The dhcpcd template is only used when there are WifiNetworks configured: https://github.com/burmilla/os/blob/615b3d4f7c4710580ba689e515082baa132548ea/cmd/network/network.go#L68-L71

So dhcpcd configuration changes must go in the template and must be inline changed in the Dockerfile: https://github.com/burmilla/os/blob/615b3d4f7c4710580ba689e515082baa132548ea/images/01-base/Dockerfile#L36-L37

And the inline change to remove the # from option ntp_servers is currently missing.

Maybe it is better to always use the template, regardless if WifiNetworks are configured or not, to manage the configuration only in one place.

olljanat commented 6 months ago

Included to v2.0.0

netsandbox commented 4 months ago

@olljanat actually this is not working in v2 because you just implemented requesting ntp_servers from dhcp, but not the hook mentioned in https://github.com/burmilla/os/issues/158#issuecomment-1618858605 to update the /etc/ntp.conf.

olljanat commented 4 months ago

I don't fully follow what is actually needed. Please, create pull request with valid logic.

netsandbox commented 4 months ago

dhcpcd don't automatically modifies /etc/ntp.conf by default.

You need to place hook https://github.com/NetworkConfiguration/dhcpcd/blob/master/hooks/50-ntp.conf in the network container in /lib/dhcpcd/dhcpcd-hooks to let dhcpcd update /etc/ntp.conf.

netsandbox commented 4 months ago

Sadyl I'm not familiar with the build process, so I don't know what to do to get the new hook file in the network container.

olljanat commented 4 months ago

Those are part of base image defined in these files. Can be tested with normal Docker build + run https://github.com/burmilla/os/tree/master/images/01-base