From nobody Tue Aug 11 11:17:23 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hK8Gx3Nyfz6nXmC for ; Tue, 11 Aug 2026 11:17:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hK8Gx1DqSz3RBn for ; Tue, 11 Aug 2026 11:17:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786447049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sJa3cdChaEx5OeS+XngV0lNeCWsm3AnRL4S6osooOV0=; b=jbL5BArY6PoKZo24TfNBLDBn8+Sn4c34fPO+z/y1z2pgZs84jI1TdW8sw+PA/NlZ0xhDS0 Za9FKtOQgppzOveRez1nf/I2sU0ALUiRi62Oieh3qaKu6f7R4hQZJgauk3wQd3bbipXyTd /Fr6GFa/snzdQgoMSvbxzjYcZ6EHI4qshPTyaIfMYEemP3dFxzrTI92jUGF4tyVlUg2v2r 3aNFnOH6itqOkQw8gzO996L6H/+P+2KuES/2rQnejCfCxG4J/TcQgwzu9PhwR8NUgAsrC3 TZBvAMzrZ2+HKCpA+sgKH0KR/rvOLiN/PSYgNkTcLgHSQoKRI87aZBt1j0IJ2Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786447049; a=rsa-sha256; cv=none; b=kh+oB+u+KMC2fAShCJnlZjDWGFgj6GD2LwI68aFrIrp+qin7ytipLNXn+SdUFKisHmow/r Bm0y6GBHJ8Wa/IUdfXOR45FelZPTUg20qQb3kwTSsmhg9NJmUoJKgIQ51cAEp5uVuK9oXS PBWkUOgRTh8MNultR4T7lyJJ/PQEiOXPOI3p56QskLGbKi+v4b3l+6A93xYCl/AzsVSKkh AbEKmq8w1OMV/wwAbEizFYPpg88mixjP6xrthMchrj35K9XrTUiE2pQJhXvESVThy7FtYt dMf5S2g2J+Q9cytQi8g/f8ij2axxVANlzRVcyYVriaGp8x/YzZck6gNlgxYE2g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786447049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sJa3cdChaEx5OeS+XngV0lNeCWsm3AnRL4S6osooOV0=; b=iMSPa2rhsIWOFHUt1IJnFSxtgHFVoeCRPDkqI4iargr+lm6cJ0IRunDyjYmsXcFGZdViiO wYaT5lMN3VBoAm2+qGFWAqBunw1aAHIKjW2AragqcLLXqTHrvb01iGhMq4+bJbBpii1NR3 RFVAvD6GV/3weVo2ItTizDtMPgIz/j/lxLspRXJpeWwCYo8pmV7d4QRAB2DQhD78a7WY09 OjnZTFD5DUm9Z3jALKIThsUTOu03sLhCtCi0MhupW0kn+/hcBsD6TjmVsrAmZk5iapDvST PyrN713tFfypOtC0FYYaljJ9fmWIeBQGoWXBZcFkahiIkwUmq37n6WBdzeP9Pw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hK8Gw71srzsmK for ; Tue, 11 Aug 2026 11:17:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 41094 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 11 Aug 2026 11:17:23 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 8ec108914247 - main - nuageinit: adopt cloud-init disable_root semantics List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8ec108914247502dff049059dc60df17920731c8 Auto-Submitted: auto-generated Date: Tue, 11 Aug 2026 11:17:23 +0000 Message-Id: <6a7b04c3.41094.185ad680@gitrepo.freebsd.org> The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=8ec108914247502dff049059dc60df17920731c8 commit 8ec108914247502dff049059dc60df17920731c8 Author: Baptiste Daroussin AuthorDate: 2026-08-11 08:56:52 +0000 Commit: Baptiste Daroussin CommitDate: 2026-08-11 11:15:55 +0000 nuageinit: adopt cloud-init disable_root semantics disable_root now restricts root's authorized_keys instead of setting PermitRootLogin. Reported by: np@ --- libexec/nuageinit/nuage.lua | 8 ++++++-- libexec/nuageinit/nuageinit | 40 ++++++++++++++++++++++++++---------- libexec/nuageinit/nuageinit.7 | 35 +++++++++++++++++++------------ libexec/nuageinit/tests/nuageinit.sh | 31 ++++++++++++++-------------- 4 files changed, 73 insertions(+), 41 deletions(-) diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua index cbd842460e55..3a9ac253fbcb 100644 --- a/libexec/nuageinit/nuage.lua +++ b/libexec/nuageinit/nuage.lua @@ -438,7 +438,7 @@ local function addgroup(grp) return true end -local function addsshkey(homedir, key) +local function addsshkey(homedir, key, options) local root = os.getenv("NUAGE_FAKE_ROOTDIR") if root then homedir = root .. "/" .. homedir @@ -471,7 +471,11 @@ local function addsshkey(homedir, key) warnmsg("impossible to open " .. ak_path) return end - f:write(key .. "\n") + if options and options ~= "" then + f:write(options .. " " .. key .. "\n") + else + f:write(key .. "\n") + end f:close() -- Set permissions and ownership on newly created files/dirs diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit index ba26f504effb..d67ac6ce4229 100755 --- a/libexec/nuageinit/nuageinit +++ b/libexec/nuageinit/nuageinit @@ -570,18 +570,36 @@ local function ssh_deletekeys(obj) end end -local function disable_root(obj) - if obj.disable_root == nil then return end - if obj.disable_root then - local value = "no" - if obj.disable_root_opts then - if type(obj.disable_root_opts) == "string" then - value = obj.disable_root_opts - elseif type(obj.disable_root_opts) == "table" then - value = obj.disable_root_opts[1] - end +local DISABLE_USER_OPTS = 'no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo \'Please login as the user \\"$USER\\" rather than the user \\"$DISABLE_USER\\".\';echo;sleep 10;exit 142"' + +local function disable_root(obj, metadata) + -- cloud-init semantics: restrict root's authorized_keys options + local disable = true + if obj.disable_root ~= nil then + disable = obj.disable_root + end + local opts = "" + if disable then + opts = obj.disable_root_opts or DISABLE_USER_OPTS + if type(opts) == "table" then + opts = opts[1] + end + opts = opts:gsub("%$USER", "freebsd") + opts = opts:gsub("%$DISABLE_USER", "root") + end + local keys = {} + if type(metadata.public_keys) == "table" then + for _, k in pairs(metadata.public_keys) do + table.insert(keys, k) end - nuage.update_sshd_config("PermitRootLogin", value) + end + if obj and type(obj.ssh_authorized_keys) == "table" then + for _, k in ipairs(obj.ssh_authorized_keys) do + table.insert(keys, k) + end + end + for _, k in ipairs(keys) do + nuage.addsshkey("/root", k, opts) end end diff --git a/libexec/nuageinit/nuageinit.7 b/libexec/nuageinit/nuageinit.7 index a3d9da2415d9..c9c9096eee72 100644 --- a/libexec/nuageinit/nuageinit.7 +++ b/libexec/nuageinit/nuageinit.7 @@ -331,25 +331,34 @@ configuration in .It Ic disable_root Boolean which determines if root login via SSH should be disabled. If set to -.Ar true , -sets -.Qq Ic PermitRootLogin -to -.Ar no -.Pq or the value specified in Ic disable_root_opts -in -.Pa /etc/ssh/sshd_config . +.Ar true +.Pq the default , +the public SSH keys are written to +.Pa /root/.ssh/authorized_keys +with the options specified in +.Ic disable_root_opts , +which by default redirects the login to the default user. +If set to +.Ar false , +the public SSH keys are written to +.Pa /root/.ssh/authorized_keys +without any restriction. .It Ic disable_root_opts -String or array of options used to set the value of -.Qq Ic PermitRootLogin -in -.Pa /etc/ssh/sshd_config , +String or array of options used to prefix the public SSH keys in +.Pa /root/.ssh/authorized_keys when .Ic disable_root is set to .Ar true . +The +.Ar $USER +and +.Ar $DISABLE_USER +placeholders are replaced with the default user name and +.Ar root +respectively. If not specified, defaults to -.Ar no . +.Ar no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user "$USER" rather than the user "$DISABLE_USER".';echo;sleep 10;exit 142" . .Pp Only the first value is used when an array is provided. .It Ic network diff --git a/libexec/nuageinit/tests/nuageinit.sh b/libexec/nuageinit/tests/nuageinit.sh index ab9e697076e1..1fb5f7b4c967 100644 --- a/libexec/nuageinit/tests/nuageinit.sh +++ b/libexec/nuageinit/tests/nuageinit.sh @@ -267,6 +267,7 @@ ssh_authorized_keys: - "ssh-rsa AAAAB3NzaC1y...== Generated by Nova" EOF mkdir -p etc + mkdir -p root cat > etc/master.passwd << EOF root:*:0:0::0:0:Charlie &:/root:/bin/sh sys:*:1:0::0:0:Sys:/home/sys:/bin/sh @@ -294,6 +295,7 @@ ssh_authorized_keys: - "ssh-rsa AAAAB3NzaC1y...== Generated by Nova" EOF mkdir -p etc + mkdir -p root cat > etc/master.passwd << EOF root:*:0:0::0:0:Charlie &:/root:/bin/sh sys:*:1:0::0:0:Sys:/home/sys:/bin/sh @@ -340,6 +342,7 @@ config2_pubkeys_meta_data_body() } EOF mkdir -p etc + mkdir -p root cat > etc/master.passwd << EOF root:*:0:0::0:0:Charlie &:/root:/bin/csh sys:*:1:0::0:0:Sys:/home/sys:/bin/csh @@ -1004,37 +1007,35 @@ config2_userdata_disable_root_body() { mkdir -p media/nuageinit setup_test_adduser + mkdir -p root printf "{}" > media/nuageinit/meta_data.json cat > media/nuageinit/user_data < media/nuageinit/user_data < media/nuageinit/user_data < media/nuageinit/user_data < etc/ssh/sshd_config atf_check -o empty /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 - atf_check -o inline:"PermitRootLogin yes\n" cat etc/ssh/sshd_config + atf_check -o inline:"ssh-rsa AAAAB3NzaC1y...== Generated by Nova\n" cat root/.ssh/authorized_keys } config2_userdata_bootcmd_head()