From nobody Mon Sep 07 04:20:38 2026 X-Original-To: dev-commits-src-branches@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 4hdYlV5G4jz6rMMM for ; Mon, 07 Sep 2026 04:20:38 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hdYlV2YTdz3SJW for ; Mon, 07 Sep 2026 04:20:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788754838; 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=zsZwib1bP6iZt8astXfkdw43qLjff1vjhFol6a7/w6Y=; b=GwB4jvxmbOuB7WwtjJI7xicABQstZ8BN55XlkMqql1tLNngQ7Chrd7exekZrmeCN7dsDvJ bsdFj9UGW+x+j0dkZoGFf2vffVbsX0ke1QiJ3Xk+tfq1C05h6FDxsUatUfJn8NyNaEDLX3 yL0jbO+jJUrQlT8DOz3lJoCgFjEbt1sKHSU5YmaiG8lN/nzVBXEpZfwdVizm+fU1xm9Lpq VyqnUxezHESDeDqEs1Lop+YtZnS1JM+/hqti7AaVuA871s+1X3/yOkFl6kNVr9BFpsedTO 24SuJ9XabjbIhTs+N2ehUXd8oLsSaOOqdQENQ31/UmQGAplxea+R6yx9pxnWhg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1788754838; a=rsa-sha256; cv=none; b=oKk366NsH5QZhscmVg3fUBNFRXBC/IoP+GoyKrBVaAMHg9ODJLcfehKbTUPM4liagyrHbz gNUH6AIuqXc3ZO007CMX0g6foFOpD7Z+n2eHhJndphDsGnuUKdQYJ2LaTkHMRs7QTLzh+y lcJIezd9BxgqPFO+ZedPj59nH8svzKOIECHC9g/ch4q1+/CpTL24bHBCyTFYKYvMaG7/I3 tgFR2VPEM6VuND87xb3YrsIQdYnizqVgsLmCgS3FLW1n6sw/uX3HWeYEDuU6sP+I8xvQFD SVJsoBgxnhRRiah7r/ePADcwVv/Uaqp0U7bK44fArcMWmPg44KzjZDNDzaS7ww== 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=1788754838; 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=zsZwib1bP6iZt8astXfkdw43qLjff1vjhFol6a7/w6Y=; b=ix5uodiAvNWIoZJOTXBn/4bx5dt88NXZSL8Ddq0qoXg3zMi6CjKPOl3KA10v/UeW0pf0KT hhgoQYPVxDiyjUs6A9IlGgu/Dlc6Zb4LOCU2a9/YJUsetEPFYnTOo7zybbe2IqtBVkbQzH kujLPm3ulSbMKlb7Ytgue7AkOT5wriEGYjUroDOw2o8nNQ9MLIDGmVfn/j1sJmDJBR+C/Z BStoWB00EyUHXDfuTTImmh205R3WdFim9N+rZQQ8A/03ZfoVBXWFS05j6DUKFnoxTpHdia YvuH4XeXhq6W2wF1elZ/sgYyWKY1c2uiBfjbFqvpAITpSDK/HJ1g2M/Yw0Vx9A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hdYlV1bBrz12LH for ; Mon, 07 Sep 2026 04:20:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 19564 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 07 Sep 2026 04:20:38 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: ece43a7994b6 - stable/15 - nuageinit: adopt cloud-init disable_root semantics List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/15 X-Git-Reftype: branch X-Git-Commit: ece43a7994b68f93c2b9fc434a9fdf6e0668dc92 Auto-Submitted: auto-generated Date: Mon, 07 Sep 2026 04:20:38 +0000 Message-Id: <6a9e3b96.19564.841792f@gitrepo.freebsd.org> The branch stable/15 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=ece43a7994b68f93c2b9fc434a9fdf6e0668dc92 commit ece43a7994b68f93c2b9fc434a9fdf6e0668dc92 Author: Baptiste Daroussin AuthorDate: 2026-08-11 08:56:52 +0000 Commit: Baptiste Daroussin CommitDate: 2026-09-07 04:19:01 +0000 nuageinit: adopt cloud-init disable_root semantics disable_root now restricts root's authorized_keys instead of setting PermitRootLogin. Reported by: np@ (cherry picked from commit 8ec108914247502dff049059dc60df17920731c8) --- 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 523bfc65a579..8f609feb0980 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 e1c4b9d61382..a9552cace85f 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()