git: 6d27d52ccd35 - main - nuageinit: implement ntp support
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 06 Jun 2026 06:14:14 UTC
The branch main has been updated by bapt:
URL: https://cgit.FreeBSD.org/src/commit/?id=6d27d52ccd35d1980e99bc2fc4dae602334d28af
commit 6d27d52ccd35d1980e99bc2fc4dae602334d28af
Author: Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2026-06-05 20:25:29 +0000
Commit: Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2026-06-05 20:25:29 +0000
nuageinit: implement ntp support
Add support for the 'ntp' cloud-config key which configures NTP
by writing /etc/ntp.conf with server and pool entries.
---
libexec/nuageinit/nuageinit | 37 ++++++++++++++++++++++++++++++++++++
libexec/nuageinit/nuageinit.7 | 21 ++++++++++++++++++++
libexec/nuageinit/tests/nuageinit.sh | 28 +++++++++++++++++++++++++++
3 files changed, 86 insertions(+)
diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit
index 8e2658f2cd13..19681b54810f 100755
--- a/libexec/nuageinit/nuageinit
+++ b/libexec/nuageinit/nuageinit
@@ -532,6 +532,42 @@ local function ssh_authkey_fingerprints(obj)
end
end
+local function ntp(obj)
+ if obj.ntp == nil then return end
+ if type(obj.ntp) == "table" and obj.ntp.enabled == false then
+ return
+ end
+ local servers = {}
+ if type(obj.ntp) == "table" then
+ if obj.ntp[1] then
+ servers = obj.ntp
+ else
+ for _, s in ipairs(obj.ntp.servers or {}) do
+ table.insert(servers, "server " .. s .. " iburst")
+ end
+ for _, p in ipairs(obj.ntp.pools or {}) do
+ table.insert(servers, "pool " .. p .. " iburst")
+ end
+ end
+ elseif type(obj.ntp) == "string" then
+ table.insert(servers, "server " .. obj.ntp .. " iburst")
+ end
+ if #servers == 0 then return end
+ local path = root .. "/etc/ntp.conf"
+ local f = io.open(path, "w")
+ if not f then
+ warnmsg("unable to open " .. path .. " for writing")
+ return
+ end
+ for _, line in ipairs(servers) do
+ f:write(line .. "\n")
+ end
+ f:write("leapfile /var/db/ntpd.leap-seconds.list\n")
+ f:write("restrict default limited kod nomodify notrap nopeer noquery\n")
+ f:write("restrict source limited kod nomodify notrap noquery\n")
+ f:close()
+end
+
local function ssh_deletekeys(obj)
if obj.ssh_deletekeys == nil then return end
if obj.ssh_deletekeys then
@@ -931,6 +967,7 @@ elseif line == "#cloud-config" then
}
local post_network_calls = {
+ ntp,
packages,
users,
chpasswd,
diff --git a/libexec/nuageinit/nuageinit.7 b/libexec/nuageinit/nuageinit.7
index 200eb2524fe6..ae8e9446bde5 100644
--- a/libexec/nuageinit/nuageinit.7
+++ b/libexec/nuageinit/nuageinit.7
@@ -237,6 +237,27 @@ Boolean which determines whether fingerprints of SSH host keys
should be logged to the console.
Defaults to
.Ar false .
+.It Ic ntp
+An object configuring the NTP daemon by writing
+.Pa /etc/ntp.conf .
+.Pp
+The following keys are recognized:
+.Bl -tag -width "enabled"
+.It servers
+A list of NTP server addresses.
+.It pools
+A list of NTP pool addresses.
+.It enabled
+Boolean, defaults to
+.Ar true .
+Set to
+.Ar false
+to skip NTP configuration.
+.El
+.Pp
+Alternatively,
+.Ic ntp
+can be a list of server addresses (legacy format).
.It Ic timezone
Sets the system timezone based on the value provided.
.Pp
diff --git a/libexec/nuageinit/tests/nuageinit.sh b/libexec/nuageinit/tests/nuageinit.sh
index 44c681e18046..63366f79486a 100644
--- a/libexec/nuageinit/tests/nuageinit.sh
+++ b/libexec/nuageinit/tests/nuageinit.sh
@@ -38,6 +38,7 @@ atf_test_case config2_userdata_mounts
atf_test_case config2_userdata_resolv_conf
atf_test_case config2_userdata_keyboard
atf_test_case config2_userdata_ssh_authkey_fingerprints
+atf_test_case config2_userdata_ntp
atf_test_case config2_userdata_fqdn_and_hostname
atf_test_case config2_userdata_write_files
@@ -1218,6 +1219,32 @@ EOF
true
}
+config2_userdata_ntp_head()
+{
+ atf_set "require.user" root
+}
+config2_userdata_ntp_body()
+{
+ mkdir -p media/nuageinit
+ setup_test_adduser
+ printf "{}" > media/nuageinit/meta_data.json
+ cat > media/nuageinit/user_data <<EOF
+#cloud-config
+ntp:
+ servers:
+ - 192.168.1.1
+ - 10.0.0.1
+ pools:
+ - 0.pool.ntp.org
+EOF
+ atf_check -o empty /usr/libexec/nuageinit "${PWD}"/media/nuageinit postnet
+ atf_check -o match:"server 192.168.1.1 iburst" cat etc/ntp.conf
+ atf_check -o match:"server 10.0.0.1 iburst" cat etc/ntp.conf
+ atf_check -o match:"pool 0.pool.ntp.org iburst" cat etc/ntp.conf
+ atf_check -o match:"leapfile /var/db/ntpd.leap-seconds.list" cat etc/ntp.conf
+ true
+}
+
config2_userdata_fqdn_and_hostname_body()
{
mkdir -p media/nuageinit
@@ -1271,6 +1298,7 @@ atf_init_test_cases()
atf_add_test_case config2_userdata_resolv_conf
atf_add_test_case config2_userdata_keyboard
atf_add_test_case config2_userdata_ssh_authkey_fingerprints
+ atf_add_test_case config2_userdata_ntp
atf_add_test_case config2_userdata_fqdn_and_hostname
atf_add_test_case config2_userdata_write_files
}